#!/bin/sh
# remove /etc/mtab* so mount creates the /etc/mtab file
/bin/rm -f /etc/mtab* /etc/nologin

# Start udev.
echo "Starting udev..."

mount -w -n -t proc /proc /proc
mount -w -n -t sysfs /sys /sys
mount -w -n -o mode=0755 -t tmpfs /dev /dev
mkdir /dev/pts
mkdir /dev/shm
chmod 1777 /dev/shm

# ln -s /bin/true /dev/.hotplug.agent

/sbin/udevstart
/sbin/udevd --daemon

mknod /dev/unikey -m 0644 c 10 202
mknod /dev/ppp -m 0660 c 108 0
mknod /dev/loop0 -m 0660 b 7 0
chgrp disk /dev/loop0
mknod /dev/md0 -m 0660 b 9 0
chgrp disk /dev/md0
mknod /dev/fd0 -m 0660 b 2 0
chgrp floppy /dev/fd0
ln -sf /proc/self/fd /dev/fd
	
#/sbin/mount -f -v -o remount /
#/sbin/mount -f -v /proc
#/sbin/mount -f -v /sys
#/sbin/mount -f -v /dev
#
#echo "remount finished"
#sleep 10

# /bin/mount -av -t nonfs
ln -sf /proc/mounts /etc/mtab
ln -sf /tmp /var/log/setup/tmp

# Make detected partitions:
/sbin/makedevs.sh

# set system time from hwclock(/dev/rtc) as localtime
hwclock -l -s

echo "starting murasaki"
/etc/rc.d/rc.murasaki start

# module for USB
USBCHK=`lspci -v -i /usr/share/pci.ids | grep prog-if | grep USB `
if [ -n "$USBCHK" ] ;  then
    echo "USBCHK : $USBCHK "
    echo "loading usbcore "
    modprobe usbcore
    /bin/mount none /proc/bus/usb -t usbfs
    echo "mounting usbfs"

    /etc/rc.d/rc.murasaki start
    echo "starting murasaki"

    if `echo $USBCHK | grep 'UHCI' > /dev/null 2>&1 ` ; then
         echo "loading uhci-hcd"
         modprobe uhci-hcd
    fi

    if `echo $USBCHK | grep 'OHCI'  > /dev/null 2>&1 ` ; then
         echo "loading ohci-hcd"
         modprobe ohci-hcd
    fi

    if `echo $USBCHK | grep 'EHCI'> /dev/null 2>&1 ` ; then
         echo "loading ehci-hcd"
         modprobe ehci-hcd
    fi

    if grep 'kbd=usbkbd' /proc/cmdline >/dev/null 2>&1 ;then
       echo "loading usbkbd"
       modprobe usbkbd
    else
       echo "loading usbhid"
       modprobe usbhid
    fi
    echo "loading usb-storage"
    modprobe usb-storage

    # /sbin/lsmod
    # sleep 15
fi
#
# PCMCIA service
chk_pcmcia=`lspci -n | grep "Class 060[57]"`
if [ -n "$chk_pcmcia" ] ;  then
   echo "found PCMCIA bridge. loading pcmcia"
   /etc/rc.d/pcmcia start
   sleep 5
fi

# driver for Network card (Class 200)
vers=`uname -r`
v_id="0x0000"`/sbin/lspci -n | grep 0200 | awk '{print $4}' | cut -f 1 -d ':' | head -1`
p_id="0x0000"`/sbin/lspci -n | grep 0200 | awk '{print $4}' | cut -f 2 -d ':' | head -1`
mod=`grep $v_id /lib/modules/$vers/modules.pcimap | grep $p_id | head -1 | awk '{print $1}'`
echo "network module:$mod"
if [ -n "$mod" ]; then
    modprobe $mod
    echo "module $mod loaded"
    sleep 5
fi

if [ -x /etc/rc.d/rc.inet1 ]; then
	/bin/sh /etc/rc.d/rc.inet1
fi

/sbin/syslogd 2> /dev/null
sleep 1
/sbin/klogd -c 3 1> /dev/null

# /bin/setterm -blank 0
loadkeys /etc/custom/kbd/jp106.map
echo "jp106.map" > /tmp/keyset

/sbin/modprobe unikey
/sbin/modprobe encode-eucjp
/sbin/loadunimap /usr/share/fonts/direct.uni
/sbin/uniconctrl --eucjp tty1
/sbin/uniconctrl --eucjp tty2
/sbin/uniconctrl --eucjp tty3
/sbin/uniconctrl --eucjp tty4

#echo
#echo "<OPTION TO LOAD SUPPORT FOR NON-US KEYBOARD>"
#echo
#echo "If you are not using a US keyboard, you may now load a different"
#echo "keyboard map.  To select a different keyboard map, please enter 1"
#echo "now.  To continue using the US map, just hit enter."
#echo
#echo -n "Enter 1 to select a keyboard map: "
#read ONE
#if [ "$ONE" = "1" ]; then
#  /usr/lib/setup/SeTkeymap
#fi
#clear

echo > /etc/motd
echo "`/bin/uname -a | /bin/cut -d\  -f1,3`." >> /etc/motd
echo >> /etc/motd
echo "Plamo Linux のインストーラへようこそ" >> /etc/motd
echo  >> /etc/motd
echo "インストールを始めるには setup を実行してください" >> /etc/motd
echo >> /etc/motd

# Fake login:  (fooled ya! ;^)

cat /etc/issue
echo -n "plamo linux login: "
read BOGUS_LOGIN
cat /etc/motd
