#!/usr/bin/perl -w
# xinstaller - Started by Brian Bresen <bbresen@linuxppc.org>
# Copyrite Brian Bresen - released under the GPL
# 
# modified for Vine Linux
# by MATSUBAYASHI 'Shaolin' Kohji <shaolin@rhythmaning.org>

#TITLE: xinstaller ( was xli.pl )
#REQUIRES: Gtk

# Changelog:
#
# 4.0-0vl6 / Sun Jun 25 2000
#   - now xinstaller can automatically update packages already installed
# 4.0-0vl5 / Sun Jun 04 2000
#   - create_net() and report_add() now handles
#     domainsearch entry in /etc/pump.conf 
# 4.0-0vl4 / Mon May 29 2000
#   - modified for iMacDV with XFree86-4.0-mga-r128-v2
#   - set authconfig --useshadow --enablemd5 in create_passwd()
# 4.0-0vl3 / Fri May 19 2000
#   - check disk space before starting installation
#   - create_net() modified to take over already-set value
#   - modified report_add() around writing /etc/hosts
#   - some more translation for Japanese
# 4.0-0vl2 / Sun May 07 2000
#   - "Miscellaneous" now in Japanese
# 4.0-0vl1 / Sat Apr 29 2000
#   - given a new version number
#   - radical modification (too much)
#
# 3.7.8-0vl9 / Wed Apr 26 2000
#   - default kernel (manually installed) synced up to 2.2.15pre14-ben1
#   - mount proc to $out_dir/proc when post_install
# 3.7.8-0vl8 / Sun Apr 16 2000
#   - modified argument for update_progress() in call_rpm()
# 3.7.8-0vl7 / Sat Apr 15 2000
#   - finally xinstaller is prepared in Japanese!
# 3.7.8-0vl6 / Wed Apr 12 2000
#   - fixed finish_new_install() around copying LinuxPPC's System.map
# 3.7.8-0vl5 / Tue Apr 11 2000
#   - Oops fixed typo around fixing /etc/inittab
# 3.7.8-0vl1 - 3.7.8-0vl4
#   - ... sorry I don't remember what part I've modified ...

use Gtk;
use Gtk::Atoms;
use Gtk::Gdk;

use strict 'vars';

init Gtk;

my $VERSION = "4.0-0vl6";	#The version number  
my $DATE = "Jun 04 2000";	#

my $in_method = "local";	#The way we will install
my $ftp_url;			#url to RedHat dir on a ftp site
my %map;			#The Install Map
my %mapupgrade;			#The Upgrade Map
my %rpmlist;			#The RPM List
my %rpmlisttree;		#A hash of the rpm list treeitems
my %rpmlisttreereverse;		#A hash of the rpm list treeitems
my @rpmlistcurrent;		#A List of the currently installed rpms
my %sets;			#A hash of the treeitems
my %hdlistinfo;			#The hdlistinfo
my($is_upgrade) = 0;		#0 for install, 1 for upgrade
#my($net_set) = 0;		#State if we need net setup for NFS or FTP
my($net_set) = 1;
my $in_dir = "/tmp/install/";	#the dir with the install files in it
my $out_dir = "/mnt/install/";	#the dir we will install to
my %mount_fstab;	#list of drives selected to install
my @list_bases = ("");	#list of package sets to install
my $menu_window;	#menu to choose steps to do
my $entry_window;	#extra entry windows i will use
my $package_list;	#list of packages to install
my $packages_window;	#choose each rpm individually
my %drive_hash;		#my drives for hash, or um my...
my %net_devs;		#my network devices
my %my_widgets;		#network setup widgets
my $root_passwd;	#hmmmm
my $rpm_label;		#what package is installing
my $prep_install = 0;	#flag for PReP install
my $prepboot;			# PReP boot partition
my %mke2_mount; 	#widgets values
my $wget = "wget -c -t 4 ";	#The wget command - add -q for quiet mode
my $root_dev;

my $bootproto = "none";

my $testing = 0;	#for future testing purposes
#
# %drive_hash -
#	%dev - (e.g. %hda %sda)
#		%p_no - (e.g. %1 %2 %16)
#			( $type $name $length $base $size )

##Step window global vars
my $splash_window;	# Splash window, as the variable name says
my $instruction_window;	# Instruction window

my $main_window;	# Take a guess
my $method_window;	#Install/upgrade from where
my $update_window;	#update the installer itself
my $drives_window;	#Choose which drive
my $pdisk_window;	#partition disk ala druid
my $pswap_window;	#choose swap
my $mount_window;	#choose root partition and other
my $comps_window;	#choose packages to install
my $passwd_window;	#choose a root passwd
my $net_window;		#add a network device
my $bootx_window;	#get info on using bootx to boot linux
my $cngrat_window;	#get a pat on the back you made it
my $language_window;
my $ButtonPressed;	#Set to the name of the last button clicked
my $CurrentWindow;	# The window currently being drawn in
my %words;		# hash of words for internationalization
my $CurrentRoot;	# What device to use in BootX
my $ProgressBar;	# The progress bar to update
my $ProgressEntry;	# The progress entrybox to update
my $MasterCounter;	# A global counter for number of packages to install
my $MasterCounterDone;	# A global counter for number of packages installed
my $CheckDisk = FALSE;	# A flag for checking diskspace
my $ChangeLanguage = FALSE;	#A flag for if you are changing the language
my $CurrentFont;
my $MethodButton;
my $PackagesButton;
my $PasswordButton;
my $LinuxConfButton;

sub new_pixmap {
 my ($filename, $window, $background) = @_;
 my ($pixmap, $mask) = create_from_xpm Gtk::Gdk::Pixmap($window, $background, $filename);
 return new Gtk::Pixmap($pixmap, $mask);
}

sub destroy_window {
        my($widget, $windowref, $w2) = @_;
        $$windowref = undef;
        $w2 = undef if defined $w2;
        0;
}

sub my_system {
	print "RUNNING @_ \n";
	system "@_";
}

sub create_standard_entry {
	my($hbox) = create_standard_hbox( 10 , $_[2]);

	my($label) = new Gtk::Label $_[0];
	$label->set_alignment(0.0,0.5);
	$hbox->pack_start($label, 0, 1, 0);
	$label->show;

	my($entry) = new Gtk::Entry;
	$entry->set_usize(0, 20);
	$entry->set_text("$_[1]");
	$hbox->pack_start($entry, 1, 1, 0);
	$entry->show;

	return $entry;
}

sub my_separator {
	my($box1) = @_;

	my($separator) = new Gtk::HSeparator;
	$box1->pack_start($separator, 0, 1, 0);
	$separator->show;

	my($box2) = create_standard_hbox( 10 , $box1, 0, 1, 0 );
	return $box2;
}

sub create_standard_window {
	if ( defined $_[0] ) { $_[0]->destroy; return; }
	$_[0] = new Gtk::Window "toplevel";
	$_[0]->set_uposition($_[1],$_[2]);
	if ( ! ( $_[3] == -1 )) {
		# print "Setting window size to $_[3], $_[4]\n";
		# $_[0]->set_usize($_[3],$_[4]);
		$_[0]->set_default_size( $_[3], $_[4] );
	}
	$_[0]->signal_connect("destroy", \&destroy_window, \$_[0]);
	$_[0]->signal_connect("delete_event", \&destroy_window, \$_[0]);
	$_[0]->set_title( "$_[5]" );
	$_[0]->border_width(0);
	$_[0]->grab_focus;
	$_[0]->show;
	$CurrentWindow = $_[0];
}

sub create_standard_vbox {
	my( $item );
	$item = new Gtk::VBox(0,0);
	$item->border_width( $_[0] );
	if( defined $_[1] ) {
		if( defined $_[2] ) {
			$_[1]->pack_start($item, $_[2], $_[3], $_[4] );
		} else {
#			$_[1]->add($item);
		}
	} else {
		$CurrentWindow->add($item);
	}
	$item->show;
	return $item;
}

sub create_standard_hbox {
	my( $item );
	$item = new Gtk::HBox(0,10);
	$item->border_width( $_[0] );
	if( ! defined $_[1] ) {
		$CurrentWindow->add($item);
	} elsif ( ! defined $_[2] ) {
		$_[1]->add($item);
	} else {
		$_[1]->pack_start($item, $_[2], $_[3], $_[4] );
	}
	$item->show;
	return $item;
}

sub create_standard_label {
	my($label) = new Gtk::Label $_[0];
#	$label->set_alignment(0.0,0.5);
	if( ! defined $_[2] ) {
		$_[1]->add($label);
	} else {
		$_[1]->pack_start($label, $_[2], $_[3], $_[4] );
	}
	$label->show;
	return $label;
}

sub create_standard_button {
	my( $button ) = new Gtk::Button( $_[0] );
#	$_[0]->can_default(1);
	if( ! defined $_[1] ) {
		$button->show;
		return $button;
	}
	if( ! defined $_[2] ) {
		$_[1]->add($button);
	} else {
		$_[1]->pack_start($button, $_[2], $_[3], $_[4] );
	}
	if( defined $_[5] ) {
		$button->signal_connect('clicked', $_[5] );
	}
	$button->show;
	return $button;
}

sub create_method {
	my($button, $vbox, $hbox, $chk_upg, @buttons, $button_name ) ;
	my($entry, @tmp, $label, $sitename, $text, $device);
	my($string, $destdir, @dir_check, $myURL, %sitenameLookup);

	if (defined $method_window) { destroy $method_window; return; }

	if (! -e ("$out_dir/tmp")) { system ("mkdir -p $out_dir/tmp"); }
	if (! -e ("/tmp/install/tmp")) { system ("mkdir -p /tmp/install/tmp"); }

	create_standard_window( $method_window, 260, 20, 350, 350, $words{Choose_Method} );
	$vbox = create_standard_vbox( 1 );
	$hbox = create_standard_hbox( 1, $vbox, 1, 0, 1 );

	$button = create_standard_button( $words{CDROM}, $hbox, 1, 0, 1 );
	$button->signal_connect('clicked', sub {
		if ( -e "/tmp/install/software/base/") {
			destroy $method_window;
			choose_packages();
			return;
		}
		foreach $device ( "/dev/cdrom", "/dev/scd0", "/dev/scd1", "/dev/hda", "/dev/hdb", "/dev/hdc", "/dev/hdd") {
			system( "umount /tmp/install" );
			system( "mount $device /tmp/install" );
			if ( -e "/tmp/install/software/") {
				$in_dir = "/tmp/install/"; 
				if( ! -e "/dev/cdrom" ) {
					system( "ln -sf $device /dev/cdrom" );
				}
				destroy $method_window;
				choose_packages();
				return;
			}
		}
		$text = "/tmp/install " . $words{No_Install_Files};
		create_text_window( 150, 20, 375, 200, 
			$words{CDROM_Mount_Failed}, $words{Close}, $text,
			"stop");
	});

	$button = create_standard_button( $words{LocalPartition}, $hbox, 1, 0, 1 );
	$button->signal_connect('clicked', sub {
		$in_dir = "/tmp/install/"; 
		if ( ! ( -e "$in_dir/software/base/")) {
			$text = "/tmp/install " . $words{No_Install_Files};
			create_text_window( 150, 20, 375, 200, $words{LocalMountFailed},
				$words{Close}, $text, "stop");
		} else {
			destroy $method_window;
			choose_packages();
		}
	});

	$button = create_standard_button( "NFS", $hbox, 1, 0, 1 );
	$button->signal_connect('clicked', sub {
		$in_dir = "/tmp/install/"; 
		$sitename = $myURL->get_text;
		print "i should be running  mount sitename:destdir /tmp/install\n";
		if ( ! ( -e "$in_dir/software/base/")) {
			if( $sitename eq "" ) {
				create_text_window( 150, 20, 375, 200, $words{NFS_Mount_Failed},
					$words{Close}, $words{NFS_instructions}, "stop" );
			} else {
				create_text_window( 150, 20, 375, 200, $words{NFS_Mount_Failed}, 
					$words{Close}, $words{NFS_badmount_message}, "stop" );
			}
		} else {
			destroy $method_window;
			choose_packages();
		}
	});

	create_standard_label( $words{URL_help} , $vbox );

	$myURL = create_standard_entry( $words{Site} , "", $vbox );

# Adds known sites.
	create_standard_label( $words{Known_sites} , $vbox );

	my( $list , $scrolled_win, $list_item, $i, $name );
	$scrolled_win = new Gtk::ScrolledWindow(undef, undef);
	$scrolled_win->set_policy(-automatic, -automatic);
	$vbox->pack_start($scrolled_win, 1, 1, 0);
	$scrolled_win->show;

        $list = new Gtk::List;
        $scrolled_win->add_with_viewport($list);
        $list->show;

	chdir("$in_dir/");
	unlink( "$in_dir/SITES" );
	system( "$wget http://www.vinelinux.org/SITES" );
	if( -e "$in_dir/SITES" ) {
		print "Yahoo! I retrived this ok from the server!\n";

		open( SITES , "$in_dir/SITES" );
		print "$in_dir/SITES\n";
		while( <SITES> ) {
			chop( $_ );
			if( $_ eq "" ) { next; }
			@tmp = split( " " , $_ );
			if( ! defined $tmp[1] ) { next; }
			$list_item = new Gtk::ListItem( $_ );
			$sitenameLookup{$list_item} = $tmp[2];
			$list->add($list_item);
			$list_item->show;
		}
		close( SITES );
	} 

	$button = create_standard_button( $words{Try_URL}, $hbox, 1, 1, 0 );
	$button->signal_connect('clicked', sub {
		$in_dir = "/tmp/install/"; 
		$in_method = "http"; 
		$sitename = $myURL->get_text;
		if( defined $list->selection() ) {
			@tmp = split( " " , $list->selection() );
			my( $selectedURL ) = pop( @tmp );
			$ftp_url = $sitenameLookup{ $selectedURL };
			print "Trying selected: $ftp_url\n";
		} else {
			print "Trying $sitename\n";
			$ftp_url = $sitename;
		}

		chdir("$in_dir");
		print "in_dir = $in_dir\n";
		if ( -e ("$in_dir/hdlistinfo")) {
			system "rm -f /$in_dir/hdlistinfo";
			system "rmdir /$in_dir/tmp/";
		}

		print "Getting $ftp_url/RedHat/base/hdlistinfo\n";
		system ("$wget $ftp_url/RedHat/base/hdlistinfo");
		if ( ! ( -e "$in_dir/hdlistinfo")) {
			print "Failed getting $ftp_url/RedHat/base/hdlistinfo\n";
			create_text_window( 150, 20, 275, 200, $words{Connection_Failed},
				$words{Close}, "$sitename \n $words{Bad_Site}", "stop" );
		} else { 
			system ("$wget $ftp_url/install/maps/install.master");
			system ("$wget $ftp_url/install/maps/order.master");
			destroy $method_window;
			choose_packages();
		}
	});

	$hbox = create_standard_hbox( 1, $vbox, 1, 0, 1 );
#	$hbox = my_separator($vbox);
	$button = create_standard_button( $words{Setup_Network}, $hbox, 1, 1, 0 );
	$button->signal_connect('clicked', sub {
		destroy $method_window;
		create_net();
	});

	create_standard_button( $words{Cancel} , $hbox, 1, 1, 0, sub {
		$method_window->destroy; 
	});
}

