#!/sbin/sh
#
# Customizing files in jumpstart client / directory
#
if [ -z "${slash_a}" ] ; then
	if [ -r /a/etc/vfstab ] ; then slash_a=/a ; else slash_a=/ ; fi
	export slash_a
fi

if [ -z "${SI_CONFIG_DIR}" ] ; then
	SI_CONFIG_DIR=/export/install/config
	export SI_CONFIG_DIR
fi


MNT=/tmp/Personality
ConfHost=`mount | grep "$SI_CONFIG_DIR on" | awk '{print $3}' | awk -F: '{print $1}'`
PersDir=/export/install/Personality

#
# Actually, Personality directory is supposed to be already
# mounted read/write by begin script. If somehow it is not,
# try to mount it again
#

[ -d "$MNT" ] || mkdir -p $MNT
[ -d "$MNT/Std" ] || {
  /sbin/mount ${ConfHost}:${PersDir} $MNT || {
       echo "
	Cannot mount Personality directory ${ConfHost}:${PersDir} on $MNT
	Logs not copied
    "
    exit 1
  }
}

PERS=$MNT
LOG=${slash_a}/RootDirCustLog
touch $LOG || exit 1

MACHINE=`uname -n | awk -F. '{print $1}'`
DOMAIN=`domainname | awk -F. '{print $1}'`
LIST="
 ${PERS}/Std/Rootdir
 ${PERS}/${DOMAIN}/Std/Rootdir
 ${PERS}/${DOMAIN}/${MACHINE}/Rootdir
"

exec >>${LOG} 2>>${LOG}

for i in ${LIST}
do
    if [ -d $i ] ; then
	echo === Files added from $i ===
	(cd $i && find . -depth -print | tee -a $LOG | cpio -oc) |\
	    (cd ${slash_a} && cpio -ivucd)
    fi
done    > /dev/null 2>&1

