#!/bin/ash

PATH=/bin:/usr/bin:/sbin:/usr/sbin:.
hostname pld

hd () {
  from=/dev/ide/host$1/bus$2/target$3/lun0
  ln -sf $from/disc /dev/hd$4
  for f in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ; do
    ln -sf $from/part$f /dev/hd$4$f
  done
}

sd () {
  from=/dev/scsi/host$1/bus$2/target$3/lun0
  ln -sf $from/disc /dev/sd$4
  for f in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ; do
    ln -sf $from/part$f /dev/sd$4$f
  done
}

links_in_dev () {
  echo -n "Making compatibilty links in /dev... "
  for f in 0 1 2 3 4 5 6 7 8 9 10 11 12 ; do
    ln -s /dev/vc/$f /dev/tty$f
  done
  ln -s /dev/floppy/0 /dev/fd0
  hd 0 0 0 a
  hd 0 0 1 b
  hd 0 1 0 c
  hd 0 1 1 d
  hd 1 0 0 e
  hd 1 0 1 f
  hd 1 1 0 g
  hd 1 1 1 h
  sd 0 0 0 a
  sd 0 0 1 b
  sd 0 0 2 c
  sd 0 0 3 d
  sd 0 0 4 e
  sd 0 0 5 f
  sd 0 0 6 g
  sd 0 0 7 h
  echo done
}

if uname -r | grep -q '^2.4' ; then
  umount /oldroot/dev
  umount /oldroot
  freeramdisk /dev/rd/0
  links_in_dev
  if test -f /lib/modules/`uname -r`/ext2.o ; then
    insmod /lib/modules/`uname -r`/ext2.o
    rm -f /lib/modules/`uname -r`/ext2.o
  fi
else
  mount proc /proc -t proc
  mount devpts /dev/pts -t devpts
fi

if grep -q " console=.*ttyS[0-9]" /proc/cmdline; then
    serial_console=1
    TERM=vt100
fi

if [ "$TERM" = "" ] ; then
    TERM=linux
fi

export TERM

syslogd
klogd

# load them always because user might want to save config after
# all modules are deleted
insmod floppy
insmod fat
insmod vfat

if grep -q ' config=' /proc/cmdline ; then
  mount -t vfat /dev/fd0 /mnt
  f=`sed -e 's/.* config=//' /proc/cmdline | sed -e 's/^\([^ ]*\).*/\1/'`
  if test -r /mnt/$f ; then
    cd /
    # support both .tar and .tar.gz
    zcat /mnt/$f | tar xf - || tar xf /mnt/$f
  else
    echo "Cannot find /mnt/$f..."
  fi
  umount /mnt
fi

export LANG
if test -f /etc/profile; then 
  . /etc/profile
fi


# place for user defined hooks
if test -f /etc/pre-install ; then
  . /etc/pre-install
fi

if grep -q " batch" /proc/cmdline ; then
  echo "Starting installer..."
  installer
else # !batch
  if test -z "$LANG" ; then
    if test -x /bin/dml -a -z "$serial_console"; then
      # +- Choose... -+ was ugly :)
      eval `dml <<EOF
<meta title="Language">
<br>
<menu id=LANG res=1>
<item id=en>English
<item id=pl>Polski
</menu>
EOF
`
    else #!dml || serial_console
      echo "Please select 2-letter language code."
      echo "Supported languages:"
      echo
      echo "en - English"
      echo "pl - Polish"
      echo
      echo -n "Your choice: "
      read LANG
    fi
    echo "export LANG=$LANG" >> /etc/profile
  fi


  if test -z "$serial_console"; then 
    echo ; echo ; echo ; echo
    # don't clear, as there can be some intresting messages above
    case "$LANG" in 
    pl)
	zcat /usr/share/fonts/l2.psfu.gz | loadfont
	;;
    esac
  fi

  test -f /etc/motd.$LANG && ln -sf motd.$LANG /etc/motd
  test -f /etc/motd.bye.$LANG && ln -sf motd.bye.$LANG /etc/motd.bye
  test -f /doc/install-HOWTO.$LANG && ln -sf install-HOWTO.$LANG /doc/install-HOWTO

fi # !batch

# don't wanna garbage on console
dmesg -n 1

# vim:ft=sh
