#!/bin/tcsh -f

############################ refresh-default-homedir.sh ############
# Mike Bombich | mike@bombich.com                
# Copyright 2003 Mike Bombich.     
# Use Loginwindow Manager (http://www.bombich.com/software/lwm.html)
# to make this shell script run each time a user logs in or out.
####################################################################


### Description ###
#
# The purpose of this script is to move the home directory
# of the user that was just logged in to a temporary location,
# then copy the user template to the Users directory to provide a
# fresh, consistent interface for the next user.
# This script assumes that you want to manage users that all have
# the same home directory specified in NetInfo or LDAP.
# 
# If a user that just logged out realizes that they need
# something that was saved in the home directory, they can get to
# it by selecting "Go to Folder..." from the Finder's "Go" menu,
# then typing "/tmp". This script will only replace a home
# directory if the same user logs in (e.g. the default "student"
# user). If you login as the local admin, for example,
# the "student" user directory will still be in /Users.
#
# /tmp is cleared out on restarts. You could also create a cron task
# to remove these backups on a regular basis


### Properties ###
#
# These items must be modified to suit your environment before
# implementing this script! You do not need to make any other
# modifications to this file than these properties.
#
# defGrp: the group that your default user is assigned to
# defHome: the location of your default user's home directory
# defTemplate: the location of your default user home dir template
set defGrp = staff
set defHome = /Users/default
set defTemplate = /Library/Management/default
set tmpDir = /Library/Management/savedHomeDirs
set localAdmin = admin


### Debug/testing sanity check ###
if ( $#argv < 1 ) then
	echo "No user specified!"
	exit 1
endif


### Script action ###
# If this is not the admin user...
if ( $1 != $localAdmin ) then
	# Create a timestamp for the temporary home directory storage
	set time = `date ''+%m-%d-%y_%H.%M.%S''`

	# Move the home directory
	mkdir -m 755 "${tmpDir}/prevuser.$time" 
	mv $defHome "${tmpDir}/prevuser.$time"

	# Copy a new default home directory from the user template
	/usr/bin/ditto -rsrcFork $defTemplate $defHome

	# Change the ownership of the new home directory to the user logging in
	/usr/sbin/chown -R ${1}:${defGrp} $defHome
endif

### Always exit with 0 status
exit 0




