#!/bin/sh

##########################
## SHUTDOWN INIT SCRIPT ##
##########################

## Released under the GNU General Public License (version 2 or above)

## Any lines in this file preceeded by a hash ('#') indicates a comment, and is not read by the interpreter.

#--------------------#
. /etc/profile
LOGFILE="$LOGDIR/$ME.log"
. /tmp/exports
#--------------------#

ls /etc/rc0.d > /tmp/poweroff
while read service
do
	loadfile /etc/rc0.d/$service stop
done < /tmp/poweroff
print "Shutting down the Wii in 3 seconds..."
ps | grep -v -e "$0" -e "grep" -e "ps" -e "\[" -e "/etc/init/rc1" -e "launcher" -e "/bin/sh -i" -e "init" -e "kickstart" -e "PID" | awk '{ print $1 }' > /tmp/kill
mount | awk '{ print $3 }' | grep -v -e '/$' -e '/proc$' > /tmp/umount
while read kill; do
	kill $kill > /dev/null 2>&1
done < /tmp/kill
while read umount; do
	umount -l $umount > /dev/null 2>&1
done < /tmp/umount
sleep 3
mount -o remount,ro /
umount -l /proc
/etc/poweroff -f
