#!/bin/sh rootdir="" group="" id="" 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:i: opt ; do case $opt in d) rootdir="$OPTARG" ;; g) group="$OPTARG" ;; i) id="$OPTARG" ;; a) action="$OPTARG" ;; *) usage ;; esac done shift $(($OPTIND - 1)) if test -z "$group" -o -z "$action"; then usage fi # we do it once for $rootdir and once on the host to have synchronous groups for root in "$rootdir" ""; do args="" if test -n "$root"; then root="-R $root" fi if test -n "$id"; then args="-g $id" 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" $args fi ;; absent) if pw $root group show "$group" > /dev/null 2>&1; then run pw $root group del "$group" fi ;; *) usage ;; esac done