#!/bin/sh
 
#TEMPDIR='/System/Library/User Template/Japanese.lproj/Library'
TEMPDIR='/Users/skel'
LIBDIR=${TEMPDIR}/Library

ADMIN_USER=admin

ID_LINE=`/usr/bin/id -P $1`
 
GROUP=`echo "${ID_LINE}"| /usr/bin/cut -f 4 -d":"` 
#GROUP=`id -g -nr`
HOME=`echo "${ID_LINE}"| /usr/bin/cut -f 9 -d":"`

if [ "$1" = "root" -o "$1" = "${ADMIN_USER}" ]
then
        exit 0
fi

su $1 -c "test -d ${HOME}"
if [ $? -ne 0 ]
then
   echo "${HOME} is not found."
   exit 0
fi

# Global Setting Section
PRINTER=`/etc/selpr.pl`
if [ -f ${TEMPDIR}/.lpoptions.${PRINTER} ]
then
  su $1 -c "cp ${TEMPDIR}/.lpoptions.${PRINTER} ${HOME}/.lpoptions"
fi

su $1 -c "test -f ${HOME}/.CFUserTextEncoding"
if [ $? -ne 0 ]
then
  su $1 -c "cp ${TEMPDIR}/.CFUserTextEncoding ${HOME}/.CFUserTextEncoding"
fi
su $1 -c /usr/local/bin/RemoveOfficeCache.sh

#
# Make Directry Section
#
for DIR in Library Documents Movies Pictures
do
    su $1 -c "test -d ${HOME}/${DIR}"
    if [ $? -ne 0 ]
    then
	 su $1 -c "/bin/mkdir ${HOME}/${DIR}"
	 su $1 -c "/usr/bin/touch ${HOME}/${DIR}/.localized"
    fi
done

# Preference Initialize Section 
su $1 -c "test -f ${HOME}/Library/.initialized"
if [ $? -eq 0 ]
then
	 exit 0
fi
su $1 -c "touch ${HOME}/Library/.initialized"
 
su $1 -c "/usr/bin/ditto -rsrcFork "${LIBDIR}" ${HOME}/Library"

/usr/sbin/chown -R $1:${GROUP} ${HOME}/Library

exit 0

