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." echo -e " -k: Preserve live-build config."
} }
while getopts "h?o:u:ak" opt; do while [ $# -gt 0 ]; do
case "$opt" in case "${1}" in
h|\?) -h|\?)
show_help show_help
exit 0 exit 0
;; ;;
o) -o)
isofilename=$OPTARG isofilename="${2}"
shift 2
;; ;;
u) -u)
deployusername=$OPTARG deployusername="${2}"
shift 2
;; ;;
a) -a)
preserve_artifacts='y' preserve_artifacts='y'
shift
;; ;;
k) -k)
preserve_livebuild='y' preserve_livebuild='y'
shift
;;
*)
echo "Invalid option: ${1}"
echo
show_help
exit 1
;; ;;
esac esac
done done
@ -59,6 +69,12 @@ PACKAGE_LIST_NONFREE="firmware-bnx2 firmware-bnx2x"
mkdir -p artifacts/lb mkdir -p artifacts/lb
pushd 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 # Initialize the live-build config
lb config --distribution buster --architectures amd64 --archive-areas "main contrib non-free" --apt-recommends false 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." echo -e " -i: Preserve live-build ISO image."
} }
while getopts "h?o:u:aki" opt; do while [ $# -gt 0 ]; do
case "$opt" in case "${1}" in
h|\?) -h|\?)
show_help show_help
exit 0 exit 0
;; ;;
o) -o)
outputdir="$OPTARG" outputdir="${2}"
shift 2
;; ;;
u) -u)
deployusername=$OPTARG deployusername="${2}"
shift 2
;; ;;
a) -a)
preserve_artifacts='-a' preserve_artifacts='-a'
shift
;; ;;
k) -k)
preserve_livebuild='-l' preserve_livebuild='-l'
shift
;; ;;
i) -i)
preserve_liveiso='y' preserve_liveiso='y'
shift
;;
*)
echo "Invalid option: ${1}"
echo
show_help
exit 1
;; ;;
esac esac
done done
@ -73,7 +84,7 @@ build_iso() {
-o pvc-installer_pxe-tmp.iso \ -o pvc-installer_pxe-tmp.iso \
-u ${deployusername} \ -u ${deployusername} \
${preserve_artifacts} \ ${preserve_artifacts} \
${preserve_livebuild} ${preserve_livebuild} || fail "Failed to build ISO."
fi fi
} }