#!/bin/sh
TMP=/var/log/setup/tmp
if [ ! -d $TMP ]; then
  mkdir -p $TMP
fi
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

# Check for disk full error:
. /usr/lib/setup/SeTfull

# These next lines are intended to clean up any permissions
# problems that could be caused by a bad package.  We don't
# intend to make any bad packages here, but it never hurts
# to be safe. :^)
( 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
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 1777 $T_PX/var/spool/mail
fi 

# Load keyboard map (if any) when booting
if [ -r $TMP/SeTkeymap ]; then
  MAPNAME="`cat $TMP/SeTkeymap`"
  echo "#!/bin/sh" > $T_PX/etc/rc.d/rc.keymap
  echo "# Load the keyboard map.  More maps are in /usr/share/kbd/keymaps." \
  >> $T_PX/etc/rc.d/rc.keymap
  echo "if [ -x /usr/bin/loadkeys ]; then" >> $T_PX/etc/rc.d/rc.keymap
  echo " /usr/bin/loadkeys $MAPNAME" >> $T_PX/etc/rc.d/rc.keymap
  echo "fi" >> $T_PX/etc/rc.d/rc.keymap
  chmod 755 $T_PX/etc/rc.d/rc.keymap
fi

# Only ask if we want to skip configuring if we suspect the user should
# skip the step:
if [ -r $T_PX/etc/fstab ]; then
  dialog --title "CONFIGURE THE SYSTEM" --yesno "Now we can configure your \
Linux system.  If this is a new installation, you MUST configure it now or it \
will not boot correctly.  However, if you are just adding software to an \
existing system, you can back out to the main menu and skip this step.  \
However (important exception) 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.  You want to CONFIGURE \
your system, right?" 0 0
  if [ ! $? = 0 ]; then
    exit
  fi
else
  dialog --title "DONE INSTALLING PACKAGES" --infobox  \
"Preparing to configure your new Linux system..." 3 54
  sleep 4
fi

# Post installation and setup scripts added by packages.
if [ -d $T_PX/var/log/setup ]; then
  for INSTALL_SCRIPTS in $T_PX/var/log/setup/setup.* ; do
    SCRIPT=`basename $INSTALL_SCRIPTS`
    # Here, we call each script in /var/log/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/log/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/log/setup/install ]; then
        mkdir $T_PX/var/log/setup/install
      fi
      mv $INSTALL_SCRIPTS $T_PX/var/log/setup/install
    fi
  done
fi

# Set root password:
/usr/lib/setup/SeTpasswd

