#!/bin/sh
. /var/smoothwall/main/settings

umask 022

echo "Setting hostname"
hostname $HOSTNAME

#loadkeys /usr/lib/kbd/keymaps/i386/qwerty/uk.kmap.gz
loadkeys /usr/lib/kbd/keymaps/i386/azerty/fr-latin1.kmap.gz
# BIOS interface
insmod toshiba

PATH=/bin:/sbin:/usr/bin:/usr/sbin
export PATH

STRING="Checking root filesystem"

fsck -T -a -C /
RC=$?  

if [ "$RC" = "0" ]; then
	echo "$STRING: Success"
elif [ "$RC" = "1" ]; then
	echo "$STRING: Passed"
fi

# A return of 2 or higher means there were serious problems.
if [ $RC -gt 1 ]; then
	echo "$STRING: Failed"
	echo "*** An error occurred during the file system check."
	echo "*** Dropping you to a shell; the system will reboot"
	echo "*** when you leave the shell."
	export PS1="(Repair filesystem) \# # "
	sulogin
	echo "Unmounting filesystems"
	umount -a
	mount -n -o remount,ro /
	echo "Automatic reboot in progress."
	reboot -f
fi

echo "Mounting filesystems"
mount -n -o remount,rw / 
mount /proc
echo "Turning on swap"
swapon -a
echo "Module depandencies"
depmod -a
echo "Clearing old files"
chmod 660 /dev/ttyS*
chmod 660 /dev/ttyI*
rm -f /var/run/*.pid
rm -f /var/smoothwall/red/*
rm -f /var/lock/LCK..ttyS*

echo "Setting the clock"
hwclock --hctosys

if [ ! -e /usr/local/etc/ssh_host_key ]; then
	echo "Generating SSH RSA key.  This may take several minutes."
	/usr/local/bin/ssh-keygen -b 1024 -f /usr/local/etc/ssh_host_key -N ""
fi
if [ ! -e /usr/local/etc/ssh_host_dsa_key ]; then
	echo "Generating SSH DSA key.  This may take several minutes."
	/usr/local/bin/ssh-keygen -d -f /usr/local/etc/ssh_host_dsa_key -N "" 
fi

echo "Rotating logs"
/usr/sbin/logrotate /etc/logrotate.conf

echo "Running /etc/rc.d/rc.network"
. /etc/rc.d/rc.network

echo "Starting syslogd"
/sbin/syslogd -m 0
echo "Starting klogd"
/sbin/klogd
echo "Starting crond"
/usr/sbin/crond
echo "Starting inetd"
/usr/sbin/inetd
echo "Starting httpd"
/usr/sbin/httpd
echo "Starting dhcpd (if enabled)"
/usr/local/bin/restartdhcp
echo "Starting sshd (if enabled)"
/usr/local/bin/restartssh
echo "Silencing kernel. syslog output on tty12."
echo >/proc/sys/kernel/printk "1 4 1 7"

logger -t smoothwall "SmoothWall started."

/sbin/tosh_lcd -0
/sbin/hdparm -c 1 -m 16 -S 6 /dev/hda
