test-install: Upgrade CLI parsing, with getopt.

This will let us add more options without the CLI collapsing under
its own weight.
This commit is contained in:
Greg Price 2018-01-22 12:09:07 -08:00
parent 7d8cd37035
commit de7abd8f78
1 changed files with 22 additions and 3 deletions

View File

@ -1,13 +1,32 @@
#!/bin/bash
set -ex
usage() {
echo "usage: install -r RELEASE TARBALL" >&2
exit 1
}
args="$(getopt -o +r: --long help,release: -- "$@")"
eval "set -- $args"
while true; do
case "$1" in
--help) usage;;
-r|--release) RELEASE="$2"; shift; shift;;
--) shift; break;;
*) usage;;
esac
done
INSTALLER="$1"; shift
if [ -z "$RELEASE" ] || [ -z "$INSTALLER" ]; then
usage
fi
if [ "$EUID" -ne 0 ]; then
echo "error: this script must be run as root" >&2
exit 1
fi
RELEASE="$1"
INSTALLER="$2"
set -ex
THIS_DIR="$(dirname "$(readlink -f "$0")")"