From 5f9a944f44d253cd16b5a4d6ddb3e6642258b4e6 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 3 Jun 2013 21:09:53 -0600 Subject: librechroot: check if the command doesn't exist and fail early --- src/chroot-tools/librechroot | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'src/chroot-tools') diff --git a/src/chroot-tools/librechroot b/src/chroot-tools/librechroot index 9e98126..e353206 100755 --- a/src/chroot-tools/librechroot +++ b/src/chroot-tools/librechroot @@ -20,6 +20,11 @@ # You should have received a copy of the GNU General Public License # along with Parabola. If not, see . +# HACKING: if a command is added or removed, it must be changed in 3 places: +# - the usage() text +# - the commands=() array +# - the case statement in main() + . $(librelib conf.sh) load_files chroot @@ -109,6 +114,11 @@ usage() { echo ' clean-repo Clean /repo in the chroot copy' echo ' help Show this message' } +commands=( + noop make sync delete + install-file install-name update clean-pkgs + run enter clean-repo help +) # set $rootdir and $copydir; blank them on error calculate_directories() { @@ -159,6 +169,11 @@ main() { return 1 fi mode=$1 + if ! in_array "$mode" "${commands[@]}"; then + error "Unrecognized command: \`$mode'" + usage >/dev/stderr + return 1 + fi shift if [[ $mode == help ]]; then @@ -253,11 +268,6 @@ main() { rm -rf "${copydir}/repo/*" make_empty_repo "$copydir" ;; - *) - error "Unrecognized command: \`$mode'" - usage >/dev/stderr - return 1 - ;; esac } -- cgit v1.2.2