#!/usr/bin/perl

# dialog requires a shell, unfortunately.  But I guess we
# wanted to have a shell anyway.

# Copyright (C) 1996 Red Hat Software, Inc.

require "dialog";
require "mount_rh";
require "probe_cd";
require "misc";
require "net";
require "nfs_mount";
require "xinst";
require "pcmcia";
require "fdisk";
require "swap";
require "mouse";
require "dispatch";
require "xinstall";
require "media";
require "bootdisk";
require "arch";
require "getopts";

# ***
$rh_testing = 0;
# ***

$express_install = 1;

$fsmount = "/mnt";

#$rh_mounted = 1;
#$rh_available = 1;
#$rh_mountpath = "/mnt/rhscd";

$* = 1;

# The boot disk is on    /bootdisk
# The 2nd rootdisk is on /ramdisk
# The CD instimage (if there is one) goes on /image

$ENV{'PATH'} = "/bin:/usr/bin:/usr/bin/X11:/usr/X11/bin:/sbin:/usr/sbin";
$ENV{'PATH'} .= ":/mnt/bin:/mnt/usr/bin:/mnt/sbin:/mnt/usr/sbin";

# Set $scr_lines here if we need to
# This is used by the perl interface to dialog
$scr_lines = 24;

@rest = &Getopts("pnck:o:s:");
$opt_p && ($mediamounted = 1);
$opt_k && ($kernelfile = $opt_k);
$opt_o && ($configfile = $opt_o);
$opt_c && ($kernel_available = 1);
$opt_n && ($no_net_config = 1);
$opt_s && ($swap_already_on = $opt_s);

$using_nfsroot = 0;
open(CMDLINE, "/proc/cmdline");
while (<CMDLINE>) {
    /nfsroot/ && ($nfsroot = 1);
}

close(CMDLINE);

if (! $rh_testing) {
    &rhs_msgbox ( "Red Hat Linux",
<<EOM
Welcome to Red Hat Linux for $instarch processors!
>
Red Hat Software has worked very hard to bring you the highest
quality Linux system and the easiest and most
flexible installation procedure.
>
If you managed to get this far with all your hardware
detected, the hard part is done!
>
This script will walk you through each step
of the installation.
>
PLEASE BE SURE YOU HAVE READ AND UNDERSTOOD THE INSTALLATION
GUIDE IN THE MANUAL BEFORE YOU PROCEED.  It is probably a good
idea to have the manual available for reference too.
>
Copyright (C) 1996 Red Hat Software, Inc.
EOM
	     , 74);

    if (&rhs_yesno("Color Screen",
<<EOM
>
Do you have a color display hooked up to this video card?
>
EOM
		   , 70)) {
	$incolor = 1;
    } else {
	$incolor = 0;
    }

    if ( $incolor) {
	unlink("/etc/.dialogrc");
    }
}

&mount_bootdisk();

#$express_install = &rhs_yesno("Red Hat Linux",
#<<EOM
#>
#The Express Install provides the simplest installation by
#taking you through each installation step in order.
#>
#Do you want to do an Express Install?
#>
#EOM
			      #, 70);
$express_install = 1;

$installsource = "";
$installtype = "";

if ($instarch eq "i386") {
    @installtypes = ("cdrom", "Red Hat CDROM", "nfs", "NFS server",
	"hard drive", "local hard drive", "ftp", "FTP server",
	"floppy", "floppy disks");
    $enablegraphical = 1;
} else {
    @installtypes = ("cdrom", "Red Hat CDROM", "nfs", "NFS server",
	"hard drive", "local hard drive" );
    $enablegraphical = 0;
}

while ($installtype eq "") {
    if ($mediamounted) {
	$installsource = "cdrom";    # close enough
	$installtype = "text";
    } elsif (&rhs_menu("Installation Type",
<<EOM
>
Red Hat supports a number of different sources for installation. You
may use NFS, a cdrom, ftp, floppy disks, a hard drive partition. 
>
Which do you prefer?
> 
EOM
		  , 70, (($#installtypes + 1) / 2), @installtypes,
		  )) {
	$installsource = $dialog_result;
    } else {
	$installsource = "";
    }

    if (($installsource eq "cdrom" || $installsource eq "nfs") 
	    && $enablegraphical) {
	# Find out if they want to do a X based install or a text mode one
	if (&rhs_menu("Installation Type",
<<EOM
>
Red Hat supports two types of CD (or NFS) based installation interfaces. One 
is a X based graphical interface which is more powerful
and much easier to use. However, some people have difficulty
getting X set up, so we provide a simpler text only installation
procedure as an alternative.
>
Which would you prefer?
> 
EOM
		  , 70, 2, 
		  "text", "Text based install",
		  "X", "Graphical Installation"
		  )) {
	    $installtype = $dialog_result;
	} else {
	    $installsource = "";
	}
    } else {
	$installtype = "text";
    }
}

&install_dispatcher;

if (! $rh_testing) {
    &umount_bootdisk();

    &rhs_msgbox ( "Installation Complete",
<<EOM
>
When you hit enter your computer will be rebooted.
>
Be sure to remove the boot floppy from your floppy drive!
>
EOM
		 , 70);
}

exit 0;
