#!/bin/sh
#ident "@(#)user_example 1.3	97/01/14 SMI"
#
# NOTE: This is only an example script.  It has not been tested or verified.
#	It is ONLY for illustration purposes.  You will need to customize this
#	script to satisfy your specific needed.
# NOTE: Any output produced by this script will be returned and shown to the
#	user after the user operation is done.
#
# Example 'usermgr' script which could be used for multiple things.  This
# script is run on the users home server only. The following environmental
# variables are described in the admenviron(5) man page.  Example values are
# shown also.  In general, the format is:
#	ADM_*=org_value
#
# ADM_USER_LOGIN_NAME		<user specified user name. i.e. linda>
# ADM_USER_UID			<user specified user ID. i.e. 1234>
# ADM_USER_PRIMARY_GROUP	<user specified primary group. i.e. 100>
# ADM_USER_SHELL		<user specified login shell. i.e. /bin/sh>
# ADM_USER_HOMEPATH		<user specified home dir path. i.e. /export/home/linda>
# ADM_USER_SERVER		<user specified home dir server. i.e. svr1>
# ADM_USER_SKELETON_PATH	<user specified skeleton path. i.e. /etc/skel>
# ADM_USER_FILEMODE		<user specified permissions. i.e. 0755>
# ADM_USER_NAMESERVICE		<ufs,nis,nis_plus>
# ADM_USER_AUTOMOUNT_HOME	{TRUE,FALSE}
# ADM_OPERATION			{PREADD,POSTADD,PREMOD,POSTMOD,PREDEL,POSTDEL}
# PATH				/usr/sbin:/usr/bin
#
# Unlike in the hostmgr scripts, the original values are not passed down
# during a modify operation.
#
##############################################################################
# The following are just samples on things you might want to do in this
# script.  This script shows how a single script can do everything.  If you
# prefer, you can have one script per operation type.
#
# Determine if the operation is a PRE or a POST operation
pre=0
post=0
case $ADM_OPERATION in
    PRE*)pre=1;;
    POST*)post=1;;
esac

# Determine the type of operation
add=0
mod=0
del=0
case $ADM_OPERATION in
    *ADD) add=1;;
    *MOD) mod=1;;
    *DEL) del=1;;
esac

# Now decide what needs to be done.
if [ $add -eq 1 ]; then
    # We are creating a new user.  Check to see what the operation is.
    # Remember that this script is being run on the home directory server.
    if [ $pre -eq 1 ]; then
	# What ever gets put here would get called before the user gets
	# created.  The types of things that might be done here is setting up
	# of the server to support new users.  For example you might want to
	# add pkg 'X' to your server so your user's have access to it.
	echo "About to add a new user.  Am in the PREADD script."
	exit 0		# Probably want to exit just to be safe.
    fi
    if [ $post -eq 1 ]; then
	# What ever gets put here would get called after the user gets
	# created.
	# The types of things that might be done here are:
	#   - editing the user's .cshrc file to have certain aliases, paths,
	#     etc available to them.
	#   - adding additional files to the user's home area
	#   - sending email to a sysadmin letting them know about the new
	#     user
	#   - any other customizations you want to do to the user's home
	#     before the new user logs in.
	# For example:
	echo "alias ls ls -l" >> $ADM_USER_HOMEPATH
	echo "About to add a new user.  Am in the POSTADD script."
	exit 0		# Probably want to exit just to be safe.
    fi
    exit 0		# Probably want to exit just to be safe.
fi

# Modifying user information.
if [ $mod -eq 1 ]; then
    if [ $pre -eq 1 ]; then
	# Hard to say what you might want to do here before you modify the
	# user's home area.
	echo "About to modify user.  Am in the PREMOD script."
	exit 0		# Probably want to exit just to be safe.
    fi
    if [ $post -eq 1 ]; then
	# Now you can do just about anything you want to to the user.  For
	# example lets say you want to make sure the user has a certain file
	# in their home.  In this case you might do something like:
	if [ ! -f $ADM_USER_HOMEPATH/some/file ]; then
	    mkdir -p $ADM_USER_HOMEPATH/some
	    cp /some/path/to/some/file $ADM_USER_HOMEPATH/some/file
	fi
	echo "Modifying the user.  Am in the POSTMOD script."
	exit 0		# Probably want to exit just to be safe.
    fi
    exit 0		# Probably want to exit just to be safe.
fi

if [ $del -eq 1 ]; then
    if [ $pre -eq 1 ]; then
	# Before you delete the user, maybe you want to go into their home
	# area and save some file(s). 
	echo "Deleting user.  Am in the PREDEL script."
	exit 0		# Probably want to exit just to be safe.
    fi
    if [ $post -eq 1 ]; then
	# After deleting the user, maybe you want to go through the server
	# removing or changing the ownership of other files that might have
	# been owned by the user.  For example database entries, files in some
	# development tree etc.
	echo "Deleting user.  Am in the POSTDEL script."
	exit 0		# Probably want to exit just to be safe.
    fi
    exit 0		# Probably want to exit just to be safe.
fi

exit 0		# Probably want to exit just to be safe.
