#!/bin/sh
T_PX="`cat /tmp/SeTT_PX`"
ROOT_DEVICE="`cat /tmp/SeTrootdev`"
if [ ! -d $T_PX/bin -a ! -d $T_PX/etc ]; then # if there no Linux here, exit
 exit
fi
dialog --title "MAKE BOOT DISK?" --yesno "In order to boot Linux, you will \
have to use a boot disk, since the Linux boot loader is not compatible with \
the UMSDOS filesystem. Please insert the blank formatted disk that you have \
ready for this purpose, and answer YES. If you have forgotten to prepare one, \
answer NO, and you can make one later by running setup from your hard \
drive and choosing CONFIGURE; however, you'll have to use the bootkernel to \
start your system until then. Make boot disk?" \
13 60
if [ $? = 0 ]; then
 dialog --title "BOOT DISK CREATION" --yesno \
"Now put a formatted floppy in your boot drive. This will be made into your \
Linux boot disk. \
Any data on the target disk will be destroyed. \
"YES" creates the disk, "NO" aborts." 9 50 
 if [ $? = 0 ]; then
  dialog --title "CREATING DISK" --infobox "Creating boot disk from 'vmlinuz'..." 5 50
  KERNEL="/vmlinuz"
  # echo "  - writing kernel to disk: (dd if=$T_PX$KERNEL of=/dev/fd0)"
  dd if=$T_PX$KERNEL of=/dev/fd0 2> /dev/null
  # echo "Configuring boot disk..."
  # echo -n "  - boot device: "
  rdev /dev/fd0 $ROOT_DEVICE
  # echo "(rdev /dev/fd0 $ROOT_DEVICE)"
  # echo -n "  - video mode: "
  rdev -v /dev/fd0 -1
  # echo "(rdev -v /dev/fd0 -1)"
  # echo -n "  - mount root read-write for umsdos: "
  # echo "(rdev -R /dev/fd0 0)"
  rdev -R /dev/fd0 0
  sync
  # echo "Boot disk created."
 else
  dialog --title "SKIPPED BOOT DISK CREATION" --msgbox "Boot disk creation \
skipped. You'll have to use the bootkernel to start your system with the \
command: mount `cat /tmp/SeTrootdev`" 7 60
 fi
else
 dialog --title "SKIPPED BOOT DISK CREATION" --msgbox "Boot disk creation \
skipped. You'll have to use the bootkernel to start your system with the \
command: mount `cat /tmp/SeTrootdev`" 7 60
fi
dialog --title "MODEM CONFIGURATION" --yesno \
"\n\
This part of the configuration process will create a link in /dev\n\
from your callout device (cua0, cua1, cua2, cua3) to /dev/modem.\n\
You can change this link later if you put your modem on a different\n\
port.\n\n\
Would you like to set up your modem?\n" 12 73
if [ $? = 0 ]; then
 dialog --title "SELECT CALLOUT DEVICE" \
--menu "Please select the callout device which you would like to use \
for your modem:" 12 60 4 \
"cua0" "com1: under DOS" \
"cua1" "com2: under DOS" \
"cua2" "com3: under DOS" \
"cua3" "com4: under DOS" 2> /tmp/callout
 if [ $? = 1 ]; then
  rm -f /tmp/callout
 else
  MODEM_DEVICE="`cat /tmp/callout`"
  rm -f /tmp/callout
  (cd $T_PX/dev; ln -sf $MODEM_DEVICE modem)
 fi
fi


dialog --title "MOUSE CONFIGURATION" \
--yesno "\n\
This part of the configuration process will create a link in /dev\n\
from your mouse device to /dev/mouse. You can change this link\n\
later if the setting chosen does not work, or if you switch to a\n\
different type of mouse.\n\n\
Would you like to set up your mouse?" 12 70
if [ $? = 0 ]; then
 dialog --title "SELECT MOUSE TYPE" --menu "These mouse types are supported:" 14 60 6 \
