#!/bin/sh rootdir="" group="" action="" usage() { echo "Usage: $0 -g group -a action" echo "Valid actions: present, absent" exit 1 } run() { echo $* $* } OPTIND=1 while getopts d:g:a: opt ; do case $opt in d) rootdir="$OPTARG" ;; g) group="$OPTARG" ;; a) action="$OPTARG" ;; *) usage ;; esac done shift $(($OPTIND - 1)) if test -z "$group" -o -z "$action"; then usage fi root="" if test -n "$rootdir"; then root="-R $rootdir" fi case "$action" in present) if pw $root group show "$group" > /dev/null 2>&1; then if pw $root group show "$group" | grep -q LOCKED; then echo "$group exists." fi else run pw $root group add "$group" fi ;; absent) if pw $root group show "$group" > /dev/null 2>&1; then run pw $root group del "$group" fi ;; *) usage ;; esac