#!/bin/sh

##########################
## LAUNCHER INIT SCRIPT ##
##########################

## Callum Dickinson <gcfreak_ag20@hotmail.com>
## Sonic Team Junior <http://www.srb2.org>
## http://mb.srb2.org/showthread.php?t=31137
## svn://code.srb2.org/SRB2/branches/WII

## This program is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License
## as published by the Free Software Foundation; either version 2
## of the License, or (at your option) any later version.

## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.


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

#--------------------#
. /lib/lsb/init-functions
. /etc/profile
OLDLOGCOMPAT="yes"
LOGFILE="$LOGDIR/launcher-pre.log"
func="main"
proc="main"
#--------------------#

waddie()
{
	WADDIE="yes"
	diereal $@
}

killfbsplash -u

## check for SRB2 data files, otherwise not much purpose of running
[ -f $HOME/drill.dta ] || waddie N "drill.dta not found"
[ -f $HOME/knux.plr ] || waddie N "knux.plr not found"
[ -f $HOME/rings.wpn ] || waddie N "rings.wpn not found"
[ -f $HOME/soar.dta ] || waddie N "soar.dra not found"
[ -f $HOME/sonic.plr ] || waddie N "sonic.plr not found"
if ! [ -f $HOME/srb2.wad ]; then
	[ -f $HOME/srb2.srb ] || waddie N "srb2.wad or srb2.srb not found"
fi
[ -f $HOME/tails.plr ] || waddie N "tails.plr not found"
[ -f $HOME/zones.dta ] || waddie N "zones.dta not found"

if [ "$WADDIE" = "yes" ]; then
	diereal N "Files missing, please copy the missing files to $HOME on your SD card."
	reboot -c
fi

## music.dta isn't required
[ -f $HOME/music.dta ] || MUSDTA=1
if [ "$MUSDTA" = "1" ]; then
	warn N "music.dta not found"
	sleep 1
fi

## Actually (finally) run launcher! Yay!
loadfile `which launcher`
RUN="yes"
while [ "$RUN" = "yes" ]
do
	loadfile `which launcher` -s
done
