Skip to content

Commit

Permalink
Argument parsing loop rewrite & fix double dash arguments (#585)
Browse files Browse the repository at this point in the history
* Fix -E and --no-exportbuild install flags.

* Rewrite argument parsing loop.
- Fixes issue where double dash arguments `--ssl-path`, `--docroot`, `--webroot`, `--file`, `--backuppath`, `--startrange`, and `--endrange` were not evaluating user input correctly.
- Clean up loop so single and double dash arguments are evaluated on the same case.
  • Loading branch information
rluzuriaga authored Apr 5, 2024
1 parent 15436da commit 8f9e4ca
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 191 deletions.
294 changes: 104 additions & 190 deletions bin/installfog.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,247 +81,156 @@ usage() {
exit 0
}

optspec="h?odEUHSCKYyXxTPFAf:c:-:W:D:B:s:e:b:N:"
while getopts "$optspec" o; do
case $o in
-)
case $OPTARG in
help)
usage
exit 0
;;
uninstall)
exit 0
;;
ssl-path)
ssslpath="${OPTARG}"
ssslpath="${ssslpath#'/'}"
ssslpath="${ssslpath%'/'}"
ssslpath="/${ssslpath}/"
;;
no-vhost)
novhost="y"
;;
no-defaults)
guessdefaults=0
;;
no-upgrade)
doupdate=0
;;
no-htmldoc)
signorehtmldoc=1
;;
force-https)
shttpproto="https"
;;
recreate-keys)
srecreateKeys="yes"
;;
recreate-[Cc][Aa])
srecreateCA="yes"
;;
autoaccept)
autoaccept="yes"
dbupdate="yes"
;;
docroot)
sdocroot="${OPTARG}"
sdocroot="${docroot#'/'}"
sdocroot="${docroot%'/'}"
sdocroot="/${docroot}/"
;;
oldcopy)
scopybackold=1
;;
webroot)
if [[ $OPTARG != *('/')* ]]; then
echo -e "-$OPTARG needs a url path for access either / or /fog for example.\n\n\t\tfor example if you access fog using http://127.0.0.1/ without any trail\n\t\tset the path to /"
usage
exit 2
fi
swebroot="${OPTARG}"
swebroot="${webroot#'/'}"
swebroot="${webroot%'/'}"
;;
file)
if [[ -f $OPTARG ]]; then
fogpriorconfig=$OPTARG
else
echo "--$OPTARG requires file after"
usage
exit 3
fi
;;
backuppath)
if [[ ! -d $OPTARG ]]; then
echo "Path must be an existing directory"
usage
exit 4
fi
sbackupPath=$OPTARG
;;
startrange)
if [[ $(validip $OPTARG) != 0 ]]; then
echo "Invalid ip passed"
usage
exit 5
fi
sstartrange=$OPTARG
dodhcp="Y"
bldhcp=1
;;
endrange)
if [[ $(validip $OPTARG) != 0 ]]; then
echo "Invalid ip passed"
usage
exit 6
fi
sendrange=$OPTARG
dodhcp="Y"
bldhcp=1
;;
no-exportbuild)
sblexports=0
;;
exitFail)
sexitFail=1
;;
no-tftpbuild)
snoTftpBuild="true"
;;
arm-support)
sarmsupport=1
;;
*)
if [[ $OPTERR == 1 && ${optspec:0:1} != : ]]; then
echo "Unknown option: --${OPTARG}"
usage
exit 7
fi
;;
esac
;;
h|'?')
shortopts="h?odEUHSCKYyXxTPFAf:c:W:D:B:s:e:b:N:"
longopts="help,uninstall,ssl-path:,oldcopy,no-vhost,no-defaults,no-upgrade,no-htmldoc,force-https,recreate-keys,recreate-CA,recreate-Ca,recreate-cA,recreate-ca,autoaccept,file:,docroot:,webroot:,backuppath:,startrange:,endrange:,bootfile:,no-exportbuild,exitFail,no-tftpbuild,arm-support"

optargs=$(getopt -o $shortopts -l $longopts -n "$0" -- "$@")
[[ $? -ne 0 ]] && usage
eval set -- "$optargs"

