#!/bin/sh
#
# rc.halt       This file is executed by init when it goes into runlevel
#               0 (halt) or runlevel 6 (reboot). It kills all processes,
#               unmounts file systems and then either halts or reboots.
#
# Author:       Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
#               Modified for RHS Linux by Damien Neil
#

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

. /etc/rc.d/init.d/functions

runcmd() {
   echo -n "$1 "
   shift
   if [ "$BOOTUP" = "color" ]; then
      $* && echo_success || echo_failure
   else
      $*
   fi
   echo
}

# See how we were called.
case "$0" in
  *halt)
	message="The system is halted"
	command="halt"
	;;
  *reboot)
	message="Please stand by while rebooting the system..."
	command="reboot"
	;;
  *)
	echo "$0: call me as \"rc.halt\" or \"rc.reboot\" please!"
	exit 1
	;;
esac

# Kill all processes.
[ "${BASH+bash}" = bash ] && enable kill

runcmd "Sending all processes the TERM signal..." kill -15 -1
sleep 5
runcmd "Sending all processes the KILL signal.."  kill -9 -1

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

runcmd "Unmounting file systems"  umount -a -f -r

# Remount read only anything that's left mounted.
#~~echo "Remounting remaining filesystems (if any) readonly"
#~~mount | grep ext2 | cut -f 3 -d ' ' | while read line; do
#~~    mount -n -o ro,remount $line
#~~done

# Ensure the flash is actually synched
sync
#~~bin/true < /dev/root

# Now halt or reboot.
echo "$message"
eval $command -i -d -p
