#! /bin/bash

# $Id$
# reboot FAI correctly, Thomas Lange, Uni Koeln, copyright 2000-2009

faimond=0
. /usr/lib/fai/subroutines

[ -f /tmp/fai/variables.log ] && . /tmp/fai/variables.log

while getopts s opt ; do
        case "$opt" in
        s) fai-savelog -r ;;
        esac
done

cd /
killall -STOP rcS
killall -q apt-get dpkg tar gzip yes cat syslogd 

[ "X" == "X$SSH_CLIENT" -a  "$TERM" != "dumb" ] && killall -q sshd

fai-divert -R

umount $FAI_ROOT/proc $FAI_ROOT/dev/pts
umount -ar
killall udevd

sendmon "FAIREBOOT"
echo "$HOSTNAME now rebooting"

if [ "X" == "X$SSH_CLIENT" -a  "$TERM" != "dumb" ]; then
    exec reboot -dfi
else
    killall -CONT rcS
    killall rcS
    init 6 &
fi