"1" "Microsoft compatible serial mouse" \
"2" "C&T 82C710 or PS/2 style mouse (Auxiliary port)" \
"3" "Logitech Bus Mouse" \
"4" "ATI XL Bus Mouse" \
"5" "Microsoft Bus Mouse" \
"6" "Mouse Systems serial mouse" 2> /tmp/mtype
 if [ $? = 1 ]; then
  rm -f /tmp/mtype
  exit
 fi
 MOUSE_TYPE="`cat /tmp/mtype`"
 rm -f /tmp/mtype
 if [ "$MOUSE_TYPE" = "1" -o "$MOUSE_TYPE" = "6" ]; then
  dialog --title "SELECT SERIAL PORT" --menu "Your mouse requires a serial port. Which one would you \
like to use?" 13 60 4 \
"ttyS0" "com1: under DOS" \
"ttyS1" "com2: under DOS" \
"ttyS2" "com3: under DOS" \
"ttyS3" "com4: under DOS" 2> /tmp/mport
  if [ $? = 1 ]; then
   rm -f /tmp/mport
   exit
  fi
  MOUSE_DEVICE="`cat /tmp/mport`"
  rm -f /tmp/mport
  if [ "$MOUSE_TYPE" = "1" ]; then
   MTYPE="ms"
  else
   MTYPE="msc"
  fi
  (cd $T_PX/dev; ln -sf $MOUSE_DEVICE mouse)
 elif [ "$MOUSE_TYPE" = "2" ]; then
  (cd $T_PX/dev; ln -sf ps2aux mouse)
  MTYPE="ps2"
 elif [ "$MOUSE_TYPE" = "3" ]; then
  (cd $T_PX/dev; ln -sf bmouselogitec mouse)
  MTYPE="logi"
 elif [ "$MOUSE_TYPE" = "4" ]; then
  (cd $T_PX/dev; ln -sf bmouseatixl mouse)
  MTYPE="bm"
 elif [ "$MOUSE_TYPE" = "5" ]; then
  (cd $T_PX/dev; ln -sf bmousems mouse)
  MTYPE="bm"
 fi
fi
export MTYPE

( cd $T_PX ; chmod 755 ./ )
( cd $T_PX ; chmod 755 ./var )
if [ -d $T_PX/usr/src/linux ]; then
 chmod 755 $T_PX/usr/src/linux
fi
if [ ! -d $T_PX/proc ]; then
 mkdir $T_PX/proc
 chown root.root $T_PX/proc
fi
if [ -d $T_PX/usr/lib/gcc-lib/i486-linux ]; then # add the newest one
 ( cd $T_PX/lib; ln -sf ../usr/lib/gcc-lib/i486-linux/?.?.?/cpp cpp )
fi
if [ ! -d $T_PX/usr/spool/uucp ]; then
 mkdir -p $T_PX/usr/spool/uucp
fi
chown uucp.uucp $T_PX/usr/spool/uucp
chmod 1777 $T_PX/usr/spool/uucp
if [ ! -d $T_PX/usr/spool/uucppublic ]; then
 mkdir -p $T_PX/usr/spool/uucppublic
fi
chown uucp.uucp $T_PX/usr/spool/uucppublic
chmod 1777 $T_PX/usr/spool/uucppublic
chmod 1777 $T_PX/tmp
if [ ! -d $T_PX/usr/spool/mail ]; then
 mkdir -p $T_PX/usr/spool/mail
 chmod 755 $T_PX/usr/spool
 chown root.mail $T_PX/usr/spool/mail
 chmod 775 $T_PX/usr/spool/mail
fi 

# Post installation and setup scripts added by packages.
if [ -d $T_PX/usr/adm/setup ]; then
 for INSTALL_SCRIPTS in $T_PX/usr/adm/setup/setup.*
 do
  SCRIPT=`basename $INSTALL_SCRIPTS`
  # Here, we call each script in /usr/adm/setup. Two arguments are provided:
  # 1 -- the target prefix (normally /, but /mnt from the bootdisk)
  # 2 -- the name of the root device.
  if [ ! "$SCRIPT" = "setup.liloconfig" ]; then
   ( cd $T_PX ; sh usr/adm/setup/$SCRIPT $T_PX $ROOT_DEVICE )
  fi
  if echo $SCRIPT | fgrep onlyonce 1> /dev/null 2> /dev/null; then # only run after first install
   if [ ! -d $T_PX/usr/adm/setup/install ]; then
    mkdir $T_PX/usr/adm/setup/install
   fi
   mv $INSTALL_SCRIPTS $T_PX/usr/adm/setup/install
  fi
 done
fi

# Load keyboard map (if any) when booting
if [ -r /tmp/SeTkeymap ]; then
 MAPNAME="`cat /tmp/SeTkeymap`"
 if fgrep "sh /etc/rc.d/rc.keymap" $T_PX/etc/rc.d/rc.local 1> /dev/null 2> /dev/null ; then
  echo >> /dev/null # ?
 else
  echo "# Load custom keyboard map" >> $T_PX/etc/rc.d/rc.local
  echo "sh /etc/rc.d/rc.keymap" >> $T_PX/etc/rc.d/rc.local
 fi
 mkdir -p $T_PX/usr/lib/keytables
 cp /tmp/$MAPNAME $T_PX/usr/lib/keytables
 chmod 755 $T_PX/usr/lib/keytables
 echo "#!/bin/sh" > $T_PX/etc/rc.d/rc.keymap
 echo "echo 'Loading keyboard map \"$MAPNAME\"...'" >> $T_PX/etc/rc.d/rc.keymap
 echo "loadkeys /usr/lib/keytables/$MAPNAME" >> $T_PX/etc/rc.d/rc.keymap
 chmod 755 $T_PX/etc/rc.d/rc.keymap
fi
