summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2010-08-26 16:19:53 +0200
committerJonas Smedegaard <dr@jones.dk>2010-08-26 16:19:53 +0200
commit8c6cf58bb66792e095e7275936aaa7d70b512073 (patch)
tree60cff64199b4c894b3a8f244d3377ed4c00f4749
parentc31b6b3011bc6d58fd375a5dd899928a9b475cb7 (diff)
Add getopt handling to localadduser.
-rwxr-xr-xlocaladduser20
1 files changed, 18 insertions, 2 deletions
diff --git a/localadduser b/localadduser
index e3cd3a1..292608b 100755
--- a/localadduser
+++ b/localadduser
@@ -8,15 +8,31 @@
# Execute adduser noninteractively through sudo
#
# TODO: Check for bad arguments
-# TODO: Use getopts to offer help
+# TODO: Implement --help option
# TODO: Support overriding options in /etc/local file
#
set -e
+PRG=$(basename "$0")
+
+TEMP="`getopt -s sh -o vqin -l verbose,quiet,interactive,noninteractive,dry-run -n "$PRG" -- "$@"`"
+if [ $? != 0 ] ; then echo >&2 "ERROR: Internal getopt error." ; exit 1 ; fi
+eval set -- "$TEMP"
+
verbose=1
-#simulate=true
interactive=0
+while true ; do
+ case "$1" in
+ -v|--verbose) verbose=1; shift ;;
+ -q|--quiet) verbose=0; shift ;;
+ -i|--interactive) interactive=1; shift ;;
+ -n|--noninteractive) interactive=0; shift ;;
+ --dry-run) simulate=true; shift ;;
+ --) shift ; break ;;
+ *) echo >&2 "ERROR: Internal error resolving options." ; exit 1 ;;
+ esac
+done
# echo something, but only if in verbose mode
vecho() {