summaryrefslogtreecommitdiff
path: root/src/chroot-tools
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2013-06-03 21:09:53 -0600
committerLuke Shumaker <LukeShu@sbcglobal.net>2013-06-05 20:06:25 -0600
commit5f9a944f44d253cd16b5a4d6ddb3e6642258b4e6 (patch)
treedef1cf2629e51916726efb7a73cf255f134e7a66 /src/chroot-tools
parentdc75575a17044cd35d310ccd0a892f630f7f53cc (diff)
librechroot: check if the command doesn't exist and fail early
Diffstat (limited to 'src/chroot-tools')
-rwxr-xr-xsrc/chroot-tools/librechroot20
1 files changed, 15 insertions, 5 deletions
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 <http://www.gnu.org/licenses/>.
+# 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
}