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

. /etc/init.d/functions

UMOUNT="umount"
[ ! -w /etc ] && UMOUNT="umount -n"

action() {
   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="Halting system..."
	command="/sbin/halt"
	;;
   *reboot)
	message="Please stand by while rebooting the system..."
	command="/sbin/reboot"
	;;
   *)
	gprintf "%s: call me as 'halt' or 'reboot' please!\n" $0
	exit 1
	;;
esac
case "$1" in
   *start)
   	;;
   *)
	gprintf "Usage: %s\n" "$(basename $0) {start}"
	exit 1
	;;
esac

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

# Remount read only anything that's left mounted.
printf "Remounting remaining filesystems readonly\n"
mount | awk '{ print $3 }' | while read line; do
    mount -o ro,remount $line
done

# Now halt or reboot.
echo "$message"

HALTARGS="-i -d"
exec $command $HALTARGS
