#!/bin/sh
# Xwoaf sysinit rev. 0.2.0g Oct. 29, 2005.
# (C) Terry Loveall, GPL Ver 2.
# remount on the RAMDISK
/bin/mount -o remount,rw /
export PATH=/bin:/sbin:/usr/bin:/usr/sbin

# To use DHCP instead of a static IP, set this value to "yes":
DHCP="yes"            # Use DHCP ("yes" or "no")

# setup pts
mount /dev/pts

# create necessary directories
/bin/busybox mkdir /proc /mnt /tmp /lib/modules /usr/sbin /usr/bin
mount /proc

# create busybox soft links
/bin/busybox --install -s

# uncomment to start X immediately after login
# touch /etc/autologin

# setup networks for loopback
echo -e "loopback 127.0.0.0\nlocalnet 0.0.0.0" > /etc/networks

# setup internet demon inet.d (unused)
echo -e "80	stream	tcp	nowait	nobody	/sbin/sh-httpd\n25	stream	tcp	nowait	nobody /sbin/sh-smtp" > /etc/inetd.conf

# create non-shadow based passwd file and groups
echo -e "root:dEHtTH4Yy0W/Y:0:0:root:/root:/bin/sh\ndaemon::1:1::/:\nnobody::65534:65534::/tmp:\napache:x:48:48:Apache:/var/www:" > /etc/passwd
echo -e "root:x:0:\ndaemon:x:1:\ntty:x:2:\nguest:x:501:\napache:x:48:" > /etc/group

# create essential /var directory tree and files
mkdir /var
cd /var ; 
mkdir adm lock log portsentry run sh-www spool spool/cron spool/cron/crontabs spool/mail spool/mail/root
for f in `echo -e "run/utmp\nlog/messages\nlog/sh-httpd.log\nlog/wtmp"`
do
  echo "" > $f
done

# setup networking specifics
cd /

# configure name resolution order
echo -e "order hosts,bind\nmulti on" > /etc/host.conf

# name that computer
echo "george" > /etc/hostname

# alias it
echo -e "127.0.0.1\tlocalhost.localdomain localhost\n0.0.0.0\tlocalhost\n" > /etc/hosts

# say who are its friends
if [ "$DHCP" = "yes" ]; then # configure hosts for DHCP
  echo -e "127.0.0.1 george\n" >> /etc/hosts
else # configure with static IPs
  echo -e "192.168.0.3 george\n192.168.0.1 gateway\n" >> /etc/hosts
fi
echo "ALL: LOCAL" > /etc/hosts.allow

# and who are its enemies
echo "ALL: ALL" > /etc/hosts.deny

# configure name servers for
echo -e "nameserver 206.81.192.1\nnameserver 204.147.80.5" > /etc/resolv.conf

echo "Setting hostname: ";hostname -F /etc/hostname
echo "Cleaning up system: "
> /var/run/utmp
touch /var/log/wtmp;chmod 0664 /var/run/utmp
chmod 0664 /var/log/wtmp;chmod 0660 /var/log/messages
echo "Starting interface lo: ";ifconfig lo up 127.0.0.1
echo "Starting syslogd: "; syslogd -m 20 
echo "Starting klogd: ";klogd

# Windows On A Floppy - X that is.
echo -e "Xwoaf-0.2.0g `uname -s` `uname -r` [`uname -m` arch]\n" > /etc/issue

# setup missing X-window directories, files and soft links
pth=/usr/X11R6/bin
cd $pth

# create the file known as startx
echo -e "#!/bin/sh" > startx
echo -e "export PATH=$PATH:/usr/X11R6/bin" >> startx
echo -e "export DISPLAY=0.0.0.0:0" >> startx

if [ -f /usr/X11R6/bin/Xvesa ];then
  #Xvesa section
  # uncomment the next line for X auto mouse detection
  #echo -e "$pth/X -screen 800x600x256 &" >> startx
  # uncomment the next line if you have a ps2 wheel mouse
  echo -e "$pth/X -screen 800x600x256 -mouse /dev/psaux,5 &" >> startx
fi

if [ -f /usr/X11R6/bin/Xfbdev ];then
  #Xfbdev section: uses default fb mode the kernel boots in
  # uncomment the next line for X auto mouse detection
  #echo -e "$pth/X &" >> startx
  # uncomment the next line if you have a ps2 wheel mouse
  echo -e "$pth/X -mouse /dev/psaux,5 &" >> startx
fi

echo -e "/usr/X11R6/lib/X11/xinit/xinitrc" >> startx
chmod a+x startx
ln -sf /sbin/reboot shutdown
pth=/usr/X11R6/lib
cd $pth

# create /usr/X11R6/lib/X11/Xinit
cd X11 ; mkdir xinit ; cd xinit

pth=/usr/X11R6/bin
# create xinitrc and mark it executable
echo -e "#!/bin/sh" > xinitrc
echo -e "$pth/jwm &" >> xinitrc
echo -e "sleep 2" >> xinitrc
echo -e "$pth/xsetroot -solid SteelBlue" >> xinitrc
echo -e "$pth/rxvt -fg white -bg black -font 7x14 -ls -sl 500 -sr +st -geometry 96x28+60+160 -title 'Xwoaf Term' &" >> xinitrc
echo -e "sleep 2" >> xinitrc
#echo -e "$pth/retawq /README.htm &" >> xinitrc
chmod a+x xinitrc
cd /
#end of X-window setup

echo "Installing modules"
/bin/cat <<EOF >/etc/rc.d/rc.modules
#!/bin/sh
insmod /lib/modules/8390.o
insmod /lib/modules/ne.o io=0x340 > /dev/null 2>&1 && return 0
insmod /lib/modules/ne2k-pci.o > /dev/null 2>&1 && return 0
#insmod /lib/modules/3c90x.o
EOF

chmod a+x /etc/rc.d/rc.modules
. /etc/rc.d/rc.modules

# Set up to start the network interface card:
echo -e "#!/bin/sh" > /bin/netstart
if [ "$DHCP" = "yes" ]; then # use DHCP to set everything up:
  echo "Attempting to configure eth0 by contacting a DHCP server..."
  echo -e "/sbin/udhcpc -s /etc/default.script" >> /bin/netstart
else # set up IP statically:
  # Set up the ethernet card:
  echo "Configuring eth0..."
  # create static IP netstart to fire up networking
  echo -e "ifconfig eth0 192.168.0.3 netmask 255.255.255.0 broadcast 192.168.0.255\n" >> /bin/netstart
  echo -e "route add default gw 192.168.0.1" >> /bin/netstart
fi
chmod a+x /bin/netstart

# startup networking
. /bin/netstart

echo -e "\n!!! log in as 'root', password 'xwoaf'. Type 'cd /;startx' to get started. !!!"
