
# set defaults
[ -e /etc/rc.defaults ] && . /etc/rc.defaults

# include overrides
if [ -e /etc/rc.conf ]
then
	. /etc/rc.conf
else
	echo "The file /etc/rc.conf does not exist on your system,"
	echo "so the default configuration will be used."
	echo "The file /etc/rc.defaults contains instructions on how"
	echo "to create /etc/rc.conf to customise your dslinux installation."
fi

if [ ! "$font" = "" ]
then
	if [ -e "$font" ]
	then
		echo "Changing font size to $font" 
		echo "Type 'consolechars -R' to revert" 
		/usr/bin/consolechars -f $font
	else
		echo "$font does not exist!"
	fi
fi

# /opt is BEFORE /usr/bin to speed up some applications
PATH=/bin:/sbin:/opt:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
export PATH

# create /etc/passwd if it doesn't exist
if [ ! -f /etc/passwd ]
then
	echo "Creating default /etc/passwd"
	echo "root:xxSVJVBe8UDn2:0:0:Tim Bisley:/home:/bin/sh" > /etc/passwd
	echo "bin:x:1:1:bin:/bin:" >> /etc/passwd
	echo "daemon:x:2:2:daemon:/sbin:" >> /etc/passwd
	echo "nobody:x:99:99:Nobody:/:" >> /etc/passwd
fi

if [ "$start_syslogd" = "YES" ]
then
		/etc/rc.d/syslogd start
	else
		echo "Not starting syslogd"
fi

if [ "$start_hinged" = "YES" ]
then
		/etc/rc.d/hinged start
	else
		echo "Not starting hinged"
fi

# setup networking
if [ "$enable_network_on_boot" = "YES" ]
then
	if /etc/rc.d/network start
	then
		__network_up="YES"
	else
		__network_up="NO"
	fi
else
	echo "Not configuring network:"
	echo "enable_network_on_boot is set to \"$enable_network_on_boot\""
	echo "To configure wireless edit /etc/rc.conf or run 'wnc'."
	__network_up="NO"
fi
#Start iptables before other services
if [ "$start_iptables" = "YES" ]
then
	if [ "$__network_up" = "YES" ]
	then
		/etc/rc.d/iptables start
	else
		echo "Not starting iptables: network is down"
	fi
fi
# start inetd if configured
if [ "$start_inetd" = "YES" ]
then
	if [ "$__network_up" = "YES" ]
	then
		/etc/rc.d/inetd start
	else
		echo "Not starting inetd: network is down"
	fi
fi

if [ "$start_openvpn" = "YES" ]
then
	if [ "$__network_up" = "YES" ]
	then
		/etc/rc.d/openvpn start
	else
		echo "Not starting openvpn: network is down"
	fi
fi

if [ "$start_boa" = "YES" ]
then
	if [ "$__network_up" = "YES" ]
	then
		/etc/rc.d/boa start
	else
		echo "Not starting boa: network is down"
	fi
fi

if [ "$start_inadyn" = "YES" ]
then
	if [ "$__network_up" = "YES" ]
	then
		/etc/rc.d/inadyn start
	else
		echo "Not starting inadyn: network is down"
	fi
fi

if [ "$start_esd" = "YES" ]
then
	if [ "$__network_up" = "YES" ]
	then
		/etc/rc.d/esd start
	else
		echo "Not starting esd: network is down"
	fi
fi

# Check for update if specified
if [ "$check_update" = "YES" ]
then
	if [ "$__network_up" = "YES" ]
	then
		echo "Checking for update"
		/etc/rc.d/update check
	else
		echo "Not checking for update: network is down"
	fi
fi
# set hostname
hostname $hostname

# set up /etc/hosts so networking tools will work
echo "127.0.0.1 $hostname" > /etc/hosts

# if we have extra RAM, enable 2 extra terminals and gpm
exec 0</proc/meminfo
read line
exec 0</dev/null
set -- $line
if [ $2 -gt 4000 ]
then
	/usr/bin/agetty -n -l /bin/autologin 38400 tty2 linux &
	/usr/bin/agetty -n -l /bin/autologin 38400 tty3 linux &
	if [ -x /usr/bin/gpm ]
	then
	/usr/bin/gpm -m /dev/mouse0 -t ps2 &
	fi
fi

# show firmware version if configured
[ "$show_firmware_version" = "YES" ] && fwver

# run local startup script if it exists
[ -e /etc/rc.local ] && . /etc/rc.local

# setup nano-X
if [ "$start_nanox" = "YES" ]
then
	fbset -depth 16 -n
	ifconfig lo up
fi

# setup PIXIL
if [ "$start_pixil" = "YES" ]
then
	/usr/pixil/nxstart.sh&
fi

# this is here so that we will get a login prompt in any case
exit 0
