#!/bin/sh

############################################################
## DEVICE NODE CREATION AND TEMP FILE DELETION 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
LOGFILE="$LOGDIR/$ME.log"
#--------------------#

log_action_begin_msg "Creating device nodes for input devices"
mkdir -p /dev/input > /dev/null 2>&1
#if [ -f /dev/mouse0 ]
#then
#	ln -s /dev/mice /dev/input/mice > /dev/null 2>&1
#	ln -s /dev/mouse0 /dev/input/mouse0 > /dev/null 2>&1
#else
#	export SDL_NOMOUSE=1
#fi
if [ -f /dev/event0 ]
then
	ln -s /dev/event0 /dev/input/event0 > /dev/null 2>&1
fi
if [ -f /dev/event1 ]
then
	ln -s /dev/event1 /dev/input/event1 > /dev/null 2>&1
fi
if [ -f /dev/event2 ]
then
	ln -s /dev/event2 /dev/input/event2 > /dev/null 2>&1
fi
if [ -f /dev/event3 ]
then
	ln -s /dev/event3 /dev/input/event3 > /dev/null 2>&1
fi
if [ -f /dev/event4 ]
then
	ln -s /dev/event4 /dev/input/event4 > /dev/null 2>&1
fi
if [ -f /dev/event5 ]
then
	ln -s /dev/event5 /dev/input/event5 > /dev/null 2>&1
fi

[ -d $HOME/.srb2 ] || mkdir -p $HOME/.srb2
[ -d $HOME/addons ] || mkdir -p $HOME/addons
[ -d $HOME/binaries ] || mkdir -p $HOME/binaries

# detect GameCube controllers
port="1"
while [ "$port" -le "4" ]; do
	controltype="`dmesg | grep "gcn-si: port $port" | awk '{ print $6 }'`"
	case "$controltype" in
		standard) echo "Wired" > /tmp/gcnport$port;;
		wireless) echo "WaveBird" > /tmp/gcnport$port;;
		*) echo "None" > /tmp/gcnport$port;;
	esac
	port="`expr $port + 1`"
done

log_action_end_msg 0
