#!/bin/sh
#
#  rc.6: shutdown and halt 
#  by M. Andreoli, for muLinux

# Set the path.
PATH=/sbin:/bin:/usr/bin:/usr/bin

if [ -x /bin/stty ] || [ -x /usr/bin/stty ] ; then
	stty onlcr
fi

echo
set -- `cat /proc/uptime`
echo " -- Thank You, an exciting session, started `expr $2 / 60`' ago."
#setup -a shutdown stop
/usr/bin/soft-shutdown

echo
echo "Syncing disks ..."
sync

case $0 in
*6)
command="reboot"
message1="Please, stand by while rebooting the system ..."
message2="Rebooting ..."
;;
*0)
command="halt"
message1="Please, stand by while halting the system ..."
;;
esac


echo "Sending all processes the TERM signal..."
killall5 -15 
sleep 5 
echo "Sending all processes the KILL signal.."
killall5 -9 

kill -9 `pidof update` 2>/dev/null

# Write to wtmp file before unmounting /var
halt -w

echo
echo -n "Turning off swap"

(
swapoff /dev/swap 
) 2>/dev/null

echo
echo -n "Unmounting file systems: "

umount /usr 2>/dev/null
umount /usr/X11R6 2>/dev/null

mount | rgrep -v "/dev/ram" | rgrep -v "/proc" | rgrep -v " / " |\
while read line; do
    set -- $line
    echo -n " $3"
    [ "$(which fuser)" ] && fuser -mk $3 1>/dev/null 2>/dev/null
    umount  $3
    sleep 1
done

echo
echo

mount -n -o remount,ro / 2>/dev/null

# Now halt or reboot.

echo $message1 
sleep 2 
[ "$message2" ] && echo $message2
eval $command -d -f


# End
