#!/bin/sh
#
# @(#)logmgmt-Xample.sh	3.2 01/10/19 Sun Microsystems, Inc.
#
# Copyright(C) 1999..2001 Sun Microsystems, Inc.  All Rights Reserved.
#
# Sample 'sslogmgmt' user-supplied script
#
# 'sslogmgmt' supplies the following usage:
#
# <script> [-r<screen>] [-C] [-v] -o<dst-dir> <logfile>
#
# User-written scripts should process any option (beginning with '-'),
# even those which are to be ignored; this sample script does this.
#
# All options are not separated from their argument (if any).  Hence,
# it is not necessary to handle options of the form "-o <arg>" as they
# will always appear as "-o<arg>"); while this violates the 'getopt'
# convention, it allows these scripts to simply ignore options they don't
# understand.
#
# The return value from this script, if non-zero, will cause 'sslogmgmt'
# to terminate in error; that value will be returned as the resulting
# value of 'sslogmgmt'.
#
# Note also that the user may pass in additional options by appending
# them to the -X option value, separated from the script name by a space
# (e.g. -X "script -XG<myopt>"); if such options with names of the form
# "-X<option>" are used, they will not conflict with other options that
# future versions of 'sslogmgmt' may introduce.
#
# This example script changes the group identity of the gotten-logs to
# that passed-in by the "-XG<group>" option, and makes the gotten-log
# group read-writable; this can allow a set of operators without root
# privilege to further process these logs.

usage () {
	echo "usage: $ME -XG<grp> [<sslogmgt_opts>...] <logfile>" 1>&2
	exit 1
}

GRP=
VERBOSE=0

ME=$0

while [ $# -gt 0 ] ; do
	case $1 in 
	-XG*)	[ -n "$GRP" ] && usage
		GRP=`expr $1 : '...\(.*\)'`  ;;
	-v)	VERBOSE=1  ;;
	-*)	;;
	*)	break  ;;
	esac
	shift
done

[ -z "$GRP" -o $# -ne 1 ] && usage

set -e

chmod g+rw $1
chgrp $GRP $1

[ $VERBOSE -ne 0 ] && ls -l $1

# eof
