#!/bin/bash
#
# 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
#               Modified for FiwixOS by Jordi Sanfeliu
#

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

# See how we were called.
case "$0" in
	*halt)
		message=$"Halting the system..."
		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

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

# Unmount file systems.
umount -a
mount -n -o ro,remount /

echo "Remounting remaining filesystems (if any) readonly"
mount | awk '/minix/ { print $3 }' | while read line; do
    mount -n -o ro,remount $line
done
mount | awk '/ext2/ { print $3 }' | while read line; do
    mount -n -o ro,remount $line
done

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

