aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xbosun35
1 files changed, 31 insertions, 4 deletions
diff --git a/bosun b/bosun
index c195176..cbc9718 100755
--- a/bosun
+++ b/bosun
@@ -2,20 +2,44 @@
export STOW_DIR=/etc/portage/stow
+err() {
+ printf "bosun: %s\n" "$@" >&2
+}
+
+errx() {
+ err "$@"
+ exit 1
+}
+
+usage() {
+ printf "usage: bosun add role ...\n" >&2
+ printf " bosun flush\n" >&2
+ printf " bosun [list [type ...]]\n" >&2
+ printf " bosun rebuild [role ...]\n" >&2
+ printf " bosun remove [role ...]\n" >&2
+ exit 1
+}
+
+need_role() {
+ test $# -gt 0 || errx "this command requires at least one role"
+ for dir in "$@"; do
+ test -d "$STOW_DIR/$dir" || errx "no such role '$dir' in $STOW_DIR"
+ done
+}
+
need_root() {
- if test "$(id -u)" -ne 0; then
- printf 'This action requires superuser access.\n'
- exit 1
- fi
+ test "$(id -u)" -eq 0 || errx "this action requires superuser access"
}
add() {
need_root
+ need_role "$@"
stow -S "$@"
}
remove() {
need_root
+ need_role "$@"
stow -D "$@"
}
@@ -27,6 +51,7 @@ flush() {
rebuild() {
need_root
if test $# -gt 0; then
+ need_role "$@"
stow -R "$@"
else
list | xargs -- stow -R
@@ -39,6 +64,7 @@ list() {
active) list_active;;
all) list_all;;
available) list_available;;
+ *) errx "no such list type '$subcmd'. Try: active, all, available"
esac
}
@@ -71,4 +97,5 @@ case $cmd in
list) list "$@";;
rebuild) rebuild "$@";;
remove) remove "$@";;
+ *) err "no such command '$cmd'"; usage;;
esac