Improve option handling errors

The getopts framework just sucks for this, so do it manually.
This commit is contained in:
Joshua Boniface 2021-12-04 02:39:49 -05:00
parent 252c543304
commit 30f9bbec95
2 changed files with 47 additions and 20 deletions

View File

@ -32,23 +32,33 @@ show_help() {
echo -e " -k: Preserve live-build config."
}
while getopts "h?o:u:ak" opt; do
case "$opt" in
h|\?)
while [ $# -gt 0 ]; do
case "${1}" in
-h|\?)
show_help
exit 0
;;
o)
isofilename=$OPTARG
-o)
isofilename="${2}"
shift 2
;;
u)
deployusername=$OPTARG
-u)
deployusername="${2}"
shift 2
;;
a)
-a)
preserve_artifacts='y'
shift
;;
k)
-k)
preserve_livebuild='y'
shift
;;
*)
echo "Invalid option: ${1}"
echo
show_help
exit 1
;;
esac
done
@ -59,6 +69,12 @@ PACKAGE_LIST_NONFREE="firmware-bnx2 firmware-bnx2x"
mkdir -p artifacts/lb
pushd artifacts/lb
if diff -q ../../install.sh config/includes.chroot/install.sh &>/dev/null; then
echo -n "Pre-cleaning due to differences in install.sh... "
lb clean
echo "done."
fi
# Initialize the live-build config
lb config --distribution buster --architectures amd64 --archive-areas "main contrib non-free" --apt-recommends false

View File

@ -31,26 +31,37 @@ show_help() {
echo -e " -i: Preserve live-build ISO image."
}
while getopts "h?o:u:aki" opt; do
case "$opt" in
h|\?)
while [ $# -gt 0 ]; do
case "${1}" in
-h|\?)
show_help
exit 0
;;
o)
outputdir="$OPTARG"
-o)
outputdir="${2}"
shift 2
;;
u)
deployusername=$OPTARG
-u)
deployusername="${2}"
shift 2
;;
a)
-a)
preserve_artifacts='-a'
shift
;;
k)
-k)
preserve_livebuild='-l'
shift
;;
i)
-i)
preserve_liveiso='y'
shift
;;
*)
echo "Invalid option: ${1}"
echo
show_help
exit 1
;;
esac
done
@ -73,7 +84,7 @@ build_iso() {
-o pvc-installer_pxe-tmp.iso \
-u ${deployusername} \
${preserve_artifacts} \
${preserve_livebuild}
${preserve_livebuild} || fail "Failed to build ISO."
fi
}