#!/bin/bash # $HeadURL$ $LastChangedRevision$ set -e PROGNAME=$(basename $0) # Load support functions . $(pcms-config PCMS_SHARE_PREFIX)/scripts/support.sh main() { # Defaults for options VERBOSELEVEL=2 OPT_FILE=/etc/sudoers OPT_TOUCH=false # Process options while [ $# -ge 1 ]; do case $1 in --file=*) OPT_FILE=${1#*=} ;; --touch) OPT_TOUCH=true ;; --debug=*) VERBOSELEVEL=${1#*=} ;; -d) VERBOSELEVEL=$2; shift ;; -v|--verbose) VERBOSELEVEL=3 ;; --) shift; break ;; -*) error "main: $1: bad option" ;; *) break ;; esac shift done # Process arguments [ $# = 1 ] || usage eval set -- $(encode --decode "$1") [ $# -ge 1 ] || usage SUDORULE="$@" # Sanity checks and derivations # Guts lineinfile --after=EOF --text="$SUDORULE" --file=$OPT_FILE ! $OPT_TOUCH || touch $OPT_FILE visudo --check --file=$OPT_FILE > /dev/null } usage() { echo "Usage: $PROGNAME [ --file= ] [@...[@...]]" >&2; exit 1; } main "$@"