#!/bin/bash #-------------------------------------------------------------------------- # Copy the home dir of a user to a temporary location and copy the user # template to the user's home dir. This provides a consistent interface # for each user. # # Run as a login/logout hook via: # sudo defaults write com.apple.loginwindow Log[in|out]Hook /path/to/script # # Note that $1 is set to the current user when run as a hook. # # Pete Morris 05.Aug.2008 #-------------------------------------------------------------------------- # Set the following vars to reflect your system. managed_users=('student') # array of users to manage group='staff' # group of managed users. template_base='/Library/Management' # location of user templates. tmpdir='/Volumes/StudentData/archives' # where to store old home dirs. # Check usage. if [[ $# < 1 ]]; then echo "No user specified!" exit 1 fi # Do we need to manage the user logging in/out? user="$1" if echo ${managed_users[@]} | grep -q $user; then # create the tempdir if needed. [ -d "${tmpdir}" ] || mkdir "${tmpdir}" # Create a timestamp for old home dir storage. timestamp=$(date "+%Y%m%d-%H.%M.%S") # Move the old home dir. mkdir -m 755 "${tmpdir}/prevuser.${timestamp}" mv "/Users/${user}" "${tmpdir}/prevuser.${timestamp}" # Copy home dir template into place. /usr/bin/ditto -rsrcFork "${template_base}/${user}" "/Users/${user}" # Fix ownership of the new home dir. /usr/sbin/chown -R "${user}:${group}" "/Users/${user}" fi