#!/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 "CONFIGURE YOUR SYSTEM?" --yesno "Now it's time to configure \
your Linux system. If this is a new system, you must configure it now or it \
will not boot correctly. Otherwise, you can back out to the main menu if \
you're sure you want to skip this step. If you've installed a new kernel \
image, it's important to reconfigure your system so that you can install LILO \
(the Linux loader) or create a bootdisk using the new kernel. Do you want to \
move on to \
the CONFIGURE option?" 14 60 
if [ $? = 1 -o $? = 255 ]; then
 exit
fi
dialog --title "MAKE BOOT DISK?" --yesno "It is HIGHLY recommended that you \
make a standard boot disk \
for your Linux system at this time. Such a disk can be very handy if \
LILO is ever improperly installed. Since the boot disk will \
contain a kernel that is independent of LILO and the kernel on your \
hard drive, \
you'll still be able to use it to boot your system no matter what you do to \
LILO or your hard drive kernel. Would you like to make a standard \
boot disk?" \
14 60
if [ $? = 0 ]; then
 dialog --title "MOUNT ROOT PARTITION READONLY?" --yesno \
"If you use a native Linux filesystem such as ext2 or xiafs for your \
root partition, then \
you should select YES in order to allow for safe filesystem checking. \
If you use UMSDOS for your root partition, select NO or you'll run into \
problems when your system boots. \
Do you want this bootdisk to mount your root partition as read-only?" \
12 60
 if [ $? = 0 ]; then
  rdev -R /vmlinuz 1
 else
  rdev -R /vmlinuz 0
 fi
dialog --title "BOOT DISK CREATION" --yesno \
"\n\
Now put a formatted floppy in your boot drive. \n\
This will be made into your Linux boot disk. Use this to\n\
boot Linux until LILO has been configured to boot from\n\
the hard drive.\n\n\
Any data on the target disk will be destroyed.\n\n\
"YES" creates the disk, "NO" aborts.\n" 14 62
 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-only: "
  # echo "(rdev -R /dev/fd0 1)"
  # rdev -R /dev/fd0 1
  sync
  # echo "Boot disk created."
 else
  dialog --title "SKIPPED BOOT DISK CREATION" --msgbox \
"Boot disk creation skipped.  You'll have to use the bootkernel \n\
to start your system with this command at the LILO prompt: \n\
\n\
mount root=`cat /tmp/SeTrootdev` rw\n\
\n\
Or this command to use Loadlin to boot from MS-DOS:\n\
\n\
loadlin \\linux\\vmlinuz root=`cat /tmp/SeTrootdev` rw\n\
\n\
Or, you'll have to install LILO.  If you installed the LILO\n\
package the LILO install menu will be coming up soon.  NOTE:\n\
LILO will not work for booting a UMSDOS root partition.\n\
\n" 17 67
 fi
else
  dialog --title "SKIPPED BOOT DISK CREATION" --msgbox \
"Boot disk creation skipped.  You'll have to use the bootkernel \n\
to start your system with this command at the LILO prompt: \n\
\n\
mount root=`cat /tmp/SeTrootdev` rw\n\
\n\
Or this command to use Loadlin to boot from MS-DOS:\n\
\n\
loadlin \\linux\\vmlinuz root=`cat /tmp/SeTrootdev` rw\n\
\n\
Or, you'll have to install LILO.  If you installed the LILO\n\
package the LILO install menu will be coming up soon.  NOTE:\n\
LILO will not work for booting a UMSDOS root partition.\n\
\n" 17 67
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:" 13 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
 fi
 if [ -f /tmp/mtype ]; then
  MOUSE_TYPE="`cat /tmp/mtype`"
 else
  unset MOUSE_TYPE
 fi
 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?" 12 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
  fi
  if [ -f /tmp/mport ]; then
   MOUSE_DEVICE="`cat /tmp/mport`"
  else
   unset MOUSE_DEVICE
  fi
  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 psaux mouse)
  MTYPE="ps2"
 elif [ "$MOUSE_TYPE" = "3" ]; then
  (cd $T_PX/dev; ln -sf logibm mouse)
  MTYPE="logi"
 elif [ "$MOUSE_TYPE" = "4" ]; then
  (cd $T_PX/dev; ln -sf atibm mouse)
  MTYPE="bm"
 elif [ "$MOUSE_TYPE" = "5" ]; then
  (cd $T_PX/dev; ln -sf inportbm 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
# This really should be done by the gcc.tgz package, which will know it's
# own version number.
#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/var/spool/uucp ]; then
 mkdir -p $T_PX/var/spool/uucp
fi
chown uucp.uucp $T_PX/var/spool/uucp
chmod 1777 $T_PX/var/spool/uucp
if [ ! -d $T_PX/var/spool/uucppublic ]; then
 mkdir -p $T_PX/var/spool/uucppublic
fi
chown uucp.uucp $T_PX/var/spool/uucppublic
chmod 1777 $T_PX/var/spool/uucppublic
chmod 1777 $T_PX/tmp
if [ ! -d $T_PX/var/spool/mail ]; then
 mkdir -p $T_PX/var/spool/mail
 chmod 755 $T_PX/var/spool
 chown root.mail $T_PX/var/spool/mail
 chmod 775 $T_PX/var/spool/mail
fi 

# Post installation and setup scripts added by packages.
if [ -d $T_PX/var/adm/setup ]; then
 for INSTALL_SCRIPTS in $T_PX/var/adm/setup/setup.*
 do
  SCRIPT=`basename $INSTALL_SCRIPTS`
  # Here, we call each script in /var/adm/setup. Two arguments are provided:
  # 1 -- the target prefix (normally /, but /mnt from the bootdisk)
  # 2 -- the name of the root device.
  ( cd $T_PX ; sh var/adm/setup/$SCRIPT $T_PX $ROOT_DEVICE )
  if echo $SCRIPT | fgrep onlyonce 1> /dev/null 2> /dev/null; then # only run after first install
   if [ ! -d $T_PX/var/adm/setup/install ]; then
    mkdir $T_PX/var/adm/setup/install
   fi
   mv $INSTALL_SCRIPTS $T_PX/var/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/kbd/keytables
 if [ ! -r $T_PX/usr/lib/kbd/keytables/$MAPNAME ]; then
  cp /tmp/$MAPNAME $T_PX/usr/lib/kbd/keytables
  chmod 755 $T_PX/usr/lib/kbd/keytables
 fi
 echo "#!/bin/sh" > $T_PX/etc/rc.d/rc.keymap
 echo "echo 'Loading keyboard map \"$MAPNAME\"...'" >> $T_PX/etc/rc.d/rc.keymap
 echo "/usr/bin/loadkeys /usr/lib/kbd/keytables/$MAPNAME" >> $T_PX/etc/rc.d/rc.keymap
 chmod 755 $T_PX/etc/rc.d/rc.keymap
fi