#get_dinfo gets the info for the drives from fdisk -l
sub get_finfo {
	my(@tmp_input);
	my($pnum,$type,$name,$length,$base,$size);
	my($dev_name) = "";

	# ok here we take pdisk output and create known drive hash
	# sounds fun, eh?
	# after that we create visual to modify drives allow it to change
	# then update the drive tables needed
	
	#system pdisk here
	open( PART , "/proc/partitions" );
	unlink "/tmp/pdisk.out";

	#system pdisk here -- this hangs if audio or hybrid cd is in drive
	#print "Running  * fdisk -l\n";
	#system "fdisk -l > /tmp/pdisk.out 2> /tmp/pdisk.err";
	while( <PART> ) {
		chop( $_ );
		if( $_ eq "" ) { next; }
		@tmp_input = split( " " , $_ );
		if( $dev_name eq substr( $tmp_input[3] , 0 , 3 ) ) { 
			print "running fdisk on /dev/$dev_name\n"; 
			system( "fdisk -l /dev/$dev_name >> /tmp/pdisk.out" );
		}
		$dev_name = $tmp_input[3];
	}
	close( PART );

	open(DISKF,'/tmp/pdisk.out');
	
	while ( <DISKF> ) {
		chop();
		#if Disk line - store dev entry var
		if (/^Disk/) {
			@tmp_input = split(/\:/);
			$_ = $tmp_input[0];
			@tmp_input = split(/\//);
			$dev_name = $tmp_input[2];

			# print "Found drive :/dev/$dev_name\n";
			next;
		}
					# if /dev/ store info for dev part
					# but not if  #: @
#	   	next if (/[0-9]: @/);	# ^----
		$name = '';
		$type = '';
		$size = '';
		if (/^\/dev\//) {
			#make fdisk line useful
			#other stuff too
			@tmp_input = split(/\s+/);

			$pnum = chop($tmp_input[0]);
			if ($tmp_input[1] =~ /\*/) {
				splice(@tmp_input,1,1);
			}

			$length = $tmp_input[3];
			$base = $tmp_input[1];
			$type = join(' ',@tmp_input[5..$#tmp_input]);

			$drive_hash{$dev_name}{$pnum}[0] = $type; 
			$drive_hash{$dev_name}{$pnum}[1] = $name; 
			$drive_hash{$dev_name}{$pnum}[2] = $length; 
			$drive_hash{$dev_name}{$pnum}[3] = $base; 
			$drive_hash{$dev_name}{$pnum}[4] = $size; 
		}
	}
	close (DISKF);
}

#get_dinfo gets the info for the drives from pdisk -l
sub get_pinfo {
	my(@tmp_input);
	my($pnum,$type,$name,$length,$base,$size);
	my($dev_name) = "";

	# ok here we take pdisk output and create known drive hash
	# sounds fun, eh?
	# after that we create visual to modify drives allow it to change
	# then update the drive tables needed
	
	#system pdisk here
	open( PART , "/proc/partitions" );
	unlink "/tmp/pdisk.out";

	#system pdisk here -- this hangs if audio or hybrid cd is in drive
	#print "Running  * pdisk -l\n";
	#system "pdisk -l > /tmp/pdisk.out 2> /tmp/pdisk.err";
	while( <PART> ) {
		chop( $_ );
		if( $_ eq "" ) { next; }
		@tmp_input = split( " " , $_ );
		if( $dev_name eq substr( $tmp_input[3] , 0 , 3 ) ) { 
			print "running pdisk on /dev/$dev_name\n"; 
			system( "pdisk -l /dev/$dev_name >> /tmp/pdisk.out" );
		}
		$dev_name = $tmp_input[3];
	}
	close( PART );

	open(DISKF,'/tmp/pdisk.out');
	while ( <DISKF> ) {
		chop();
		#if partition map line store dev entry var
		if (/^Partition map/) {	#
			@tmp_input = split(/\'/);
			$_ = $tmp_input[1];
			@tmp_input = split(/\//);
			$dev_name = $tmp_input[2];

			#print "Found drive :/dev/$dev_name\n";
			next;
		}
					# if #: store info for dev part
					# but not if  #: @
	   	next if (/[0-9]: @/);	# ^----
		$name = '';
		$type = '';
		$size = '';
		if (/[0-9]:/) {
			#make pdisk line useful
			#other stuff too

			@tmp_input = split(/:/);
			$pnum = $tmp_input[0];
			while ($pnum =~ /\s+/) { $pnum=substr($pnum,1) }
			#$pnum = join ("p",$tmp_input[0]);
			#print "/dev/$dev_name :part # $tmp_input[0] - ";

			$_ = $tmp_input[1];
			@tmp_input = split(/\s+/);
                        while ( ! ($tmp_input[0]) ) { 
				shift(@tmp_input);
			}

			if ($tmp_input[$#tmp_input] =~ /\)/) {
				if (!($tmp_input[$#tmp_input] =~ /[GM]/)) {
				    $tmp_input[$#tmp_input-1] .= pop(@tmp_input);
				}
				if (!($tmp_input[$#tmp_input] =~ /\(/)) {
				    $tmp_input[$#tmp_input-1] .= pop(@tmp_input);
				}
				$size = pop(@tmp_input);
			}
			$base = pop(@tmp_input);
			pop(@tmp_input);
			$length = pop(@tmp_input);
		
			if ( $tmp_input[0] =~ /\*/ ) {
				my(@tmpa) = split(/\*/, shift(@tmp_input) );
				$type = shift(@tmpa);
                        	$name .= shift(@tmpa) . " ";
			} else {
				$type = shift(@tmp_input);
			}
                	while ( scalar(@tmp_input) )	{
				$name .= shift(@tmp_input) . " ";
                	}
			chop $name;
			# print "$dev_name $pnum\n";
			$drive_hash{$dev_name}{$pnum}[0] = $type; 
			$drive_hash{$dev_name}{$pnum}[1] = $name; 
			$drive_hash{$dev_name}{$pnum}[2] = $length; 
			$drive_hash{$dev_name}{$pnum}[3] = $base; 
			$drive_hash{$dev_name}{$pnum}[4] = $size; 
		} else {
			if (/Number of Blocks/) {
				@tmp_input = split(/=/);
				$_ = $tmp_input[2];
				@tmp_input = split(/ /);
#				print "/dev/$dev_name:  $tmp_input[0] blocks $tmp_input[1]\n";
			}
		}
	}
	close (DISKF);
}

sub mknod {
	my( $i , $j, $path ) = @_;
	my( $majorid );
	if( -e "$path/$i$j" ) { return; }
	print "Making missing dev entry $i$j\n";
	if( $i eq "hda" ) {
		system "mknod $path/$i$j b 3 $j";
	}
	if( $i eq "hdb" ) {
		$majorid = $j + 64;
		system "mknod $path/$i$majorid b 3 $majorid";
	}
	if( $i eq "hdc" ) {
		system "mknod $path/$i$j b 22 $j";
	}
	if( $i eq "hdb" ) {
		$majorid = $j + 64;
		system "mknod $path/$i$majorid b 22 $majorid";
	}
}

sub create_mount {
	my @usedrive  = @_;
	my (%mountwlist, %mke2wlist, @titles, @title_sizes, $button, $cancel);
	my ($box1, $box2, $cb_mke2, $scw, $table, $text1, $entry, $crow);
	my(@swap_list, $numparts, $i, $j, @device_order);
	my($use_pdisk) = 1;

	if( defined $mount_window ) { $mount_window->destroy; return; }
	#check if prep or chrp install
	if ($prep_install) {
		$use_pdisk = 0;
	}

	if ($use_pdisk) {
		&get_pinfo();
	} else {
		&get_finfo();
	}

    if ($usedrive[0] =~ /^Gtk/ ) {
	@usedrive = ();
	foreach $i (sort keys(%drive_hash)) { push(@usedrive,$i) }
    }

    #set $numparts equal to number of partitoions shown plus title row
    $numparts = 1;
	my $unix_drive;
    foreach $i (sort(@usedrive)) {
		foreach $j (keys(%{$drive_hash{$i}})) {
#			if ( ! defined $drive_hash{$i}{$j}[0] ) { next; }
			if ( $drive_hash{$i}{$j}[0] eq "Linux_PPC" ) {
				$unix_drive = "TRUE";
			}
			if ( $drive_hash{$i}{$j}[0] eq "Apple_UNIX_SVR2" ) {
				$unix_drive = "TRUE";
			}
   			next if ($drive_hash{$i}{$j}[0] eq 'Apple_partition_map');
			next if ($drive_hash{$i}{$j}[0] eq 'Apple_Driver43');
			next if ($drive_hash{$i}{$j}[0] eq 'Apple_Driver_ATA');
			next if ($drive_hash{$i}{$j}[0] eq 'Apple_FWDriver');
			next if ($drive_hash{$i}{$j}[0] eq 'Apple_Patches');
			next if ( substr( $drive_hash{$i}{$j}[0] , 0, 12 ) eq 'Apple_Driver');
			next if ($drive_hash{$i}{$j}[0] eq 'FWB');
			$numparts++;	
		}
    }

	if( ! defined $unix_drive ) {
		&create_text_window( 260, 20, 400, 250, 
		$words{ No_Linux_Partitions }, $words{Close}, $words{ No_Linux_Partitions_Text }, "caution" ) ;
		return;
	}

    if ($prep_install) {
		@titles = ( $words{Partition}, $words{Type}, $words{Length}, $words{Mount_Point});
    } else {
		@titles = ( $words{Partition}, $words{Name}, $words{Size}, $words{Mount_Point});
    }
	@title_sizes = ( 85, 115, 65, 105 );

	create_standard_window( $mount_window, 90, 25, 540, 250, $words{MountWindowName} );

	#create main vert box for titles row followed by partition rows
	$box1 = create_standard_vbox( 0 );
	$box2 = create_standard_vbox( 10, $box1, 1, 1, 0 );
		
	$scw = new Gtk::ScrolledWindow(undef,undef);
	$scw->border_width(10);
	$scw->set_policy(-automatic, -automatic);
	$box2->pack_start($scw, 1, 1, 0);
	$scw->show;

	$table = new Gtk::Table($numparts, 4, 0);
	$table->set_row_spacings(1);
	$table->set_col_spacings(1);
	$table->set_row_spacing(0,8);
	$scw->add_with_viewport($table);
	$table->show;

	# setup title row
	for $i ( 0 .. (scalar(@titles) - 1) ) {
		$text1 = new Gtk::Text;
		$text1->set_usize( $title_sizes[$i], 20);
		$text1->can_focus(0);
		$text1->insert(undef,$text1->style->black,undef, $titles[$i]);
		$table->attach_defaults($text1, $i, $i+1, 0, 1);
		$text1->show;
	}

	$crow = 1; 				#current row is 2
	#load up the info into the window
	foreach $i (sort(@usedrive)) {
	    for $j (keys(%{$drive_hash{$i}})) {
		mknod $i, $j, "/dev";
		next if ($drive_hash{$i}{$j}[0] eq 'Apple_partition_map');
		next if ($drive_hash{$i}{$j}[0] eq 'Apple_Patches');
		next if ($drive_hash{$i}{$j}[0] eq 'Apple_FWDriver');
		next if ( substr( $drive_hash{$i}{$j}[0] , 0, 12 ) eq 'Apple_Driver');
		next if ($drive_hash{$i}{$j}[0] eq 'FWB');

		#new stuff
		#("/dev/$i$j",${$dhash{$i}{$j}}[1],${$dhash{$i}{$j}}[4],entry box,mke2fs checkbutton);
		#fill the data 1 2 3
		$text1 = new Gtk::Text;
		$text1->set_usize(15,22);
		$text1->can_focus(0);
		$text1->insert(undef,$text1->style->black,undef, "/dev/$i$j");
		$table->attach_defaults($text1, 0, 1, $crow, $crow+1);
		$text1->show;

		$text1 = new Gtk::Text;
		$text1->set_usize(15,22);
		$text1->can_focus(0);
		if ($prep_install) {
			$text1->insert(undef,$text1->style->black,undef, ${drive_hash{$i}{$j}}[0] );
		} else {
			$text1->insert(undef,$text1->style->black,undef, ${drive_hash{$i}{$j}}[1] );
		}
		$table->attach_defaults($text1, 1, 2, $crow, $crow+1);
		$text1->show;

		$text1 = new Gtk::Text;
		$text1->set_usize(15,22);
		$text1->can_focus(0);
		if ($prep_install) {
			$text1->insert(undef,$text1->style->black,undef, ${drive_hash{$i}{$j}}[2] );
		} else {
			$text1->insert(undef,$text1->style->black,undef, ${drive_hash{$i}{$j}}[4] );
		}
		$table->attach_defaults($text1, 2, 3, $crow, $crow+1);
		$text1->show;

		$entry = new Gtk::Entry;
		$entry->set_usize(15,25);
		$entry->set_text("");

		#This code will check to see what drives are currently mounted
		# <insert that code here, flight home now, must leave! <jwc>

		my( @mountinfo );
		open( MOUNTS, "/proc/mounts" );
		while( <MOUNTS> ) {
			chop( $_ );
			if( $_ eq "" ) { next; }
			@mountinfo = split( " " , $_ );
			if( substr( $mountinfo[1], 0, length( $out_dir ) ) eq $out_dir ) {
				my( $tmp, $junk, $partition ) = split( /\// , $mountinfo[0] );
				my( $path ) = substr( $mountinfo[1] , length( $out_dir ) );
				$path = "/" . $path;
				$path =~ s/\/\/+/\//g;
				$mount_fstab{ "$partition" } = $path;
			}
		}

		print "drive hash = $drive_hash{$i}{$j}[1] \n";
		if ($drive_hash{$i}{$j}[1] =~ /[Ss]wap/ ) {
			$entry->set_text("swap");
			print "swap guessed from partition name = $i$j\n";
		} elsif ($drive_hash{$i}{$j}[0] =~ /[Ss]wap/ ) {
			$entry->set_text("swap");
			print "swap guessed from partition name = $i$j\n";
		} elsif ($drive_hash{$i}{$j}[0] =~ /PPC PReP Boot/) {
			$entry->set_text("PReP Boot");
			print "PReP Boot partition guessed = $i$j\n";
		} else {
			if( exists $mount_fstab{ "$i$j" } ) {
				$entry->set_text( $mount_fstab{ "$i$j" } );
			}
		}
		
		$mountwlist{"$i$j"} = $entry;

		$entry->show;
		$table->attach_defaults($entry, 3, 4, $crow, $crow+1);

		undef $cb_mke2;
		# Add a checkbox for mke2fs and mkswap
		if (($drive_hash{$i}{$j}[1] =~ /[Ss]wap/ ) || ($drive_hash{$i}{$j}[0] =~ /[Ss]wap/ )) {
			$cb_mke2 = new Gtk::CheckButton 'mkswap';
			$cb_mke2->set_state(1);
		} elsif ($drive_hash{$i}{$j}[0] =~ /PPC PReP Boot/ ) {
			$cb_mke2 = new Gtk::CheckButton 'mkboot';
			$cb_mke2->set_state(1);
		} elsif ( $drive_hash{$i}{$j}[0] eq 'Apple_HFS' ) {
			if ($drive_hash{$i}{$j}[1] eq "/boot" ) {
				$cb_mke2 = new Gtk::CheckButton 'hformat';
			} else {
				undef $cb_mke2;
			}
		} else {
			if ($drive_hash{$i}{$j}[0] ne 'Apple_Free' ) {
				$cb_mke2 = new Gtk::CheckButton $words{Format};
			}
		}
		if ( defined $cb_mke2 ) {
			$table->attach_defaults($cb_mke2, 4, 5, $crow, $crow+1);
			$cb_mke2->show;
			$mke2wlist{"$i$j"} = $cb_mke2;
		}
		# in here so next will skip it, happy 
		$crow++;
	    } #end new stuff happy more
	}

	#check if swap is already mounted
	open (SWAP,"/proc/swaps");
	my($swap_input);
	while ($swap_input = <SWAP>) {		#if not eof then swap partition that is on
			next if	($swap_input =~ /^File/); 		#Filename just ignore
			my(@swap_array) = split(' ',$swap_input);
			my($dev) = $swap_array[0];
			@swap_array = split("\/",$dev);
			$dev = pop(@swap_array);
			$mountwlist{$dev}->set_text("swap");
			print "swap partition already mounted = $dev\n";
			push(@swap_list, $dev);
		}
	close(SWAP);
	foreach $i (@swap_list) {
		$mke2wlist{$i}->hide;
		$mke2wlist{$i}->set_state(0);
		$mke2wlist{$i}->show;
		while (Gtk::Gdk->events_pending() ) { Gtk->main_iteration(); }
	}
	$box2 = my_separator($box1);

	create_standard_button( $words{Help} , $box2, 1, 1, 0, sub {
			create_text_window(260,20,500,350, $words{Recommend},
				$words{Close}, $words{Recommend_text}, "note");
	});

	create_standard_button( $words{FormatMount} , $box2, 1, 1, 0, sub {
		foreach $i (keys(%mountwlist)) {
			my($wref) = $mountwlist{$i}->get_text;
			next if ($wref eq "");
			$mount_fstab{$i} = $wref; #widgets value

			#Check for / partition
			if ($mount_fstab{$i} eq "\/") {
					$root_dev = $i;
			}
			my($cb_wref);
			if (( defined $mke2wlist{$i} ) && ($mke2wlist{$i}->state eq "active")) { 
				$cb_wref = 1;
			}
			$mke2_mount{$i} = $cb_wref; #widgets value
		}
				
		#if root_dev parse it to two vars
		if (defined $root_dev) {
			my (@tmp_root) = split(//,$root_dev);
			$i = shift(@tmp_root);		#device name
			$i .= shift(@tmp_root);		
			$i .= shift(@tmp_root);		
			$j = join ('',@tmp_root);	#partition number
		}

		#if no root partition give warning
		if (!defined $root_dev) {
			create_text_window(260,20,450,350, $words{no_root_title},
				$words{Close}, $words{no_root_warning}, "stop");
			#do not destroy mount window since info is wrong
			#this might screw everything up
			#$mount_window->destroy;
		} else {
			if ($drive_hash{$i}{$j}[2] < 512000) {
				#root_dev is not big enough for base install
				create_text_window(20,20,400,350, $words{too_small_title},
					$words{Close}, $words{too_small_warning}, "caution");
			}
			#mount drives here
			mount_drives();

			$mount_window->destroy;
			$PackagesButton->set_sensitive(1);
			choose_packages();
		}
	});
	if( (-e "/live/perldisk/perldisk") || (-e "/usr/bin/perldisk" ) ){
	create_standard_button( $words{Partition_Drives} , $box2, 1, 1, 0, sub {
		print "Starting perldisk\n";
		system "perldisk &";
		if ( defined $mount_window ) { $mount_window->destroy; return; }
	});
	}

	create_standard_button( $words{Cancel} , $box2, 1, 1, 0, sub {
		$mount_window->destroy; 
	});

}

sub reset_packages {
	my( $set, $key, $count );
	my @list_items = @_;
	# print "Should do some kind of reset to the original selections\n";
	$count = 0;
	foreach $set ( @list_items ) {
		my @stuff = keys %sets;
		if( ! defined $sets{$set} ) { next; }
#		if( $count < 5 ) { 
		if( $set =~ /default/ ) { 
			$sets{$set}->select;
		} else {
			$sets{$set}->deselect;
		}
		++$count;
	}
	foreach $key ( @rpmlistcurrent ) { 
		if( exists $rpmlisttreereverse{$key} ) {
			$rpmlisttreereverse{$key}->select;
		}
	}
}

sub choose_packages {
	my( $box1, $box2, $scrolled_win, $list, $leaf, $base_dir, $branch );
	my( $set, $rpm, $tmp, @stuff, $size, $label );
	my( $count ) = 0;

	undef( %sets );
	undef( %rpmlisttree );

	%map = ();
	%mapupgrade = ();

	# Here we will read the base dir files

	my(@list_items) = scan_install_master();	# returns list of catergories
	print "items: @list_items\n";
	get_package_info();			# look at package info

	if( -e "$out_dir/var/lib/rpm" ) {
		my($temp) = `rpm -qa --queryformat=\"%{NAME} \" --root=$out_dir 2>/dev/null`;
		@rpmlistcurrent = split( " " , $temp );
		print "Checking for installed stuff in $out_dir\n";
		$temp = `rpm -qa --queryformat=\"%{NAME} %{BUILDTIME}\" --root=$out_dir 2>/dev/null`;
		print "There are $#rpmlistcurrent packages already installed.\n";
	}

	create_standard_window( $packages_window, 260, 20, 400, 400, $words{Choose_Packages} ) || return;
	$box1 = create_standard_vbox( 0 );

	$box2 = create_standard_hbox( 5 , $box1 , 0, 1, 0);
	$label = create_standard_label( "$words{Package1}" , $box2, 1, 1, 0 );

	$box2 = create_standard_hbox( 5 , $box1 , 0, 1, 0);
	$label = create_standard_label( "$words{Package2}" , $box2, 1, 1, 0 );

	$box2 = create_standard_hbox( 10 , $box1, 1, 1, 0 );

	$scrolled_win = new Gtk::ScrolledWindow(undef, undef);
	$scrolled_win->set_policy(-automatic, -automatic);
	$box2->pack_start($scrolled_win, 1, 1, 0);
	$scrolled_win->show;

        $list = new Gtk::Tree();
	$list->set_selection_mode(-multiple);
	$scrolled_win->add_with_viewport($list);

	$box2 = my_separator($box1);
	create_standard_button( $words{Install} , $box2, 1, 1, 0, \&install_packages );

	create_standard_button( $words{Close} , $box2, 1, 1, 0, sub {
		$packages_window->destroy; 
	});

	create_standard_button( $words{Reset} , $box2, 1, 1, 0, [ \&reset_packages , @list_items ]);

	$box2 = create_standard_hbox( 4 , $box1, 0, 1, 0 );
	$ProgressBar = new Gtk::ProgressBar;
	$ProgressBar->set_usize(350,25);
	$box2->pack_start($ProgressBar,1,1,0);
	$ProgressBar->show;

	$box2 = create_standard_hbox( 4 , $box1, 0, 1, 0 );
	$ProgressEntry = new Gtk::Entry;
	$ProgressEntry->set_usize(0, 20);
	$ProgressEntry->set_text("");
	$box2->pack_start($ProgressEntry, 1, 1, 0);
	$ProgressEntry->show;

	foreach $set ( @list_items ) {
		$sets{$set} = new Gtk::TreeItem( $set );
		$list->add($sets{$set});
#		$sets{$set}->signal_connect('collapse', \&collapsed );
		$sets{$set}->signal_connect('expand', \&expanded );
		$sets{$set}->signal_connect('select', \&selected );
		$sets{$set}->signal_connect('deselect', \&deselected );
#		$sets{$set}->collapse;
		$sets{$set}->show;

		$branch = new Gtk::Tree();
#		$branch->set_selection_mode(-multiple);
		$sets{$set}->set_subtree($branch);
		$branch->show;

#		print "Starting $set\n";
		foreach $rpm ( sort keys( %rpmlist ) ) {
			if( $set ne $rpmlist{$rpm} ) { next; }
			if( exists $hdlistinfo{$rpm} ) {
				@stuff = split ( "\t" , $hdlistinfo{$rpm} );
				$tmp = "$rpm $stuff[4] $stuff[5]";
				$size = $stuff[4] / ( 1024 * 1024 );
				$tmp = sprintf "$rpm     %.2f MB  $stuff[5]", $size;
			} else {
#			print "Not adding $rpm to tree:not in hdlistinfo\n";
				next;	#assume for now files must have hdlistinfo entries
			}
#			print "Adding $rpm to tree\n";
#			if( exists $rpmlisttreereverse{$rpm} ) {
#				print "Already added $rpm to tree\n";
#				next;
#			}
			$leaf = new Gtk::TreeItem( $tmp );
			$branch->add($leaf);
			$leaf->collapse;
			$leaf->hide;
			$rpmlisttree{$leaf} = $rpm;
			$rpmlisttreereverse{$rpm} = $leaf;
			$leaf->signal_connect('select', \&selected );
			$leaf->signal_connect('deselect', \&deselected );
#			$leaf->show;
#			print "$rpm, $rpmlist{$rpm}\n";
		}
		# if ($count < 5) {
		# 	$sets{$set}->select;
		# }
		++$count;
	}
	close( MAP );

	$list->show;
	reset_packages ( @list_items );
}

sub expanded {
	my ($key, $key2);
	foreach $key ( keys( %sets ) ) {
		if( $_[0] eq $sets{$key} ) {
			print "expanded $key\n";
			foreach $key2 ( keys( %rpmlisttree ) ) {
#				print "$rpmlisttree{$key2} ";
				if( $key eq $rpmlist{ $rpmlisttree{$key2} } ) {
#					print "$key2 , $rpmlisttree{$key2} ";
					$rpmlisttreereverse{$rpmlisttree{$key2}}->show;
				}
			}
#			print "\n";
		}
	}
}

sub selected {
	my ($key, $key2, @selected);
	foreach $key ( keys( %sets ) ) {
		if( $_[0] eq $sets{$key} ) {
			$CheckDisk = FALSE;
			foreach $key2 ( keys( %rpmlisttree ) ) {
				if( $key eq $rpmlist{ $rpmlisttree{$key2} } ) {
					$rpmlisttreereverse{$rpmlisttree{$key2}}->select;
				}
			}
			$CheckDisk = TRUE;
			check_diskspace();
			return();
		}
	}
	$map{ $rpmlisttree{$_[0]} } = $_[0];
	if( $CheckDisk eq TRUE ) { check_diskspace(); }
}

sub deselected {
	my ($key, $key2);
	foreach $key ( keys( %sets ) ) {
		if( $_[0] eq $sets{$key} ) {
#			print "deselected $key\n";
			$CheckDisk = FALSE;
			foreach $key2 ( keys( %rpmlisttree ) ) {
				if( $key eq $rpmlist{ $rpmlisttree{$key2} } ) {
					$rpmlisttreereverse{$rpmlisttree{$key2}}->deselect;
				}
			}
			$CheckDisk = TRUE;
			check_diskspace();
			return();
		}
	}
	delete $map{ $rpmlisttree{$_[0]} };
	if( $CheckDisk eq TRUE ) { check_diskspace(); }
}

sub check_diskspace {
	my( $key, $size, @stuff, $string, $number );

	foreach $key ( @rpmlistcurrent ) { delete $map{$key}; }

	$number = keys( %map );
	$size = 0;
	foreach $key (keys( %map )) {
		@stuff = split( "\t" , $hdlistinfo{ "$key" } );
		$size += $stuff[4];
	}
	$size = $size / ( 1024 * 1024 );
	$string = sprintf "$number packages: for %.2f MBytes", $size;
#	print "$string\n";
	$ProgressEntry->set_text( $string );
}

sub update_progress {
	my $value;
	++$MasterCounterDone;
	if( $MasterCounterDone > $MasterCounter ) {  #jcarr hardcoded this
		$MasterCounterDone = $MasterCounter;
	}
	if( $MasterCounter eq 0 ) {
		$value = 0;
	} else {
		$value = $MasterCounterDone / $MasterCounter;
	}
	$ProgressBar->hide;
	$ProgressBar->set_format_string( "%p %%  ($MasterCounterDone of $MasterCounter)" );
	$ProgressBar->set_show_text( 1 );
	$ProgressBar->update( $value );
	$ProgressBar->show;
	print "Installing $_[0] ( $MasterCounterDone of $MasterCounter )\n";
	$ProgressEntry->hide;
	$ProgressEntry->set_text( "$words{Installing} $_[0] ( $MasterCounterDone of $MasterCounter )" );
	$ProgressEntry->show;

#	print "About to update\n";
	while (Gtk::Gdk->events_pending() ) {
		Gtk->main_iteration();
	}
#	print "Done with update\n";
}

sub find_file {
	#Just a simple routine that looks around for a filename
	my ( $path, $newfilename);
	my $file = $_[0];
	#print "Trying to find file $file\n";

	foreach $path ( "$in_dir", "$in_dir/software/RedHat/base", "$in_dir/software/RedHat/RPMS", "$in_dir/RedHat/RPMS", "$out_dir/tmp/", "$in_dir/software/RedHat/maps" , "$in_dir/RPMS/" , "$in_dir/software" , "$in_dir/maps/" , "/home/new" , "/mnt/cdrom/maps", "/tmp/install/software" ) {
		# print "\tTesting $path/$file\n";

		if ( -e "$path/$file" ) {
			print "FOUND $path/$file!\n";
			return "$path/$file";
		}
		$newfilename = substr( $file, 0, 31 );
		if ( -e "$path/$newfilename" ) {
			print "FOUND $path/$newfilename!\n";
			return "$path/$newfilename";
		}
		$newfilename = substr( $file, 0, 27 ) . ".rpm";
		if ( -e "$path/$newfilename" ) {
			print "FOUND $path/$newfilename!\n";
			return "$path/$newfilename";
		}
		$newfilename = substr( $file, 0, 23 ) . ".ppc.rpm";
		if ( -e "$path/$newfilename" ) {
			print "FOUND $path/$newfilename!\n";
			return "$path/$newfilename";
		}
		$newfilename = substr( $file, 0, 20 ) . ".noarch.rpm";
		if ( -e "$path/$newfilename" ) {
			print "FOUND $path/$newfilename!\n";
			return "$path/$newfilename";
		}

	}
	print "Can not find $file\n";
	return $file;
}

sub call_rpm {
	my(@rpmargs,@stuff,$temp,$file);
	my(@order) = @_;
	my($force) = " --nodeps --force ";
	my( $filename, $date, $version, $revision, $size, $description, $path);
	my $returned;
	my $counter;

	$counter = 1;
	foreach $temp ( @order ) {
		($file,@rpmargs) = split( " " , $temp );
		if( ! exists $map{ "$file" } ) { next; }
		if (! exists $hdlistinfo{ "$file" }) { 
			print "$file appears to be missing.\n"; 
			++$MasterCounterDone;
			next;
		}

		@stuff = split( "\t" , $hdlistinfo{ "$file" } );
		$filename = shift( @stuff );
#		shift( @stuff );
		$date = shift( @stuff );
		$version = shift( @stuff );
		$revision = shift( @stuff );
		$size = shift( @stuff );
		$description = shift( @stuff );
#		print "Order Install $map{ $file } $filename @rpmargs\n";
		update_progress( "$filename ..." );

		if (($in_method eq "ftp") || ($in_method eq "http")) {
#			print "Running  * $wget $ftp_url/RedHat/RPMS/$filename\n";
			system "$wget $ftp_url/RedHat/RPMS/$filename -P $out_dir/tmp/";
		}
		$path = find_file $filename;
		print "Running  * rpm -ivh --root=$out_dir $path @rpmargs\n";
		$returned = system ( "rpm -ivh --root=$out_dir $path @rpmargs $force" );  
		if( $returned ne 0 ) {
			# print "RPM FAILED: RETURNED $returned\n";
			if( $returned eq 11 ) {
				system "xmessage -center script failed for $filename\\\nNon-fatal error";
			} else {
				system "xmessage -center $filename failed to install. \\\nrpm exited with $returned.";
			}
			# will return 2 if you control-c it
		}
		if( $counter > 5 ) {
			sleep 2;
			print "Running sync\n";
			system "sync";
			$counter = 1;
		}
		++$counter;
		delete $map{ "$file" };
	}
	undef @rpmargs;

	system( "sync" );
	update_progress( $words{Done} );
	$ProgressBar->update( 1 );
	print " I counted $MasterCounterDone RPMS that i tried to install.\n";
	$PasswordButton->set_sensitive(1);
	$LinuxConfButton->set_sensitive(1);
}

sub call_rpmupgrade {
	my(@rpmargs,@stuff,$temp,$file);
	my(@order) = @_;
	my($force) = " --nodeps --force ";
	my( $filename, $date, $version, $revision, $size, $description, $path);
	my $returned;
	my $counter;

	$counter = 1;
	foreach $temp ( @order ) {
		($file,@rpmargs) = split( " " , $temp );
		if( ! exists $mapupgrade{ "$file" } ) { next; }
		if (! exists $hdlistinfo{ "$file" }) { 
			print "$file appears to be missing.\n"; 
			++$MasterCounterDone;
			next;
		}

		@stuff = split( "\t" , $hdlistinfo{ "$file" } );
		$filename = shift( @stuff );
#		shift( @stuff );
		$date = shift( @stuff );
		$version = shift( @stuff );
		$revision = shift( @stuff );
		$size = shift( @stuff );
		$description = shift( @stuff );
#		print "Order Install $mapupgrade{ $file } $filename @rpmargs\n";
		update_progress( "$filename ..." );

		if (($in_method eq "ftp") || ($in_method eq "http")) {
#			print "Running  * $wget $ftp_url/RedHat/RPMS/$filename\n";
			system "$wget $ftp_url/RedHat/RPMS/$filename -P $out_dir/tmp/";
		}
		$path = find_file $filename;
		print "Running  * rpm -Uvh --root=$out_dir $path @rpmargs\n";
		$returned = system ( "rpm -Uvh --root=$out_dir $path @rpmargs $force" );  
		if( $returned ne 0 ) {
			# print "RPM FAILED: RETURNED $returned\n";
			if( $returned eq 11 ) {
				system "xmessage -center script failed for $filename\\\nNon-fatal error";
			} else {
				system "xmessage -center $filename failed to install. \\\nrpm exited with $returned.";
			}
			# will return 2 if you control-c it
		}
		if( $counter > 5 ) {
			sleep 2;
			print "Running sync\n";
			system "sync";
			$counter = 1;
		}
		++$counter;
		delete $mapupgrade{ "$file" };
	}
	undef @rpmargs;

	system( "sync" );
	update_progress( $words{Done} );
	$ProgressBar->update( 1 );
	print " I counted $MasterCounterDone RPMS that i tried to install.\n";
	$PasswordButton->set_sensitive(1);
	$LinuxConfButton->set_sensitive(1);
}

sub install_packages {
	my($button,$vbox,$pbar,$i,$set,$file,$rpm,$key,$temp);
	my(@stuff,@rpmargs,$base_dir);
	my($size, $diskspace, @tmp_input);
	my($version, $release);
	
	#take out installed packages from install map
	if ( -e "$out_dir/var/lib/rpm/packages.rpm" ) {
	system( "xmessage -center -buttons \"\" Checking for rpms to update ... Please wait for a while &" );
	foreach $key ( @rpmlistcurrent ) {
		if ( exists $hdlistinfo{$key} ) {
			my($tmpver) = `rpm -q --queryformat=\"%{VERSION}\" --root=$out_dir $key 2>/dev/null`;
			my($tmprel) = `rpm -q --queryformat=\"%{RELEASE}\" --root=$out_dir $key 2>/dev/null`;
			@stuff = split( "\t" , $hdlistinfo{ "$key" } );
			shift( @stuff );
			shift( @stuff );
			$version = shift( @stuff );
			$release = shift( @stuff );
			if ( $tmpver ne $version || $tmprel ne $release ) {
				print "$key must be upgraded\n";
				$mapupgrade{$key} = $map{$key};
			}
		}
		delete $map{$key};
	}
	system( "killall -9 xmessage >/dev/null 2>&1" );
	}

	#check if there's enough disk space
	foreach $key (keys( %map )) {
		@stuff = split( "\t" , $hdlistinfo{ "$key" } );
		$size += $stuff[4];
	}
	$size = $size / 1024;
	system( "LANG=C LANGUAGE=C df -k | grep -v var | grep -v home > /tmp/df.out" );
	$diskspace = 0;
	open (DISKF, '/tmp/df.out');
	while (<DISKF>) {
		if (/\/mnt\/install/) {
			@tmp_input = split( " ", $_ );
			$diskspace += $tmp_input[3];
		}
	}
	$diskspace = $diskspace * 0.95;
	print "Disk space (except /var and /home) is $diskspace KB\n";
	print "Disk space needed for install is $size KB\n";
	if ( $size > $diskspace ) {
		create_text_window( 260, 20, 420, 350, $words{Disk_Shortage},
		$words{Close}, $words{Size_Exceeds}, "caution" );
		return;
	}

	#how many
	my($rpmcount) = 0;
	foreach $rpm (keys %map) { $rpmcount++; }
	$MasterCounter = $rpmcount;
	$MasterCounterDone = 0;

	print "Here we set up the filesystem: \n";
	print "Running  * mkdir -p $out_dir/var/lib/rpm $out_dir/etc $out_dir/usr\n";
	system( "mkdir -p $out_dir/var/lib/rpm $out_dir/etc $out_dir/usr" );

	#create X11 link in usr
	print "Linking X11 to X11R6 in usr\n";
	system( "ln -sf /usr/X11R6 $out_dir/usr/X11" );

	# get install order
	my(@order) = get_install_order();	

	if (( $in_method eq "ftp" ) || ($in_method eq "http")) {
		chdir "$in_dir";
	} else {
		chdir "$in_dir/software/RedHat/RPMS";
	}

	# Install the packages here and in the right order
	call_rpm( @order , keys( %map ) );

	# reset counter for Upgrade process
	$rpmcount = 0;
	foreach $rpm (keys %mapupgrade) { $rpmcount++; }
	$MasterCounter = $rpmcount;
	$MasterCounterDone = 0;

	# Update the packages here and in the right order
	call_rpmupgrade( @order , keys( %mapupgrade ) );

	# If new install: run the new install fixes....
	if( ( -e "/live/lib/" ) && ( ! -e "$out_dir/etc/fstab" ) ) {
		print "This seems like a new install.\n";
		finish_new_install();
		$packages_window->destroy; 
		create_passwd();
	} else {
		print "This doesn't seem to be a new install, \n";
		print "so I'm not going to run the fixes.\n";
		$ProgressEntry->set_text( "The new packages are Installed." );
		$ProgressEntry->hide;
		$ProgressEntry->show;
	}
}

sub finish_new_install {
	print "Writing out fstab to $out_dir/etc/\n";
	make_fstab();

	# small hack for $out_dir/etc/mtab
	system "touch $out_dir/etc/mtab";

	print "Setting default timezone to Japan\n";
	system "cp -f $out_dir/usr/share/zoneinfo/Japan $out_dir/etc/localtime";

	#print "Copying X settings to $out_dir\n";
	#my $blah = readlink "/root/bin/X";
	#my @stuff = split /\// , $blah;
	#my $file = pop( @stuff );
	#print "X server is $blah file is $file\n";
	#if (( $file eq "Xpmac" ) || ( $file eq "XF68_FBDev" )) {
	#} else {
	#	if( -e "/ram1/$file" ) {
	#		system "cp /ram1/$file $out_dir/usr/X11R6/bin/";
	#	} elsif ( -e "/mnt/cdrom/live/bin/$file" ) {
	#		system "cp /mnt/cdrom/live/bin/$file $out_dir/usr/X11R6/bin/";
	#	}
	#}
	#system "ln -sf /usr/X11R6/bin/$file $out_dir/etc/X11/X";
	my $blah = readlink "/root/bin/X";
	my @stuff = split /\// , $blah;
	my $file = pop( @stuff );
	print "X server is $blah file is $file\n";
	if ( $file eq "XFree86-4.0-mga-r128-v2" ) {
	    print "\nSetting up XFree86-4.0-mga-r128-v2 ... ";
	    system "cp -a /etc/XF86Config.iMacDV2 $out_dir/etc/X11/XF86Config";
	    system "cp -a /etc/XF86Config.iMacDV2 $out_dir/etc/X11/XF86Config.iMacDV";
	    system "chmod 644 $out_dir/etc/X11/XF86Config";
	    system "chroot $out_dir chkfontpath /usr/X11R6/lib/X11/fonts/TrueType";
	    system "cp -a /mnt/cdrom/live/bin/XFree86-4.0-mga-r128-v2 $out_dir/usr/X11R6/bin";
	    system "chmod 755 $out_dir/usr/X11R6/bin/XFree86-4.0-mga-r128-v2";
	    system "ln -sf ../../usr/X11R6/bin/XFree86-4.0-mga-r128-v2 $out_dir/etc/X11/X";
	    print "DONE\n";
	} else {
	if (( $file eq "Xpmac" ) || ( $file eq "Xpmac.rage128.usb.rev9" )) {
	    print "Setting up Xpmac rev.10 ...\n";
	    system "ln -sf ../../usr/X11R6/bin/Xpmac $out_dir/etc/X11/X";
	    #
	    # Replace Xpmac.conf file
	    #
	    if ( -f "/tmp/usb_jp" ) {
		system "cp -p /root/bin/Xpmac.conf.usb_jp $out_dir/etc/X11/Xpmac.conf";
	    } elsif ( -f "/tmp/adb_jp" ) {
		system "cp -p /root/bin/Xpmac.conf.adb_jp $out_dir/etc/X11/Xpmac.conf";
	    }
	    #
	    # Set init default to 5
	    #
	    system "sed -e 's/^id:3:initdefault:/id:5:initdefault:/' $out_dir/etc/inittab > $out_dir/etc/inittab.new";
	    system "mv -f $out_dir/etc/inittab.new $out_dir/etc/inittab";
	    #
	} else {
	    system "ln -sf ../../usr/X11R6/bin/XF68_FBDev $out_dir/etc/X11/X";
	    system "cp -a /etc/X11/XF86Config $out_dir/etc/X11/";
	} }

	print "Preparing appropriate mouse/keyboard settings ...\n";
	system("cp -a /etc/sysconfig/mouse $out_dir/etc/sysconfig/");
	system("cp -a /etc/sysconfig/keyboard $out_dir/etc/sysconfig/");
	system("rm -f $out_dir/dev/mouse");
	system("cp -a /dev/mouse $out_dir/dev/mouse");
	system("touch $out_dir/etc/sysconfig/keyboard");
	system("touch $out_dir/etc/sysconfig/sound");

	# FIX netscape preferences
	system("cp -a /root/bin/.netscape $out_dir/etc/skel/.");
	system("cp -a /root/bin/.netscape $out_dir/root/.");

	# FIX /etc/X11/WindowMaker/WindowMaker
	print "Preparing Mac-savvy WindowMaker setting ...\n";
	system("cp -af /live/fixes/WindowMaker $out_dir/etc/X11/WindowMaker/.");

	# FIX /usr/doc/HTML/index.html for PPC
	#print "Replacing index.html for PPC ...\n";
	#system("cp -af /root/bin/index.html $out_dir/usr/doc/HTML/index.html");

	# FIX /etc/X11/xinit/xinitrc and xdm/Xsession
	#print "\nDOING $VERSION version FIXES to xinit, Xsession, and bashrc\n\n";
	#if( -d "$out_dir/etc/X11/xinit/" ) {
	#	my_system("cp -a /etc/X11/xinit/xinitrc $out_dir/etc/X11/xinit/");
	#}
	#if( -d "$out_dir/etc/X11/xdm/" ) {
	#	my_system("cp -a /etc/X11/Xsession $out_dir/etc/X11/xdm/");
	#}

	# Add aliases to /etc/bashrc
	#open( BASHRC , ">>/$out_dir/etc/bashrc" );
	#print BASHRC "alias lf=\"ls -aCF\"\n";
	#print BASHRC "alias ll=\"ls -alF\"\n";
	#print BASHRC "alias pa=\"ps -axuw\"\n";
	#print BASHRC "PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin:/usr/games:\$HOME/bin\n";
	#print BASHRC "\nPS1=\"\[\\u\@\\h \\W\]\\\\\$ \"\n\n";
	#print BASHRC "export PS1 PATH\n";
	#close( BASHRC );

	write_passwd("");

	#net_set is 1 if nfs or ftp install we need write the network files out

	print "Copying network settings to $out_dir\n";
	if( ! -e "$out_dir/etc/hosts" ) {
		my_system("cp /etc/hosts $out_dir/etc/"); }
	if( ! -e "$out_dir/etc/resolv.conf" ) {
		my_system("cp  /etc/resolv.conf $out_dir/etc/resolv.conf"); }
	if( ! -e "$out_dir/etc/sysconfig/network" ) {
		my_system("cp  /etc/sysconfig/network $out_dir/etc/sysconfig/network"); }
	my_system("cp -f /etc/sysconfig/network-scripts/ifcfg-* $out_dir/etc/sysconfig/network-scripts/.");

	if ( -e "/etc/pump.conf" ) {
		my_system("cp /etc/pump.conf $out_dir/etc/"); }

	#system("cp -a /etc/pam.d/passwd $out_dir/etc/pam.d/passwd");

	# Fix /var/spool/mqueue permissions so anyone can send mail
	#if( -e "$out_dir/var/spool/mqueue" ) {
	#	system( "chmod 755 $out_dir/var/spool/mqueue" );
	#}

	if ( ($prep_install) && (defined($prepboot)) ) {
		if ($mke2_mount{$prepboot}) {
			#prepboot exists and was clicked
			print "It looks like /dev/$prepboot is the PPC PReP Boot\n";
			print "Running	* dd if=/tmp/install/PReP.zImage of=/dev/$prepboot\n";
			my_system("dd if=/tmp/install/PReP.zImage of=/dev/$prepboot");
		}
	}

	# Make sure all the devices exist
	my( @usedrive, $i, $j );
	foreach $i (sort keys(%drive_hash)) { push(@usedrive,$i) }
	foreach $i (sort(@usedrive)) {
	    for $j (sort keys(%{$drive_hash{$i}})) {
			mknod $i, $j, "$out_dir/dev";
		}
	}

	# Update xli.pl manually
	#system "cp -a /root/bin/xinstaller.ja $out_dir/usr/X11R6/bin/xinstaller";
	#system "cp -a /root/bin/English $out_dir/usr/X11R6/lib/xinstaller/";
	#system "cp -a /root/bin/Japanese $out_dir/usr/X11R6/lib/xinstaller/";
	#system "echo LinuxPPC 2000 > $out_dir/etc/redhat-release";
	
	#if( ! -e "$out_dir/home/root" ) {
	#	system "cp -a $out_dir/root $out_dir/home/";
	#}
	#system "cp -a /live/fixes/inetd.conf $out_dir/etc/";
	#system "cp -a /live/fixes/inittab $out_dir/etc/";
	#system "cp -a /live/fixes/rc.sysinit $out_dir/etc/rc.d/";
	#system "cp -a /live/fixes/redhat.links $out_dir/usr/lib/desktop-links/";
	#system "cp -a /live/fixes/default-page.html $out_dir/usr/share/gnome/help/help-browser/C/";

	if( -e "/mnt/cdrom/live/modules-2.2.15pre14-ben1.tar.gz" ) {
		chdir "$out_dir";
		system "tar xfz /mnt/cdrom/live/modules-2.2.15pre14-ben1.tar.gz";
	}
	if( -e "/mnt/cdrom/live/System.map-2.2.15pre14-ben1.gz" ) {
		chdir "$out_dir/boot/";
		system "cp -f /mnt/cdrom/live/System.map-2.2.15pre14-ben1.gz .";
		system "gzip -fd System.map-2.2.15pre14-ben1.gz";
	}
	if( -e "/mnt/cdrom/Linux\ Kernels/vmlinux-2.2.15pre14-ben1" ) {
		chdir "$out_dir/boot/";
		system "cp -f /mnt/cdrom/Linux\\ Kernels/vmlinux-2.2.15pre14-ben1 .";
	}
        # setup cdrom device in installation
        print "Create /dev/cdrom link ...\n";
        my($devcdrom) = `grep 'drive name:' /proc/sys/dev/cdrom/info`;
        my(@devcdroms);
        if (defined($devcdrom)) {
                $devcdrom =~ s/^\s*drive\s+name\s*:\s+//;
                @devcdroms = split(" ", $devcdrom);
                @devcdroms = sort(@devcdroms);
                $devcdrom = pop(@devcdroms);
                if ($devcdrom) {
			if( substr( $devcdrom, 0, 2 ) eq "sr" ) {
				$devcdrom = "scd" . substr( $devcdrom, 2, 1 );
			}
                        print "found /dev/$devcdrom as main CD-ROM device\n";
                        system("ln -fs /dev/$devcdrom $out_dir/dev/cdrom");
                }
        }

	#if( ! -e "$out_dir/etc/conf.modules" ) {
	#	system "echo alias sound dmasound >> $out_dir/etc/conf.modules";
	#}
	system "echo alias sound dmasound >> $out_dir/etc/conf.modules";

	# gdm fixes
	#system "chroot $out_dir /usr/sbin/useradd -u 42 -r gdm > /dev/null";
	#system "mkdir $out_dir/var/gdm";
	#system "chroot $out_dir chown gdm:gdm /var/gdm";
	#system "ln -sf /dev/null $out_dir/var/gdm/\:0.log";
}

sub create_passwd {
	my($box1,$box2,$entry,$entry2,$button,$separator,$i,$buffer,$label);
	
	# ok here there will be two entry fields with no echo
	# new root passwd typed in both then 'set' button will
	# compare the entries then if the same set new install root passwd

	create_standard_window( $passwd_window, 260, 20, 190, 160, $words{Passwd_Title} );

	$box1 = create_standard_vbox( 0 );

	$entry = create_standard_entry( $words{Password}, "", $box1 );
	$entry->set_visibility(0);
	
	$entry2 = create_standard_entry($words{Again}, "", $box1 );
	$entry2->set_visibility(0);

	my_separator($box1);

	$button = new Gtk::Button $words{Set_password};
	$button->can_focus(0);
	$button->can_default(1);
	$button->signal_connect("clicked", sub { 
		my(@cmp_list) = ();
		my($tmp) = $entry->get_text;
		push(@cmp_list,$tmp);
		$tmp = $entry2->get_text;
		push(@cmp_list,$tmp);
		if ($cmp_list[0] eq $cmp_list[1]) {
			print "They match!\n";
			print "Setting root passwd\n";
			$root_passwd = $cmp_list[0];
			write_passwd($root_passwd);
			# set useshadow & enablemd5 with authconfig
			print "Enabling shadow / md5 password ...\n";
			system "chroot $out_dir authconfig --nostart --useshadow --enablemd5 --kickstart";
			destroy $passwd_window;
			if( -e "/live/lib" ) {
				print "You are done!\n";
				&create_finished_window( 260, 20, 375, 350, 
				$words{ Congradulations }, $words{Finished_Message} ) 
			}
		} else {
			$entry->set_text("");
			$entry2->set_text("");
		}
	});
	$box1->pack_start($button, 1, 1, 0);
	$button->show;

	create_standard_button( $words{Cancel} , $box1, 1, 1, 0, sub {
		$passwd_window->destroy; 
	});
}

sub create_text_window {
	my($box1,$box2,$button,$separator,$table,$hscrollbar,$vscrollbar,$text);
	my($pixmap1, $bg1, $pixmapdir);

	create_standard_window( $cngrat_window, $_[0], $_[1], $_[2], $_[3], $_[4] ) || return;
	$bg1 = $cngrat_window->style->bg('normal');

	$box1 = create_standard_vbox( 0 );
	$box2 = create_standard_vbox( 10, $box1, 1, 1, 0 );

	$table = new Gtk::Table(3,2,0);
	$table->set_row_spacing(0,2);
	$table->set_col_spacing(0,2);
	$box2->pack_start($table,1,1,0);
	$table->show;

	if ( defined $_[7] ) {
		if ( -e "/usr/X11R6/lib/xinstaller/pixmaps" ) {
			$pixmapdir = "/usr/X11R6/lib/xinstaller/pixmaps";
		} else {
			$pixmapdir = "/root/bin/pixmaps";
		}
		$pixmap1 = new_pixmap("$pixmapdir/$_[7].xpm", $cngrat_window->window, $bg1);
		$table->attach_defaults($pixmap1, 0,1,0,1);
		show $pixmap1;
	}

	$text = new Gtk::Text(undef,undef);
	$table->attach_defaults($text, 0,1,1,2);
	show $text;
		
	$hscrollbar = new Gtk::HScrollbar($text->hadj);
	$table->attach($hscrollbar, 0, 1,2,3,[-expand,-fill],[-fill],0,0);
	$hscrollbar->show;

	$vscrollbar = new Gtk::VScrollbar($text->vadj);
	$table->attach($vscrollbar, 1, 2,1,2,[-fill],[-expand,-fill],0,0);
	$vscrollbar->show;
		
	$text->freeze;
	$text->realize;
	
	$text->insert(undef,$text->style->black,undef, $_[6] );
	
	$text->thaw;

	$box2 = my_separator($box1);
		
	create_standard_button( $_[5] , $box2, 1, 1, 0, sub {
		$cngrat_window->destroy; 
	});
}

sub create_finished_window {
	my($box1,$box2,$button,$separator,$table,$hscrollbar,$vscrollbar,$text);
	
	create_standard_window( $cngrat_window, $_[0], $_[1], $_[2], $_[3], $_[4] ) || return;

	$box1 = create_standard_vbox( 0 );
	$box2 = create_standard_vbox( 10, $box1, 1, 1, 0 );

	$table = new Gtk::Table(2,2,0);
	$table->set_row_spacing(0,2);
	$table->set_col_spacing(0,2);
	$box2->pack_start($table,1,1,0);
	$table->show;
		
	$text = new Gtk::Text(undef,undef);
	$table->attach_defaults($text, 0,1,0,1);
	show $text;
		
	$hscrollbar = new Gtk::HScrollbar($text->hadj);
	$table->attach($hscrollbar, 0, 1,1,2,[-expand,-fill],[-fill],0,0);
	$hscrollbar->show;

	$vscrollbar = new Gtk::VScrollbar($text->vadj);
	$table->attach($vscrollbar, 1, 2,0,1,[-fill],[-expand,-fill],0,0);
	$vscrollbar->show;
		
	$text->freeze;
	$text->realize;
	
	$text->insert(undef,$text->style->black,undef, $_[5] );
	
	$text->thaw;

	$box2 = my_separator($box1);
		
	create_standard_button( $words{Reboot} , $box2, 1, 1, 0, \&do_exit );
}

sub get_install_order {
	my( @order );

	my $path = find_file "order.master";
	if ( $path ne "" ) {
		open (MAP, "$path");
	} else {
		print "order.master does not exist\n";
	}

        while( <MAP> ) {
                chop( $_ );
                if( $_ eq "" ) { next; }
                push( @order, $_ );
        }
	return @order;
}

sub get_package_info {
	my( @stuff, $filename, $date, $version, $revision, $size, $description, $path);

	$path = find_file "hdlistinfo";
	if ( $path ne "" ) {
		open (INFO, "$path");
	} else {
		print "hdlistinfo does not exist\n";
		return;
	}

        while(<INFO>) {
                my($key, $value) = split( "\t" , $_ );
		@stuff = split( " " , $value );
		$filename = shift( @stuff );
		shift( @stuff );
		$date = shift( @stuff );
		$version = shift( @stuff );
		$revision = shift( @stuff );
		$size = shift( @stuff );
		$description = join( " ", @stuff );
                $hdlistinfo{$key} = "$filename\t$date\t$version\t$revision\t$size\t$description";
		if( ! exists $rpmlist{$key} ) { 
#			print "$key "; 
			$rpmlist{$key} = "$words{Miscellaneous}";
		}
        }
#	print "are all not in install.master yet.\n";
        close(INFO);
}


sub scan_install_master {
	my( @stuff, @master, $set, $rpm, $temp, $path );

	$path = find_file "install.master";
	if ( $path ne "" ) {
		open (MAP, "$path");
	} else {
		print "install.master does not exist\n";
		return;
	}

	undef %map;
	while( <MAP> ) {
                chop( $_ );
                if( $_ eq "" ) { next; }
                ( $set , $temp ) = split( ":" , $_ );
        #       $set = shift @stuff );
                @stuff = split( " " , $temp );
		push(@master,$set);
                foreach $rpm ( @stuff ) {
			if( exists $rpmlist{$rpm} ) { next; }
			$rpmlist{$rpm} = $set;  # Add to rpm master list
                        foreach $temp ( @ARGV ) {
                                if( $set eq $temp ) {  $map{ "$rpm" } = $set; }
                        }
                }
        }
        close( MAP );

	#dir read stuff

	#possibly add an all option here to filenames array
	return @master , "$words{Miscellaneous}";
}

sub mount_drives {
	# read through %mount_fstab hash mounting drive to install to
	# and also deal with turning on swap
	my($i,$j,$p);
	my( %mount_point, @mount_order );

	system ("mkdir -p $out_dir/tmp");

	# This code sorts out the drives to mount based on the mountpoint
	foreach $i (sort keys(%mount_fstab)) {
		$mount_point{ $mount_fstab{$i} } = $i;
	}
	foreach $i (sort keys(%mount_point)) {
		@mount_order = ( @mount_order , $mount_point{ $i } );
	}

	# mkswap and swapon swap partitions
	foreach $i ( @mount_order ) {
		if ($mount_fstab{$i} =~ /[Ss]wap/) {
			system "mkswap /dev/$i";
			system "swapon /dev/$i";
		}
	}

	print "Final mount order = @mount_order\n";
	foreach $i ( @mount_order ) {
		print "mount_fstab key = $i \n";
		if ($mount_fstab{$i} =~ /[Ss]wap/) {
			next;
		} elsif ($mount_fstab{$i} =~ /PPC PReP Boot/) {
			$prepboot = $i;
			next;
		}
		if (! -e ("$out_dir".$mount_fstab{$i})) { 
			system ("mkdir -p $out_dir/$mount_fstab{$i}"); 
		}
		# run mke2fs on drives that need it
		my(@tmp_array) = split (//,$i);
		$j = $tmp_array[0].$tmp_array[1].$tmp_array[2];
		#get rid off drive name
		shift(@tmp_array);
		shift(@tmp_array);
		shift(@tmp_array);
		$p = join '',@tmp_array;

		if ($mke2_mount{$i} ) {
			if( $mount_fstab{$i} eq "/boot" ) {
				my_system "hformat -l \"Vine Linux Boot\" /dev/$i";
				my_system "mk_boot.pl /dev/$i";
			} else {
				my_system "mke2fs /dev/$i";
			}
		} else {
			print "Not mke2fsing /dev/$i\n";
		}

		my $tmppoint = "$out_dir$mount_fstab{$i}";
		$tmppoint =~ s/\/\/+/\//g;
		my_system "mount /dev/$i $tmppoint";
	}
}

sub make_fstab {
	my($i, $label);
	#make fstab file in $out_dir/etc/fstab

	my($file_name) = $out_dir."etc/fstab";
	if( -e $file_name ) { return; }
	open (FSTAB,">$file_name");

	my( %mount_point, @mount_order );
	foreach $i (sort keys(%mount_fstab)) {
		$mount_point{ $mount_fstab{$i} } = $i;
	}
	foreach $i (sort keys(%mount_point)) {
		@mount_order = ( @mount_order , $mount_point{ $i } );
		print "new order: $i\n";
	}
	print "Final mount order = @mount_order\n";

	my $counter = 0;
	foreach $i ( @mount_order ) {
		if ($mount_fstab{$i} =~ /[Ss]wap/) {
			my $swapline = pack "A20", "/dev/$i";
			print FSTAB "$swapline swap                 swap    defaults        0 0\n";
			next;
		} 
		++$counter;
		$label = get_e2label ( "/dev/$i" );
		my ( $entry, $length, $count, $mountpoint);
		my $type = "auto";
		if( $label eq "" ) {
			$entry = "/dev/$i";
		} else {
			print "/dev/$i label = $label\n";
			# $entry = "LABEL=$label";
			$entry = "/dev/$i";
			$type = "ext2";
		}

		$length = 20 - length $entry;
		for $count ( 1 ... $length ) { $entry .= " "; }

		if( length $mount_fstab{$i} < 20 ) {
			$mountpoint = pack "A20", $mount_fstab{$i};
		} else {
			$mountpoint = $mount_fstab{$i};
		}

		print FSTAB ("$entry $mountpoint $type    defaults        1 $counter\n");
	}

	print FSTAB "/dev/fd0             /mnt/floppy          auto    noauto          0 0\n";
	print FSTAB "/dev/cdrom           /mnt/cdrom           auto    noauto          0 0\n";
	print FSTAB "none                 /proc                proc    defaults        0 0\n";
	print FSTAB "none                 /dev/pts             devpts  gid=5\,mode=620  0 0\n";
	close(FSTAB);
}

sub get_e2label {
	my $device = $_[0];

	my $e2label = `e2label $device`;
	# if( ! defined $e2label ) { print "not defined\n"; }
	if( $e2label eq "" ) { 
		print "Skiping label for $device - not ext2 filesystem\n";
		return "";
	}
	chomp $e2label;
	if( $e2label eq "" ) {
		my $uuid_tmp = substr `uuidgen`, 0 , 8;
		chomp $uuid_tmp;
		system "e2label $device $uuid_tmp";
	}

	$e2label = `e2label $device`;
	chomp $e2label;
	return "$e2label";
}

sub write_passwd {
    my($rootp) = shift;
    my($line);
    my(@pass_file) = ();

    my $salt = "R5";
    my $crypt_passwd = crypt($rootp,$salt);
    my($pass_line) = join(':', "root",$crypt_passwd,"0:0:root:/root:/bin/bash");

    open(PASSWD,"$out_dir/etc/passwd");
    while (defined($line = <PASSWD>)) { 
    	next if ($line =~ /^root/);
	push(@pass_file,$line); 
    }
    close (PASSWD);
    open(PASSWD,">$out_dir/etc/passwd");
    print PASSWD "$pass_line\n";

    while ($line = shift(@pass_file)) {
	print PASSWD $line;
    }
    close(PASSWD);
    my_system( "chroot $out_dir pwconv" );
}

sub report_add {
	my($key,$devs,$device,$hostnameonly);
	my($net_dir) = $out_dir; 

	if($net_set eq 1) {
		$net_dir = "/";
	}
	$device = $my_widgets{devname}->get_text;

	print "Writing $net_dir/etc/sysconfig/network/ifcfg-$device:\n";
	open (IFCFG, ">$net_dir/etc/sysconfig/network-scripts/ifcfg-$device") || print "Cannot open $net_dir/etc/sysconfig/network-scripts/ifcfg-$device\n";
	print IFCFG "DEVICE=$device\n";

	my($tmp) = $my_widgets{ipaddr}->get_text;
        if($bootproto eq "dhcp") { $tmp = ""; }
	print IFCFG "IPADDR=$tmp\n";

	$tmp = $my_widgets{netmask}->get_text;
        if($bootproto eq "dhcp") { $tmp = ""; }
	print IFCFG "NETMASK=$tmp\n";

	if ($my_widgets{onboot}->state eq "active") {
		print IFCFG "ONBOOT=yes\n";
	} else {
		print IFCFG "ONBOOT=no\n";
	}
	print IFCFG "BOOTPROTO=$bootproto\n";
	close(IFCFG);

	print "Writing $net_dir/etc/sysconfig/network:\n";
	open (NETCFG, ">$net_dir/etc/sysconfig/network") || print "Cannot open $net_dir/etc/sysconfig/network\n";
	print NETCFG "NETWORKING=yes\n";
	print NETCFG "FORWARD_IPV4=false\n";

	my($hostname) = $my_widgets{hostname}->get_text;
	if( $hostname eq "" ) { $hostname="localhost" }
	print NETCFG "HOSTNAME=$hostname\n";

	$tmp = $my_widgets{gateway}->get_text;
        if($bootproto eq "dhcp") { $tmp = ""; }
	print NETCFG "GATEWAY=$tmp\n";

	if ($my_widgets{defgtw}->state eq "active") {
        	if($bootproto eq "none")
		{
			print NETCFG "GATEWAYDEV=$device\n";
		} else {
			print NETCFG "GATEWAYDEV=\n";
		}
	} else {
		print NETCFG "GATEWAYDEV=\n";
	}
	close (NETCFG);

	my($ns) = $my_widgets{dns}->get_text;
	if ($ns eq "") { $ns = "127.0.0.1"; }

        if($bootproto eq "none")
	{
		open (RESOLV, ">$net_dir/etc/resolv.conf") || print "Cannot open resolv.conf\n";
		#get domainname from hostname
		my(@parts) = split(/\./, $hostname ); 
		$hostnameonly = shift (@parts);
		$tmp = join ('.', @parts);

		print "domain looks like = $tmp\n";
		print RESOLV "domain $tmp\n";
		print RESOLV "search $tmp\n";
		print RESOLV "nameserver $ns\n";
		close (RESOLV);

		open (HOSTS, ">$net_dir/etc/hosts") || print "Cannot open /etc/hosts\n";
		print HOSTS "127.0.0.1	localhost localhost.localdomain\n";
		if ($hostnameonly ne "localhost") {
			$tmp = $my_widgets{ipaddr}->get_text;
			print HOSTS "$tmp    $hostnameonly $hostname\n";
		}
		close (HOSTS);
	}

	if ($bootproto eq "dhcp")
	{
		open (PUMP, ">$net_dir/etc/pump.conf") || print "Cannot open pump.conf\n";
		$tmp = $my_widgets{searchdomain}->get_text;
		print "DHCP searchdomain is \"$tmp\"\n";
		if ($tmp ne "") {
			print PUMP "domainsearch \"$tmp\"\n";
		}
		close (PUMP);
	}

	system ( "hostname $hostname" );

	if ($net_set eq 1) { 
		print "$in_method installation... setting up network device now \n";
		print "Running  * ifup ifcfg-$device\n";
        	if($bootproto eq "none")
		{
			system ("ifup ifcfg-$device");
		}
	}

	$net_window->destroy;
}

sub create_net {
	my($chk_boot,$chk_def,$hostname, $searchdomain);
	my($vbox,$hbox,$bbox,$button,$label,$chkbox,$entry);	#local widgets
	my $myipaddr = "192.168.1.1";
	my $mygateway = "192.168.1.254";
	my $mynetmask = "255.255.255.0";
	my $myonboot = "yes";
	my $mydns = "";

	# check current setting and set default if available
	if ( -f "/etc/sysconfig/network" ) {
		open (NETWORK, '/etc/sysconfig/network');
		while (<NETWORK>) {
			chop;
			if (s/^GATEWAY\=//)  { $mygateway = $_; }
		}
		close (NETWORK);
	}
	if ( -f "/etc/sysconfig/network-scripts/ifcfg-eth0" ) {
		open (ETH0, '/etc/sysconfig/network-scripts/ifcfg-eth0');
		while (<ETH0>) {
			chop;
			if (s/^IPADDR\=//)  { $myipaddr = $_; }
			if (s/^NETMASK\=//) { $mynetmask = $_; }
			if (s/^ONBOOT\=//) { $myonboot = $_; }
		}
		close (ETH0);
	}
	if ( -f "/etc/resolv.conf" ) {
		open (RESOLV, '/etc/resolv.conf');
		while (<RESOLV>) {
			chop;
			if (s/^nameserver\ //) { @_=split; $mydns = $_[0]; }
		}
		close (RESOLV);
	}

	create_standard_window( $net_window, 260, 20, -1, 450, $words{Setup_Network} );

	$vbox = create_standard_vbox( 5 );

	if ( $bootproto eq "none" )
	{
		$hbox = create_standard_hbox( 5 , $vbox , 0, 1, 0);

		$my_widgets{devname} = create_standard_entry( $words{Device_Name}, "eth0", $vbox );
		$my_widgets{ipaddr} = create_standard_entry( $words{IP_Address}, $myipaddr, $vbox );
		$my_widgets{gateway} = create_standard_entry( $words{Gateway}, $mygateway, $vbox );
		$my_widgets{netmask} = create_standard_entry( $words{Netmask}, $mynetmask, $vbox );
	} else {
		$hbox = create_standard_hbox( 5 , $vbox , 0, 1, 0);
		$label = create_standard_label( "$words{DHCP_Set1}" , $hbox, 1, 1, 0 );
		$hbox = create_standard_hbox( 5 , $vbox , 0, 1, 0);
		$label = create_standard_label( "$words{DHCP_Set2}" , $hbox, 1, 1, 0 );
		$hbox = create_standard_hbox( 5 , $vbox , 0, 1, 0);
		$label = create_standard_label( "$words{DHCP_Set3}" , $hbox, 1, 1, 0 );
	}

	$hbox = create_standard_hbox( 5 , $vbox , 0, 1, 0);

	#on boot cbox
		$chkbox = new Gtk::CheckButton $words{On_Boot};
		$hbox->pack_start($chkbox, 1, 0, 1);
		if ( $myonboot eq "yes" ) {
			$chkbox->set_state(1);
		}
		else {
			$chkbox->set_state(0);
		}
		$chkbox->show;
		$my_widgets{onboot} = $chkbox;

	if ( $bootproto eq "none" )
	{
	#default gtway cbox
		$chkbox = new Gtk::CheckButton $words{Default_Gateway};
		$hbox->pack_start($chkbox, 1, 0, 1);
		$chkbox->set_state(1);
		$chkbox->show;
		$my_widgets{defgtw} = $chkbox;
	}

	$hbox = my_separator($vbox);

	chop( $hostname = `hostname` );
	print "hostname returned $hostname \n";
	if( $hostname eq "(none)" ) { $hostname = "localhost.localdomain"; }
	$my_widgets{hostname} = create_standard_entry($words{Hostname}, "$hostname", $vbox );

	if ( $bootproto eq "dhcp" )
	{
		$my_widgets{searchdomain} = create_standard_entry($words{SearchDomain}, "", $vbox );
	}

	if ( $bootproto eq "none" )
	{
		$my_widgets{dns} = create_standard_entry( $words{Nameserver}, $mydns, $vbox );
	}

	$bbox = my_separator($vbox);

	create_standard_button( $words{Activate} , $bbox, 1, 0, 1, \&report_add );
	# if( ! -e "/live/lib/" ) {
	create_standard_button( $words{Setup_DHCP} , $bbox, 1, 0, 1, sub {
		print "Running dhcpcd to configure the network\n";
		if( -e "/sbin/dhcpcd" ) {
			system( "dhcpcd" );
			$bootproto = "dhcp" ;
			$net_window->destroy;
			create_net();
		} else {
			create_text_window( 260, 20, 400, 350, $words{welcome_title},
			$words{Close}, $words{DHCP_Warning}, "stop");
		}
	});
	# }

	create_standard_button( $words{Start_Over} , $bbox, 1, 0, 1, sub {
		print "Reset and configure network again\n";
		$bootproto = "none" ;
		$net_window->destroy;
		create_net();
	});

	# create_standard_button( $words{Setup_PPP} , $bbox, 1, 0, 1, sub {
	#	print "Running kppp\n";
	#	if( -e "/usr/bin/kppp" ) {
	#		system( "kppp &" );
	#	} else {
	#		create_text_window( 260, 20, 400, 350, $words{welcome_title},
	#		$words{Close}, $words{KPPP_Warning});
	#	}
	#});

	create_standard_button( $words{Close} , $bbox, 1, 0, 1, sub {
		$net_window->destroy; 
	});
}

sub do_exit {
	print "done!\n";
	if( $ChangeLanguage eq TRUE ) { return; }
	if( -e "/live/lib/" ) {
		system( "umount $out_dir/proc" );
		sleep 1;
		system( "sync" );
		sleep 1;
		system( "mount -a" );
		sleep 1;
		system( "init 6 &" );
	}
	Gtk->exit(0);
}

## Create Splash Window (new install only)
sub create_splash_window {
	my( $box1, $box2, $button, $bg, $pixmap1 );

	create_standard_window( $splash_window, 260, 20, 400, 400, $words{Welcome_Title} );

	$box1 = create_standard_vbox( 0 );
	$bg = $splash_window->style->bg('normal');
	$pixmap1 = new_pixmap( "/root/bin/pixmaps/vine_logo.xpm", $splash_window->window, $bg );
	$pixmap1->show;
	$box1->pack_start( $pixmap1, 1, 1, 10 );

	my_separator( $box1 );

	$button = create_standard_button( $words{Continue}, $box1, 1, 0, 1 );
	$button->signal_connect('clicked', sub {
		#create_main_window();
		create_instruction_window();
		$splash_window->destroy;
	} );
}

## Create Instruction Window (new install only)
sub create_instruction_window {
	create_text_window( 260, 20, 420, 350, $words{welcome_title},
		$words{Continue}, $words{welcome_text}, "note");
	$cngrat_window->signal_connect("destroy" => \&create_network_window);
}

## Create Network Window (new install only)
sub create_network_window {
	create_net();
#	$net_window->signal_connect("destroy" => \&create_mount);
}

## Create MAIN Window
sub create_main_window {
	my( @buttons, $box1, $scw, $box2, $button, $hbox,
		$separator, $buffer, $label, $i);

	create_standard_window( $main_window, 20, 20, 230, 350, "X Linux Installer" ) || return;
	$main_window->signal_connect("destroy" => \&do_exit);
#	$main_window->signal_connect("destroy" => \&Gtk::main_quit);

	$box1 = create_standard_vbox( 0 );
	$hbox = create_standard_hbox( 0 , $box1, 0, 0, 0 );
	$label = create_standard_label( "$words{Version} $VERSION" , $hbox, 1, 1, 0 );

	my( $menubar, $menu, $submenu, $menuitem, $name );
	$menubar = new Gtk::MenuBar;
	$hbox->pack_start($menubar, 1, 1, 0);
	$menubar->show;
	
	$menu = new Gtk::Menu;
	$submenu = undef;
	$menuitem = undef;
	
	$menuitem = new Gtk::MenuItem( $words{Credits} );
	$menu->append($menuitem);
	$menuitem->signal_connect("activate", sub { 
		&create_text_window( 260, 20, 400, 200, 
		$words{ Credits }, $words{Close}, $words{Credits_Text}, "note") 
	} );
	$menuitem->show;

	$menuitem = new Gtk::MenuItem( $words{About_BootX} );
	$menu->append($menuitem);
	$menuitem->signal_connect("activate", sub { 
		&create_text_window( 260, 20, 500, 200, 
		$words{ Using_BootX }, $words{Close}, $words{BootX_message}, "note" ) 
	} );
	$menuitem->show;

#	if( ! -e "/live/lib/" ) {
#		$menuitem = new Gtk::MenuItem( $words{Update_Installer} );
#		$menu->append($menuitem);
#		$menuitem->signal_connect("activate", sub { 
#			my($tmp) = "http://www.linuxppc.org/xinstaller/";
#			chdir "$out_dir/tmp";
#			print "Getting new file from $tmp .\n";
#			system "$wget $tmp/2000_CURRENT";
#			if (-e "./2000_CURRENT" ) {
#				my($current) = `cat 2000_CURRENT`;
#				system( "rpm -hviU $tmp/$current" );
#				exec "xinstaller";
#			} else {
#				print "Failed getting new version.\n";
#			}
#		});
#		$menuitem->show;
#	}

	$menuitem = new Gtk::MenuItem( $words{Launch_xterm} );
	$menu->append($menuitem);
	$menuitem->signal_connect("activate", sub { system "xterm &"; } );
	$menuitem->show;

#	$menuitem = new Gtk::MenuItem( $words{Configure_Keys} );
#	$menu->append($menuitem);
#	$menuitem->signal_connect("activate", sub { system "xmodmap.pl &"; } );
#	$menuitem->show;

	$menuitem = new Gtk::MenuItem( $words{Show_output} );
	$menu->append($menuitem);
	$menuitem->signal_connect("activate", sub { 
		system "xterm -T output -e xinstaller &";
		Gtk->exit(0);
	} );
	$menuitem->show;

	$menuitem = new Gtk::MenuItem( $words{Choose_Method} );
	$menu->append($menuitem);
	$menuitem->signal_connect("activate", \&create_method );
	$menuitem->show;

	$menuitem = new Gtk::MenuItem( $words{Network_Config} );
	$menu->append($menuitem);
	$menuitem->signal_connect("activate", \&create_net );
	$menuitem->show;

	$menuitem = new Gtk::MenuItem( $words{ Options_Menu } );
	$menuitem->set_submenu($menu);
	$menubar->append($menuitem);
	show $menuitem;

	if((-e "/root/bin/perldisk") || (-e "/usr/bin/perldisk" )){
		$menuitem = new Gtk::MenuItem( $words{Partition_Drives} );
		$menu->append($menuitem);
		$menuitem->signal_connect("activate", sub{ 
			system "perldisk /dev/hda &";
		} );
		$menuitem->show;
	}
	
	$scw = new Gtk::ScrolledWindow(undef, undef);
	$scw->set_policy('automatic', 'automatic');
	$scw->show;
	$scw->border_width(10);			#gtk 1.0 doesnt have this
	$box1->pack_start($scw, 1, 1, 0);

	$box2 = create_standard_vbox( 10, $main_window );
	$scw->add_with_viewport($box2);		#for x86/ppc with new gtk
	
	create_standard_button( $words{Instructions} , $box2, 1, 1, 0, sub {
		create_text_window( 260, 20, 420, 350, $words{welcome_title},
		$words{Close}, $words{welcome_text}, "note");
	} );

	if((-e "/root/bin/perldisk") || (-e "/usr/bin/perldisk" )){
		create_standard_button( $words{Partition_Drives}, $box2, 1,1,0,sub{
			print "Starting perldisk\n";
			system "perldisk /dev/hda &";
			if ( defined $mount_window ) { $mount_window->destroy; return; }
		});
	}

	if( (-e "/live/perldisk/perldisk") || (-e "/usr/bin/perldisk" ) ){
		create_standard_button( $words{Partition_Drives} , $box2, 1, 1, 0, sub {
			print "Starting perldisk\n";
				system "perldisk &";
		});
	}

	if( -e "/live/lib/" ) {
		create_standard_button( "$words{Select_Partitions}" , 
			$box2, 1, 1, 0, \&create_mount );
	} else {
		$out_dir = "/"; 
		print "Installing into out_dir = $out_dir\n";
		$menuitem = new Gtk::MenuItem( $words{Select_Partitions} );
		$menu->append($menuitem);
		$menuitem->signal_connect("activate", \&create_mount );
		$menuitem->show;
	}

	if ( -e "/mnt/cdrom/maps/" && -e "/mnt/cdrom/software/" ) {
		$in_dir = "/mnt/cdrom";
		$in_method = "cdrom"; 
	} elsif ( -e "/tmp/install/software/RedHat") {
		$in_method = "cdrom"; 
	} else {
		$MethodButton = create_standard_button( "$words{Choose_Method}" ,
			$box2, 1, 1, 0, \&create_method );
	}
	$PackagesButton = create_standard_button( "$words{Choose_Packages}" , 
			$box2, 1, 1, 0, \&choose_packages );
	$PasswordButton = create_standard_button( "$words{Enter_Password}" , $box2, 1, 1, 0, \&create_passwd );
	
	$LinuxConfButton = create_standard_button( "$words{Post_Install}" , $box2, 1, 1, 0, sub {
		print "Should run the Linux Configuration things here.\n";
		my $tmp = "";
		if( -e "/live/lib/" ) {
			$tmp = "/live/setroot.sh";
			system "mount -t proc /proc $out_dir/proc";
		}
		system "$tmp /usr/X11R6/lib/xinstaller/post_install_options.pl &";
	} );
	
	if( -e "/live/lib/" ) { 
		print "hide buttons\n";
		$PackagesButton->set_sensitive(0);
		$PasswordButton->set_sensitive(0);
		$LinuxConfButton->set_sensitive(0);
	}
	

#	$button = create_standard_button( $words{Language}, $box2, 1, 1, 0, \&choose_language );

	$box2 = my_separator($box1);
	
	if( -e "/live/lib/" ) {
		$button = create_standard_button( $words{Reboot} , $box2, 1, 1, 0, \&do_exit );
	} else {
		$button = create_standard_button( $words{Quit}, $box2, 1, 1, 0, \&do_exit );
	}

	$menuitem = new Gtk::MenuItem( $words{Quit} );
	$menu->append($menuitem);
	$menuitem->signal_connect("activate", sub {
		Gtk->exit(0);
	} );
	$menuitem->show;

}

sub change_font {
	my( $StandardText, $FontSelector );
	$StandardText = new Gtk::Text(undef,undef);
	$FontSelector  = new Gtk::FontSelectionDialog "Font Selection Dialog";
	my $newFont = $_[0];
	if( ! defined $newFont ) {
		print "Setting font to lucida medium\n";
		# $FontSelector->set_font_name( "-misc-fixed-medium-r-semicondensed-*-13-*-*-*-c-*-iso8859-8" );
		# $FontSelector->set_font_name( "-b&h-lucida-medium-r-normal-sans-12-*-72-72-p-*-*-1" );
		$FontSelector->set_font_name( "-b&h-lucida-medium-r-normal-sans-12-120-75-75-p-71-iso8859-1" );
	} else {
		print "Setting font to $newFont\n";
		$FontSelector->set_font_name( $newFont );
	}
	$CurrentFont = $FontSelector->get_font;
	# print "got font $CurrentFont\n";
	$StandardText->style->font($CurrentFont);
	# print "set font to $CurrentFont\n";
}

sub choose_language {
	my( $box1, $label, $language);
	create_standard_window( $language_window, 260, 20, -1, -1, $words{Choose_Language} );
	$box1 = create_standard_vbox( 0 );
	$label = create_standard_label( $words{Choose_Language} , $box1, 0, 0, 0 );

	foreach $language ( "Deutsch", "English", "Espaol", "Franais", "Italiano" , "Portugues", "Swedish" ) {
		create_standard_button( $language , $box1, 1, 1, 0, sub { 
			if( $language eq "Japanese" ) {
				change_font "-jis-fixed-medium-r-normal-*-16-*-*-*-c-*-jisx0208.1983-0";
			} else {
				change_font();
			}
			print "Choose $language\n";
			$ChangeLanguage = TRUE;
			make_word_hash( $language );
			create_main_window;
			create_main_window;
			$language_window->destroy;
			$ChangeLanguage = FALSE;
		} );
	}
	create_standard_button( "Request for help" , $box1, 1, 1, 0, sub { 
		create_text_window( 150, 20, 375, 200, 
			"Request for Help", $words{Close}, $words{Request_for_Help}, "note");
	} );
}

sub make_word_hash {
	my( $entry, $key, @stuff );
	print "start make_word_hash\n";
	if( -e "/usr/X11R6/lib/xinstaller/$_[0]" ) {
		open( WORDS , "/usr/X11R6/lib/xinstaller/$_[0]" );
	} elsif ( -e "/root/bin/$_[0]" ) {
		open( WORDS , "/root/bin/$_[0]" );
	}
	while( <WORDS> ) {
		chop $_;
		if( $_ eq "" ) { next; };
		@stuff = split( /	/ , $_ );
		if( defined $stuff[1] ) {
			$words{ $stuff[0] } = pop( @stuff );
			next;
		}
		$entry = $_;
		undef $words{ $entry };
		while( <WORDS> ) {
			chop $_;
			if( $_ eq "end" ) { 
				chop $words{ $entry };
				last;
			}
			$words{ $entry } .= "$_\n";
#			print "$_\n";
		}
	}
	close( WORDS );

#	foreach $key ( keys( %words ) ) { print "$key\n"; }
}

sub check_arch {
	my(@tmp_input);

	open( CPU , "/proc/cpuinfo" );
	while( <CPU> ) {
		chop( $_ );
		if( $_ !~ /^machine/ ) { 
			next; 
		}
		@tmp_input = split(/:/);
		if ($tmp_input[1] =~ /PReP/) {
			close(CPU);
			return 1;
		}
	}
	close(CPU);
	return 0;
}

$ENV{PATH} = "$ENV{PATH}:/sbin:/usr/sbin";    #regular users dont have pdisk

$prep_install = check_arch();
if ($prep_install) {
	print "Looks like a PReP install\n";
} else {
	print "Not a PReP install\n";
}

if ( -f "/tmp/English" ) {
	make_word_hash( "English" );
} else {
	make_word_hash( "Japanese" );
}

if( -e "/live/lib/" ) {
	system( "killall -9 xmessage >/dev/null 2>&1" );
}

if ( -f "/tmp/English" ) {
	change_font();
} else {
	change_font( "-alias-fixed-medium-r-normal-*-12-*-*-*-*-*-*-*" );
}

# prepare /etc/dhcpc directory
if (! -e "/etc/dhcpc") {
	system( "mkdir /etc/dhcpc" );
}

# set Japanese locale
if (! -f "/tmp/English" ) {
	$ENV{'LANG'} = "ja_JP.ujis";
	$ENV{'LANGUAGE'} = "ja";
	Gtk->set_locale();
}

create_main_window;

if ( -e "/live/lib" ) {
	create_splash_window;
}

system ("touch /tmp/install.run");

main Gtk;
