summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2019-04-21 19:55:16 +0200
committerJonas Smedegaard <dr@jones.dk>2019-04-21 19:55:16 +0200
commit3d6fb20968457c7a343df4fd1bd17b87a2449475 (patch)
tree43b5ea90ac36f3cfe0c05d9f3570d75201bda3ed
parent11d941d9e56d41d3505793d8558f12401998243a (diff)
Implement options verbose quiet dry-run help.
-rwxr-xr-xlocalrmstaleaccounts37
1 files changed, 34 insertions, 3 deletions
diff --git a/localrmstaleaccounts b/localrmstaleaccounts
index b6e9a05..dbb92f0 100755
--- a/localrmstaleaccounts
+++ b/localrmstaleaccounts
@@ -2,21 +2,52 @@
set -e
+PRG=$(basename "$0")
+
exit1() {
echo >&2 "ERROR: $1"
exit 1
}
+TEMP=$(getopt -s sh -o vqnh --long verbose,quiet,dry-run,help -n "$PRG" -- "$@") || exit1 "Internal getopt error"
+eval set -- "$TEMP"
+
+usage() {
+ cat <<EOF >&2
+Usage: $PRG [opts...] USER [USER...]
+
+ -v, --verbose increase verbosity
+ -q, --quiet suppress non-error messages
+ -n, --dry-run perform a trial run with no changes made
+ -h, --help show this help
+EOF
+ exit 0
+}
+
+VERBOSE=
+QUIET=
+DRY_RUN=
+while true ; do
+ case "$1" in
+ -v|--verbose) VERBOSE=1; shift;;
+ -q|--quiet) QUIET=1; shift;;
+ -n|--dry-run) DRY_RUN=1; shift;;
+ -h|--help) usage;;
+ --) shift; break;;
+ *) exit1 "Internal getopt parsing error";;
+ esac
+done
+
warn() {
- echo >&2 "WARNING: $1"
+ [ -n "$QUIET" ] || echo >&2 "WARNING: $1"
}
info() {
- echo >&2 "INFO: $1"
+ [ -n "$QUIET" ] || [ -z "$VERBOSE" ] || echo >&2 "INFO: $1"
}
remove_account() {
- localrmaccount "$1"
+ [ -n "$DRY_RUN" ] || localrmaccount "$1"
}
for user in $@; do