#!/bin/bash # # linuxmuster-client-offline # # Tobias Küchel 2014, # 04.11.2014 # GPLv2 . /etc/linuxmuster-client/offlineuser/config [ "x$offlineuserenabled" != "xyes" ] && exit 0 # files involved: # /etc/linuxmuster-client/offlineuser/config # lightdm.conf.online,offline # -> session-cleanup-script=/usr/bin/linuxmuster-check-offlineity # /etc/rc.local (workaround for boot.d not working) # /usr/bin/linuxmuster-setup-offlineuser # linuxmuster-client-extras-setup --type login --order 020 --on /usr/local/bin/linuxmuster-setup-offlineuser # leoclient-vm-printer.conf # run-vm-printer-splitter # run-vm-printer-spooler # functions log_msg() { logger -t check-offlineity "$1" } STATUSFILE=/etc/linuxmuster-client/offlineuser/offline PROFILE_USER=linuxadmin HOMEDIR=/home/$offlineuser ## save the old status of offlineity [ -e $STATUSFILE ] && OLDSTATUS=1 || OLDSTATUS=0 log_msg "Offlineity was: $OLDSTATUS" ## ## check if we are offline ## if ! ping -c 1 10.16.1.1 >/dev/null ; then ## we should be offline echo 1 > $STATUSFILE else ## we should be online, revert changes rm -f $STATUSFILE fi ## Debugging FORCE offline #echo 1 > $STATUSFILE #printenv >> /tmp/asdfasdf.$$ ## ## check, if change is needed ## restart=0 if [ -e $STATUSFILE -a $OLDSTATUS -eq 0 ]; then restart=1 fi if [ ! -e $STATUSFILE -a $OLDSTATUS -eq 1 ]; then restart=1 fi if [ -n "$1" -a "x$1"="x--init" ]; then restart=1 log_msg "Called using --init. We set current status offline/online." fi ## no change needed, get out [ $restart -eq 0 ] && { log_msg "No change needed."; exit 0; } || log_msg "Changing offline/online status." log_msg "Lokales Verzeichnis erstellen/überprüfen" mkdir -p $offlinetargetdir chown $offlineuser $offlinetargetdir if [ -e $STATUSFILE ]; then log_msg "Seem to be offline. Change to offline." #pw="$offlineuser"':$6$SCla3OOt$DJSgJ35o/AJxJ0dD5EbkeC7BazOEQlEQfuL.KjlWVNL4XQf3CjXClBe64fN6kaGnryM25WyhnplaZ8fZVEYQs0:16091::::::' pw="${offlineuser}:${offlineuserpw}:16091::::::" ## Repair leoclient-vm-printer log_msg "Fix leoclient-vm-printer to point to Home_lokal" sed -i "s/Home_auf_Server/Home_lokal/g" /etc/leoclient/leoclient-vm-printer.conf log_msg "Disable network on firewall" iptables -A OUTPUT -p all -m owner --uid-owner $offlineuser -j DROP log_msg "autologin lightdm config" unlink /etc/lightdm/lightdm.conf sed -i "s/%offlineuser%/$offlineuser/" /etc/linuxmuster-client/offlineuser/lightdm.conf.offline ln -s /etc/linuxmuster-client/offlineuser/lightdm.conf.offline /etc/lightdm/lightdm.conf else log_msg "Seem to be online. Change to online." pw="$offlineuser"':*:16091:::::' ## Repair leoclient-vm-printer log_msg "Fix leoclient-vm-printer to point to Home_auf_Server" sed -i "s/Home_lokal/Home_auf_Server/g" /etc/leoclient/leoclient-vm-printer.conf log_msg "Enable network on firewall" iptables -D OUTPUT -p all -m owner --uid-owner $offlineuser -j DROP unlink /etc/lightdm/lightdm.conf ln -s /etc/linuxmuster-client/offlineuser/lightdm.conf.online /etc/lightdm/lightdm.conf fi ## replace the lehrer pw log_msg "Replace the $offlineuser pw" sed -i "s@^$offlineuser:.*@${pw}@" /etc/shadow ## workaround fast VNC log_msg "Background setzen" sed -i 's@@@' $HOMEDIR/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-desktop.xml ## ## Restart X and lightdm, if status changed ## ## if the service is running, grep returns 0, then stop lightdm if service lightdm status | grep running >/dev/null ; then service lightdm stop sleep 2 fi ## workaround: printer-spooler stays after logout pkill 'run-vm-printer' ## Sync the PROFILE_USER to the offlineuser ## This only works, if the $offlineuser is not logged in, thus when lightdm is down log_msg "Synching: rsync -rlpt --force --delete /home/$PROFILE_USER/ $HOMEDIR/ " rsync -rlpt --force --delete /home/$PROFILE_USER/ $HOMEDIR/ chown -R $offlineuser:$offlineuser $HOMEDIR ## now start (again) service lightdm start