while :; do
case $1 in
-h | -\? | --help)
usage
exit 0
;;
o)
scopybackold=1
--uninstall)
exit 0
;;
c)
ssslpath="${OPTARG}"
ssslpath="${ssslpath#'/'}"
ssslpath="${ssslpath%'/'}"
ssslpath="/${ssslpath}/"
-c | --ssl-path)
if [[ -n "${2}" ]] && [[ "${2}" != -* ]]; then
ssslpath="${2}"
ssslpath="${ssslpath#'/'}"
ssslpath="${ssslpath%'/'}"
ssslpath="/${ssslpath}/"
else
echo "Error: Missing argument for --$1"
usage
exit 9
fi
shift 2
;;
-o | --oldcopy)
scopybackold=1
shift
;;
d)
-d | --no-defaults)
guessdefaults=0
shift
;;
U)
-U | --no-upgrade)
doupdate=0
shift
;;
H)
-H | --no-htmldoc)
signorehtmldoc=1
shift
;;
S)
-S | --force-https)
shttpproto="https"
shift
;;
K)
-K | --recreate-keys)
srecreateKeys="yes"
shift
;;
C)
-C | --recreate-[Cc][Aa])
srecreateCA="yes"
shift
;;
[yY])
-y | -Y | --autoaccept)
autoaccept="yes"
dbupdate="yes"
shift
;;
F)
novhost="y"
;;
D)
sdocroot=$OPTARG
sdocroot=${docroot#'/'}
sdocroot=${docroot%'/'}
sdocroot=/${docroot}/
-f | --file)
if [[ -f $2 ]]; then
fogpriorconfig=$2
else
echo "$1 requires file after"
usage
exit 3
fi
shift 2
;;
W)
if [[ $OPTARG != *('/')* ]]; then
echo -e "-$OPTARG needs a url path for access either / or /fog for example.\n\n\t\tfor example if you access fog using http://127.0.0.1/ without any trail\n\t\tset the path to /"
-D | --docroot)
if [[ -n "${2}" ]] && [[ "${2}" != -* ]]; then
sdocroot="${2}"
sdocroot="${sdocroot#'/'}"
sdocroot="${sdocroot%'/'}"
sdocroot="/${sdocroot}/"
else
echo "Error: Missing argument for $1"
usage
exit 2
exit 9
fi
swebroot=$OPTARG
swebroot=${webroot#'/'}
swebroot=${webroot%'/'}
shift 2
;;
f)
if [[ ! -f $OPTARG ]]; then
echo "-$OPTARG requires a file to follow"
-W | --webroot)
if [[ $2 != */* ]]; then
echo -e "$1 needs a url path for access either / or /fog.\n\t\tFor example if you access fog using http://127.0.0.1/ without\n\t\tany trail, set the path to /"
usage
exit 3
exit 2
fi
fogpriorconfig=$OPTARG
swebroot="${2}"
swebroot="${swebroot#'/'}"
swebroot="${swebroot%'/'}"
shift 2
;;
B)
if [[ ! -d $OPTARG ]]; then
-B | --backuppath)
if [[ ! -d $2 ]]; then
echo "Path must be an existing directory"
usage
exit 4
fi
sbackupPath=$OPTARG
sbackupPath=$2
shift 2
;;
s)
if [[ $(validip $OPTARG) != 0 ]]; then
-s | --startrange)
if [[ $(validip $2) != 0 ]]; then
echo "Invalid ip passed"
usage
exit 5
fi
sstartrange=$OPTARG
sstartrange=$2
dodhcp="Y"
bldhcp=1
shift 2
;;
e)
if [[ $(validip $OPTARG) != 0 ]]; then
-e | --endrange)
if [[ $(validip $2) != 0 ]]; then
echo "Invalid ip passed"
usage
exit 6
fi
sendrange=$OPTARG
sendrange=$2
dodhcp="Y"
bldhcp=1
shift 2
;;
E)
sblexports=0
-E | --no-exportbuild)
blexports=0
shift
;;
X)
exitFail=1
-X | --exitFail)
sexitFail=1
shift
;;
T)
-T | --no-tftpbuild)
snoTftpBuild="true"
shift
;;
A)
sarmsupport=1
;;
N)
if [[ -z $OPTARG ]]; then
echo "Please specify a database name"
usage
exit 4
fi
smysqldbname=$OPTARG
-F | --no-vhost)
novhost="y"
shift
;;
:)
echo "Option -$OPTARG requires a value"
usage
exit 8
-A | --arm-support)
sarmsupport=1
shift
;;
*)
if [[ $OPTERR == 1 && ${optspec:0:1} != : ]]; then
echo "Unknown option: -$OPTARG"
usage
exit 7
fi
--)
shift
break
;;
esac
done
Expand Down Expand Up @@ -409,7 +318,7 @@ case $doupdate in
echo -n " * Performing upgrade using these settings"
. "$fogpriorconfig"
doOSSpecificIncludes
[[ -n $sblexports ]] && blexports=$sblexports
[[ -n $blexports ]] && blexports=$blexports
[[ -n $snoTftpBuild ]] && noTftpBuild=$snoTftpBuild
[[ -n $sbackupPath ]] && backupPath=$sbackupPath
[[ -n $swebroot ]] && webroot=$swebroot
Expand All @@ -429,6 +338,11 @@ esac
[[ -n $ssslpath ]] && sslpath=$ssslpath
[[ -n $srecreateCA ]] && recreateCA=$srecreateCA
[[ -n $srecreateKeys ]] && recreateKeys=$srecreateKeys
[[ -n $sdocroot ]] && docroot=$sdocroot
[[ -n $swebroot ]] && webroot=$swebroot
[[ -n $sbackupPath ]] && backupPath=$sbackupPath
[[ -n $sexitFail ]] && exitFail=$sexitFail
[[ -n $snoTftpBuild ]] && noTftpBuild=$snoTftpBuild
[[ -n $sarmsupport ]] && armsupport=$sarmsupport

[[ -f $fogpriorconfig ]] && grep -l webroot $fogpriorconfig >>$error_log 2>&1
Expand Down
2 changes: 1 addition & 1 deletion packages/web/lib/fog/system.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private static function _versionCompare()
public function __construct()
{
self::_versionCompare();
define('FOG_VERSION', '1.5.10.16');
define('FOG_VERSION', '1.5.10.17');
define('FOG_SCHEMA', 270);
define('FOG_BCACHE_VER', 140);
define('FOG_CLIENT_VERSION', '0.13.0');
Expand Down

0 comments on commit 8f9e4ca

Please sign in to comment.