# this file is sourced from /usr/sbin/linuxmuster-pam-mount

# source config file
. /etc/linuxmuster-client/profile/profile.conf || return 1
# source profile functions
. /var/lib/linuxmuster-client-profile/functions.inc || return 1

# log some info
$LOGGING && msg2log profile-pre-mount "Entering 001-profilecopy $1 $2"

$LOGGING && msg2log profile-pre-mount "Environment settings are: USER=$USER VOLUME=$VOLUME MNPT=$MNTPT OPTIONS=$OPTIONS SERVER=$SERVER NUMUID=$NUMUID NUMPRIGID=$NUMPRIGID FULLNAME=$FULLNAME HOMEDIR=$HOMEDIR LOGINSHELL=$LOGINSHELL"

# this script gets executed only once, before the users home from the
# server gets mounted. in this case $USER and $VOLUME are the same
if [ $USER != $VOLUME ]; then
    return 0
fi

# log success
$LOGGING && msg2log profile-pre-mount "We are mounting users home, copy default profile"

rm -rf $HOMEDIR
cp -r /home/$PROFILE_USER $HOMEDIR
mkdir -p $MNTPT
chown -R $USER $HOMEDIR
