#! /bin/sh

# $Progeny: S99unconfigured,v 1.22 2002/06/14 21:39:00 branden Exp $

export DEBIAN_FRONTEND
DEBIAN_FRONTEND=noninteractive
LOGFILE=/var/log/installer.log

stage2_files="/etc/rcS.d/S99unconfigured \
              /etc/configlets \
              /usr/share/configlets/user \
              /etc/xinitrc-pgi \
              /usr/bin/do-apt-cdrom \
              /etc/configlets-configure-x \
              /etc/configlets-debug"

exec 2>> $LOGFILE

echo "Starting Stage 2." >&2

# work around possible bug(s) in debootstrap process
dpkg --configure --pending 2> /dev/null || true

# ensure the network interface is up
module=$(discover --format="%m\n" ethernet)
modprobe $module
ifdown eth0 2> /dev/null
ifup eth0 2> /dev/null

# If we didn't configure the X server in stage 1, we must do it now.
if [ -e /etc/configlets-configure-x ]; then
    DEBIAN_FRONTEND=dialog
fi

# call the X server configuration scripts so that its config files are written
for PKG in xserver-common xserver-xfree86; do
    dpkg-reconfigure -phigh $PKG
done

PATH=$PATH:/usr/bin/X11
if ! xinit /etc/xinitrc-pgi -- vt7; then
    dialog --cr-wrap --backtitle "PGI Debian Installer" \
        --title "Error in Installer Environment" \
        --msgbox \
        "Unable to start system configuration process.  Please see /var/log/installer.log and /var/log/XFree86.0.log for more information.\n\nIf you are able to rectify the problem and would like to try again, simply reboot the system by typing \"reboot\" at the root shell prompt.  Otherwise, set the root password by typing \"passwd\" at the root shell prompt, and then delete the file \"etc/rcS.d/S99unconfigured\"." 13 70
    # can't launch a shell in runlevel "S"; no tty
    exit
fi

# if debugging, preserve the stage 2 files for later examination
if [ -f /etc/configlets-debug ]; then
    tar cfz /etc/installer_files.tar $stage2_files
fi

# get the stage 2 files out of the way
for file in $stage2_files; do
    rm -rf $file
done

unset DEBIAN_FRONTEND

# vim:ai:et:sts=4:sw=4:tw=80:
