#!/bin/sh

#######################################
## SRB2WII INITIALISATION RUNLEVEL S ##
#######################################

## 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"
OLDLOGCOMPAT="yes"
#--------------------#

rm -rf /tmp/*
touch /tmp/exports
export >> /tmp/exports
## Start bootsplash and add bootsplashoff to uexports if it exists
bootsplash="`cat $SYSCONF 2> /dev/null | grep Bootsplash | sed -ne 's/.*Bootsplash=\([^ ]*\).*/\1/p'`"
case $bootsplash in
	"On") startfbsplash || printdie -u "fbsplash failed to start, falling back to text mode.";;
	*) softkillfbsplash -u;;
esac

## uexport list. Anything exported with the uexport command is universal
uexport OSNAME "$OSNAME"
uexport OSLNAME "$OSLNAME"
uexport OSLLNAME "$OSLLNAME"
uexport OWNER "$OWNER"
uexport CONTRIBUTOR "$CONTRIBUTOR"
uexport SYSVER "$SYSVER"
uexport SYSREV "$SYSREV"
uexport SYSMINIBLDDATE "$SYSMINIBLDDATE"
uexport SYSBLDDATE "$SYSBLDDATE"
uexport LOGDIR "$LOGDIR"
uexport BLOCK_SIZE_SWAP "$BLOCK_SIZE"
uexport BLOCK_SIZE_SWAP "$BLOCK_SIZE_SWAP"
uexport BLOCK_SIZE_SWAP_2 "$BLOCK_SIZE_SWAP_2"
uexport SDCARD "$SDCARD"
uexport IMGDIR "$IMGDIR"
uexport USBMOUNT "$USBMOUNT"
# tell the userland that we are on a USB disk if we are
rm -rf /etc/.usbdisk
USBDISK="`cat /.usbdisk 2> /dev/null | sed -ne 's/.*USBDISK=\([^ ]*\).*/\1/p'`"
if [ "$USBDISK" = "yes" ]; then
	echo 'USBDISK="yes"' > /etc/.usbdisk
	echo 'MOUNT="USB stick"' > /etc/.usbdisk
	uexport USBDISK "yes"
fi
rm -rf /.usbdisk
## FIXME: for now, while mouse is sure to not be working
uexport SDL_NOMOUSE "1"

. /tmp/exports

ls /etc/rcS.d > /tmp/rcS
while read service
do
	loadfile /etc/rcS.d/$service start
done < /tmp/rcS

[ "$FIRSTSTART" ] && uexport FIRSTSTARTOVER "yes"
