170 lines
3.7 KiB
Bash
Executable File
170 lines
3.7 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
PREFIX=/usr/local/bin/wmde
|
|
|
|
. /etc/wmde-rp.conf
|
|
|
|
#set -x
|
|
#set -e
|
|
|
|
cd /tmp
|
|
|
|
. $PREFIX/wmde-rp-check-pam-user.sh #exit if user does not belong to rp criteria
|
|
|
|
|
|
|
|
#echo "WMDE Roaming Profile"
|
|
|
|
export HOMEDIR=$(getent passwd "$PAM_USER" | cut -d: -f6)
|
|
export WMDE_UNISONARGS="-auto -log -prefer newer -batch"
|
|
export UNISON=$HOMEDIR/.unison-wmde
|
|
export PAM_USER=$PAM_USER
|
|
export SSHARGS="-o UserKnownHostsFile=$HOMEDIR/.wmdesync/known_hosts"
|
|
|
|
|
|
|
|
. $PREFIX/wmde-rp-common.sh
|
|
|
|
TIMEOUT=30
|
|
|
|
|
|
|
|
#if [ -f "$FIFULLSYNC" ]; then
|
|
# exit 0
|
|
#fi
|
|
|
|
if [ ! -f "$FIRSTSYNC" ]; then
|
|
FIRSTRUN="first"
|
|
else
|
|
FIRSTRUN="no"
|
|
|
|
fi
|
|
|
|
echo "FIRST $FIRSTRUN" >> /tmp/wtforsyc.txt
|
|
|
|
|
|
if [ "$WAIT_FOR_CONFIG" = "never" ] && [ "$WAIT_FOR_FULLSYNC" = "never" ] && [ "$WAIT_FOR_SMALLFILESSYNC" = "never" ]; then
|
|
exit 0
|
|
fi
|
|
|
|
# wait for pid file to be created (max 30 seconds)
|
|
i=0
|
|
while [ $i -lt $TIMEOUT ]; do
|
|
echo "WAITING FOR PIDFILE $i" >> /tmp/wtforsyc.txt
|
|
if [ -f "$PIDFILE" ]; then
|
|
echo "FOUND PID FILE" >> /tmp/wtforsyc.txt
|
|
PID=`cat $PIDFILE`
|
|
if kill -0 "$PID" 2>/dev/null; then
|
|
break
|
|
fi
|
|
fi
|
|
sleep 1
|
|
i=$((i + 1))
|
|
done
|
|
if [ $i -eq $TIMEOUT ]; then
|
|
echo "NO PIDFILE - ERROR" >> /tmp/wtforsyc.txt
|
|
exit 1
|
|
fi
|
|
echo "PID is $PID my PID $$" >> /tmp/wtforsyc.txt
|
|
|
|
|
|
echo "Loading roaming profile, please be patient ..."
|
|
|
|
wait_for_sync() {
|
|
# $1 dir to watch
|
|
# $2 pid_file
|
|
|
|
while kill -0 "$PID" 2>/dev/null && [ "$PID" != "`cat $2`" ]; do
|
|
size=$(du -sh $1 2>/dev/null | cut -f1)
|
|
#echo "Loading roaming profile: $size / $xsize"
|
|
echo "$3 $size $4"
|
|
echo "PID: $PID in file $2: `cat $2`" >> /tmp/wtforsyc.txt
|
|
sleep 3
|
|
done
|
|
echo "FINAL PID: $PID in file $2: `cat $2`" >> /tmp/wtforsyc.txt
|
|
|
|
|
|
# echo "Parameter 1: $1"
|
|
# echo "Parameter 2: $2"
|
|
}
|
|
|
|
if [ "$WAIT_FOR_CONFIG" = "always" ] || [ "$WAIT_FOR_CONFIG" = "$FIRSTRUN" ]; then
|
|
echo "Wait for Config" >> /tmp/wtforsyc.txt
|
|
wait_for_sync $HOMEDIR/.config $CONFIGSYNC "Loading config:" ""
|
|
fi
|
|
|
|
if [ "$WAIT_FOR_SMALLFILESSYNC" = "always" ] || [ "$WAIT_FOR_SMALLFILESSYNC" = "$FIRSTRUN" ]; then
|
|
echo "Wait for Small files" >> /tmp/wtforsyc.txt
|
|
wait_for_sync $HOMEDIR $SMALLFILESSYNC "Loading small files:" ""
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ "$WAIT_FOR_FULLSYNC" = "always" ] || [ "$WAIT_FOR_FULLSYNC" = "$FIRSTRUN" ]; then
|
|
|
|
echo "Wait for fullsync" >> /tmp/wtforsyc.txt
|
|
i=0
|
|
while [ $i -lt $TIMEOUT ]; do
|
|
if [ -f "$HOMEDIR/.wmdesync/known_hosts" ]; then
|
|
break
|
|
fi
|
|
sleep 1
|
|
i=$((i + 1))
|
|
done
|
|
|
|
if [ $i -eq $TIMEOUT ]; then
|
|
xsize="unknown"
|
|
else
|
|
xsize=$(sudo -E -u $PAM_USER ssh $SSHARGS $NFSSERVER "du -sh $HOMDIR | cut -f1")
|
|
fi
|
|
|
|
|
|
wait_for_sync $HOMEDIR/ $FULLSYNC "Loading profile:" "/$xsize"
|
|
fi
|
|
|
|
echo "Finished" >> /tmp/wtforsyc.txt
|
|
exit 0
|
|
|
|
|
|
|
|
|
|
|
|
PID=`cat $PIDFILE`
|
|
while kill -0 "$PID" 2>/dev/null; do
|
|
if [ -f "$FULLSYNC" ]; then
|
|
exit 0
|
|
fi
|
|
size=$(du -sh $HOMEDIR | cut -f1)
|
|
echo "Loading roaming profile: $size / $xsize"
|
|
sleep 3
|
|
done
|
|
|
|
echo "Failed to initialize roaming profile."
|
|
sleep 5
|
|
exit 1
|
|
|
|
|
|
|
|
if [ ! -f "$HOMEDIR/.wmdesync/known_hosts" ]; then
|
|
#sudo -E -u $PAM_USER /bin/sh -c "$PREFIX/wmde-rp-unison-initial-sync-nfs.sh"
|
|
sudo -E -u $PAM_USER /bin/sh -c "$PREFIX/wmde-rp-usersync-ssh.sh pam"
|
|
LASTERROR=$?
|
|
if [ $LASTERROR -ne 0 ]; then
|
|
echo "Initial sync with WMDE roaming profile failed. $LASTERROR"
|
|
sleep 20
|
|
rm -f "$HOMEDIR/.wmdesync/known_hosts"
|
|
exit $LASTERROR
|
|
fi
|
|
|
|
fi
|
|
|
|
#if [ ! -f "$HOMEDIR/.config/systemd/user/default.target.wants/wmde-rp-usersync.service" ]; then
|
|
|
|
# sudo -E -u $PAM_USER mkdir -p $HOMEDIR/.config/systemd/user/default.target.wants #2>>/tmp/login.txt
|
|
# sudo -E -u $PAM_USER ln -s /etc/systemd/user/wmde-rp-usersync.service $HOMEDIR/.config/systemd/user/default.target.wants/wmde-rp-usersync.service #2>>/tmp/login.txt
|
|
#fi
|
|
#sudo -E -u $PAM_USER systemctl --user start wmde-rp-usersync.service
|
|
|
|
|