summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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