#!/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 UNISON=$HOMEDIR/.unison-wmde export PAM_USER=$PAM_USER export SSHARGS="-o UserKnownHostsFile=$HOMEDIR/.wmdesync/known_hosts" . $PREFIX/wmde-rp-common.sh TIMEOUT=10 echo "WAIT_FOR_FULLSYNC=$WAIT_FOR_FULLSYNC" >> /tmp/wtforsyc.txt echo "WAIT_FOR_CONFIGC=$WAIT_FOR_CONFIG" >> /tmp/wtforsyc.txt if [ "$WAIT_FOR_CONFIG" = "never" ] && [ "$WAIT_FOR_FULLSYNC" = "never" ] ; then echo "Both, WAIT_FOR_CONFIG and WAIT_FOR_FULLSYNC are never - exit 0" >> /tmp/wtforsyc.txt exit 0 fi echo "Loading roaming profile, please be patient ..." if [ ! -f "$FIRSTSYNC" ]; then FIRSTRUN="first" echo "File $FIRSTSYNC does not exists, setting FIRSTRUN=$FIRSTRUN." >> /tmp/wtforsyc.txt else FIRSTRUN="no" echo "File $FIRSTSYNC found, setting FIRSTRUN=$FIRSTRUN." >> /tmp/wtforsyc.txt fi # wait for pid file to be created (max 30 seconds) i=0 while [ $i -lt $TIMEOUT ]; do if [ -f "$PIDFILE" ]; then PID=`cat $PIDFILE` echo "Found pid file $PIDFILEE with content: $PID" >> /tmp/wtforsyc.txt if kill -0 "$PID" 2>/dev/null; then break fi fi echo "No pid file $PIDFILE found, waiting sice $seconds" >> /tmp/wtforsyc.txt sleep 1 i=$((i + 1)) done if [ $i -eq $TIMEOUT ]; then echo "Roaming profile failed - timeout." echo "NO PIDFILE - ERROR" >> /tmp/wtforsyc.txt exit 0 fi echo "PID is $PID my PID $$" >> /tmp/wtforsyc.txt 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/ $CONFIGSYNC "Loading config:" "" 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