#!/bin/sh
TMP=/var/log/setup/tmp
if [ ! -d $TMP ]; then
  mkdir -p $TMP
fi
while [ 0 ]; do
 dialog --title "INSTALL LINUX KERNEL" --menu "In order for your system to \
boot correctly, a kernel must be installed.  If you've made it this far \
using the installation bootdisk's kernel, you should probably install \
it as your system kernel (/vmlinuz).  If you're sure you know what you're \
doing, you can also install your choice of kernels from the Slackware CD, \
or a kernel from a floppy disk.  You can also skip this menu, using \
whatever kernel has been installed already (such as a generic kernel from \
the A series.)  Which option would you like?" 18 70 4 \
"bootdisk" "Use the kernel from the installation bootdisk" \
"cdrom" "Use a kernel from the Slackware CD" \
"floppy" "Install a zimage or bzimage file from a DOS floppy" \
"skip" "Skip this menu and use the default /vmlinuz" 2> $TMP/SeTreturn
 if [ $? = 1 -o $? = 255 ]; then
  break;
 fi
 if [ "`cat $TMP/SeTreturn`" = "bootdisk" ]; then
  dialog --title "INSERT INSTALLATION BOOTDISK" --msgbox "Please \
insert your installation bootdisk in /dev/fd0 (drive a:) and press ENTER \
to continue." 7 50
  mount /dev/fd0 /floppy -t minix
  if [ -r /floppy/vmlinuz ]; then
   dialog --title "COPYING" --infobox "Copying kernel from bootdisk to \
/vmlinuz on your new system..." 4 40
   cp /floppy/vmlinuz $T_PX/vmlinuz
   chmod 400 $T_PX/vmlinuz
   rdev -R $T_PX/vmlinuz 1
   rdev $T_PX/vmlinuz $ROOT_DEVICE
   rdev -r $T_PX/vmlinuz 0
   umount /floppy
   break;
  else
   umount /floppy
   dialog --title "ERROR: LINUX KERNEL NOT FOUND" --msgbox "Sorry, but a \
Linux kernel could not be installed since no file named /vmlinuz could be \
found on the floppy.  Did you insert the installation bootdisk?  Please \
hit ENTER to return to the kernel installation menu." 8 70
  fi 
 elif [ "`cat $TMP/SeTreturn`" = "cdrom" ]; then
  if [ ! -d /cdrom/kernels ]; then
   dialog --title "ERROR" --msgbox "Sorry, but the directory /cdrom/kernels \
was not found.  Are you installing from a Slackware CD?  If not, you'll \
have to install your kernel from a floppy, a bootdisk, or the A series." \
7 70
  else
   cat << EOF > $TMP/tempscript
dialog --title "CHOOSE LINUX KERNEL" --menu "Which of the following \\
directories would you like to install a Linux kernel from? NOTE: If \\
you have a SCSI controller, choose a kernel that supports that.  You \\
can support your CDROM drive and network card later with installable \\
kernel modules." \\
18 70 8 \\
EOF
   for dir in /cdrom/kernels/* ; do
    if [ -d $dir ]; then
     echo "\"$dir\" \"\" \\" >> $TMP/tempscript
    fi
   done
   echo "2> $TMP/SeTreturn" >> $TMP/tempscript
   . $TMP/tempscript
   if [ $? = 1 -o $? = 255 ]; then
    continue;
   fi
   dir=`cat $TMP/SeTreturn`
   dialog --title "COPYING" --infobox "Copying kernel from $dir to \
/vmlinuz on your new system..." 4 50
   if [ -r $dir/zImage ]; then
    cp $dir/zImage $T_PX/vmlinuz
   elif [ -r $dir/bzImage ]; then
    cp $dir/bzImage $T_PX/vmlinuz
   fi    
   chmod 400 $T_PX/vmlinuz
   rdev -R $T_PX/vmlinuz 1
   rdev $T_PX/vmlinuz $ROOT_DEVICE
   rdev -r $T_PX/vmlinuz 0
   break;
  fi
 elif [ "`cat $TMP/SeTreturn`" = "floppy" ]; then
  dialog --title "INSERT DISK" --msgbox "Now we will install a Linux \
kernel from floppy disk.  Please insert an MSDOS formatted floppy disk \
containing a kernel file \"ZIMAGE\" or \"BZIMAGE\" and press ENTER \
to continue." 8 60
  mount /dev/fd0 /floppy -t msdos
  if [ -r /floppy/zimage ]; then
   dialog --title "COPYING" --infobox "Copying kernel from floppy disk to \
/vmlinuz on your new system..." 4 40
   cp /floppy/zimage $T_PX/vmlinuz
   chmod 400 $T_PX/vmlinuz
   rdev -R $T_PX/vmlinuz 1
   rdev $T_PX/vmlinuz $ROOT_DEVICE
   rdev -r $T_PX/vmlinuz 0
   umount /floppy
   break;
  elif [ -r /floppy/bzimage ]; then
   dialog --title "COPYING" --infobox "Copying kernel from floppy disk to \
/vmlinuz on your new system..." 4 40
   cp /floppy/bzimage $T_PX/vmlinuz
   chmod 400 $T_PX/vmlinuz
   rdev -R $T_PX/vmlinuz 1
   rdev $T_PX/vmlinuz $ROOT_DEVICE
   rdev -r $T_PX/vmlinuz 0
   umount /floppy
   break;
  else
   umount /floppy
   dialog --title "ERROR: LINUX KERNEL NOT FOUND" --msgbox "Sorry, but a \
Linux kernel could not be installed since no file named /zimage or \
/bzimage could be found on the floppy.  Did you insert an MSDOS formatted \
floppy disk containing such a file?  Please hit ENTER to return to the kernel \
installation menu." 8 70
  fi
 elif [ "`cat $TMP/SeTreturn`" = "skip" ]; then
  if [ ! -r $T_PX/vmlinuz ]; then
   dialog --title "CONTINUE WITHOUT A KERNEL?" --yesno "WARNING: no Linux \
kernel is currently installed on your system, so generating a bootdisk and \
LILO installation are not going to work -- if you continue without an \
installed kernel you'll need to have some other means of booting your system. \
LOADLIN or the installation bootdisk will work.  If you're sure you want to \
continue without installing a kernel, select YES.  Otherwise, select NO \
and you'll be returned to the kernel installation menu." 12 65 
   if [ $? = 0 ]; then
    break;
   else
    continue;
   fi
  fi # no kernel
  break;
 fi # skip option
done
rm -f $TMP/SeTreturn
