#!/bin/sh
# $Owl: Owl/packages/owl-startup/halt,v 1.8 2012/02/27 07:55:19 solar Exp $
#
# This file is based on several Debian scripts by Miquel van Smoorenburg.
#

# See how we were called.
MESSAGE=
COMMAND="poweroff"
case "$0" in
*reboot)
	MESSAGE="Rebooting... "
	COMMAND="reboot"
esac

# Kill all processes.
echo "Sending all processes the TERM signal"
killall5 "-`kill -l TERM`"

# Save the system time to the hardware clock.  This might take a second, so we
# do it when the delay is actually useful.
if [ -e /etc/rc.d/init.d/clock ]; then
	. /etc/rc.d/init.d/clock save
fi

sleep 5
echo "Sending all processes the KILL signal"
killall5 "-`kill -l KILL`"

# Write a reboot record to /var/log/wtmp before unmounting.
halt -w

if [ -x /sbin/accton ]; then
	/sbin/accton off
fi

if [ -x /sbin/quotaoff ]; then
	echo "Turning off quotas"
	/sbin/quotaoff -a
fi

echo "Unmounting filesystems"
umount -f -a -r

echo "Remounting root filesystem read-only"
mount -n -o remount,ro /

echo "Turning off swap"
swapoff -a

echo -n "$MESSAGE"
$COMMAND -d -f -i
