From 0dfedda8d9d5bfa750a1802976ede8b7aeabb231 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Fri, 1 Sep 2023 15:41:56 -0400 Subject: [PATCH] Improve option handling errors The getopts framework just sucks for this, so do it manually. --- buildiso.sh | 34 +++++++++++++++++++++++++--------- buildpxe.sh | 33 ++++++++++++++++++++++----------- 2 files changed, 47 insertions(+), 20 deletions(-) diff --git a/buildiso.sh b/buildiso.sh index 80a5b58..0b2588e 100755 --- a/buildiso.sh +++ b/buildiso.sh @@ -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 diff --git a/buildpxe.sh b/buildpxe.sh index 0e4b166..1acc32a 100755 --- a/buildpxe.sh +++ b/buildpxe.sh @@ -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 }