#!/bin/bash

###################################################################################
# Copyleft 2007-2008 Peter Garrett and Karl Goetz
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
####################################################################################
# Enable debugging
# set -vex

# Might as well make it look pretty... P.G.
# Comments will lessen as development proceeds! P.G.
# Last edit by Peter Garrett: 2008-04-21

# Colours: this will be sourced from f-colours in the final version, 
# so all this cruft disappears ;) P.G. 2007-12-20

###### Start of removable cruft ######

# Foreground colours

white ()   { printf "\E[37m" ; }
black ()   { printf "\E[30m" ; }
green ()   { printf "\E[32m" ; }
magenta () { printf "\E[35m" ; }
blue ()    { printf "\E[34m" ; }
yellow ()  { printf "\E[33m" ; }
red ()     { printf "\E[31m" ; }
cyan ()    { printf "\E[36m" ; }

bold ()    { printf "\E[1m"  ; }
unbold ()  { printf "\E[0m"  ; }

# Background colours

bblack ()   { printf "\E[40m" ; }
bred ()     { printf "\E[41m" ; }
bgreen ()   { printf "\E[42m" ; }
byellow ()  { printf "\E[43m" ; }
bblue ()    { printf "\E[44m" ; }
bmagenta () { printf "\E[45m" ; }
bcyan ()    { printf "\E[46m" ; }
bwhite ()   { printf "\E[47m" ; }

###### End of removable cruft  ######

NAME=inx
export LC_ALL=C # Stops Perl complaining re: locale ? 080422 P.G.

figright ()
	{
	figlet "> > > > > >            inXtaller"
	}
	
figleft ()
	{
	figlet inXtaller
	}

# One way to see if running this makes sense...	P.G.
	if ! [ $(uname -n) = $NAME ] ; then
		clear ; echo
		echo -e "\nThis script needs to be run from a $NAME Live CD system              "
		echo -e "You seem to be running it from somewhere else... This won't work :-)\n"
		echo -e "Exiting the INX installer...                                        \n"
		exit 1
	fi


# Dire warnings precede the pretty stuff...
	clear
	echo -e "\nThis installer wants a single hard drive without existing partitions,"
	echo -e " and formats the whole thing.\n"
	echo "You have been warned... Proceed only if you understand what this means ! "
	echo -e "Go ahead? [default is \"no\"] [y/n]\n"
	read -s -n 1 DIRE_WARNING_DECISION
	case $DIRE_WARNING_DECISION in
		y|Y)
		echo -e "\nO.K. - going ahead with the inxtaller...\n"
		sleep 2 
		;;
		*)
		echo -e "You didn't say \"y\" for yes, so I'm exiting now...\n"
		exit 0
		;;
	esac

	# Enforce a black background, to make the colours visible,
	# in case the user has done something creative ;)
	bblack ; clear ; echo
	bold ; yellow
		figright
		echo

prepare ()
	{		
	# Set the tty not to blank - people get worried if installers blank in the midst of an install.
	# This seems to actually work. P.G.
	setterm -blank 0

		
	# Make sure /mnt is not in use - we don't want to discover this half way through
	if grep /mnt /etc/mtab > /dev/null 2>&1 ; then
	yellow
		echo -e "\n/mnt seems to be in use."
		echo    "You need to unmount /mnt - the installer uses it."
		echo -e "Exiting the INX installer...\n"
		sleep 7
		exit 1
	fi
	
	# Check if we are running as root: else nothing will happen... P.G.

	if [ $(id -u) -ne 0 ] ; then
	bred ; yellow
		cat << EOROOT

		This install script must be run as root.   
		You are running it as $USER.               
		Please run " sudo $0 "    
					
		Exiting the INX installer...               

EOROOT
	unbold
				exit  1
	fi
		
# Some variables
# Ask the user awkward personal questions... ;-) 

	settings ()
		{	
		green
			printf "You have set:" ; white ; printf "\t\t\t$CHOICE\n"
		yellow
			echo -e "Is that OK ? Just hit <enter> if yes, otherwise type \"n\"\n"
		white
			read -s -n 1 CONFIRM
			case $CONFIRM in
				n | N)
					$HERE
					;;
				
				*)
					#Let's move on then...
					:
					;;
			esac
		}
		
	setnames ()
		{
		yellow ; bold
			echo -e "Welcome to the INX installer!\n"
		green
			echo -e "The first step is to choose your user name for the system you are installing."
			echo -e "Choose a user name in lower case - for instance \"arthur\" or \"adent\"\n"
		
			username ()
				{
				HERE=username
				yellow
					printf "Type your chosen user name :    "
				white
					read FIRST_USER
				CHOICE=$FIRST_USER
					echo
				settings
				}
			username
		
		green
			echo -e "Think up a name for your new system. Preferably, choose something short." 
			echo -e "One word again, lower case. You can make this anything you like...\n"
			
			hostname ()
				{
				HERE=hostname
				yellow
					printf "Type your new hostname here:    " 
				white
					read NEW_HOSTNAME
				CHOICE=$NEW_HOSTNAME
					echo
				settings
				}
			hostname
		
		}
		
	setnames
	
	green
		printf "\nOK - your settings look like this: " ; white ; printf " $FIRST_USER@$NEW_HOSTNAME\n"
	green 
		echo -e "You will be asked for a password later, during the post-install configuration.\n"
	yellow
		echo -e "Hit any key to continue with the installation.\n"
	
		read -s -n 1	
	green
		echo -e "\nChecking some needed installation variables..."
		sleep 3
	
# This is the whole drive ( e.g. /dev/sda ). Assuming there's only one, I suppose...
# You are right that this point needs attention! Maybe we can offer a choice? MBR issues too... P.G.
# Some clever fellow decided to change the output of fdisk..  work-around P.G. 080421

	DRIVE=$(sudo fdisk -l | grep Disk | grep -v identifier | awk '{print $2}' | cut -d':' -f1)

# Partitions thereon. Sorry Karl, couldn't get sfdisk to behave with ?da1 as / - this works for now
		SYSTEM="$DRIVE"2
		SWAP="$DRIVE"1

# Check for existing drives and installations by counting fdisk's output.
		FILESYSTEM_CHECK=$(fdisk -l | grep -c /dev )

# This is cleaner? Gives a nice integer value in MB...
# Yes, much nicer. kk
		if [ $(lsb_release -sc) = hardy ] ; then
			DRIVE_TOTAL_SIZE=$(sfdisk -uM -s $DRIVE | awk '{print $2}') # This is on hardy - the format has changed
		else
			DRIVE_TOTAL_SIZE=$(sfdisk -uM -s $DRIVE) # feisty - not sure about gutsy
		fi
		
		if [ $DRIVE_TOTAL_SIZE -lt 1000000 ] ; then 
		bred ; yellow ; clear
			printf "\n\n\n\n\n"
			echo -e "\n1000MB is pretty much the lower limit for a practical install..."
			echo "The installed system without additions is about 500MB, plus 256MB for swap," 
			echo "and you need space for package updates, including a new kernel. You have only"
			echo ""$DRIVE_TOTAL_SIZE"MB available. I think you need a bigger hard drive."
			echo -e "\nHit any key to exit the INX installer...\n"
				read
			echo -e "\nReturning you to the main INX menu."
			sleep 3
			exit 1
		fi
# In MB
# This is perhaps redundant, unless we get fancy about swap size. Maybe check for < 64MB RAM ?
# On the other hand, I doubt that INX Live would boot with less than about 96MB. (doesn't in qemu, anyway)
		AVAILABLE_RAM=$(free -m | grep Mem | awk '{print $2}')
		
# Arbitrary, but I don't think we need to be elegant here (?) Shouldn't need much swap anyway?
# If we want to get fancy we can add in some multiple of $AVAILABLE_RAM instead , with alternatives accordingly P.G.
	if [ $DRIVE_TOTAL_SIZE -lt 4000000 ] ; then
		SWAP_SIZE=256
	else
		SWAP_SIZE=512
	fi
		
	if [ $AVAILABLE_RAM -lt 96 ] ; then
		bred ; yellow
		echo -e "\nYou seem to have only "$AVAILABLE_RAM"MB RAM. This could be a tight squeeze.\n"
		sleep 5
		unbold
	fi

# File system stuff
		EXT3=mkfs.ext3
		# If someone works out a USB install, we might need a *shudder* "FAT" partition variable? P.G. 
		# (cross-platform storage, and all that)

	}

sanity-checks ()
	{
	# Sanity. This part just checks for obvious bloopers. Needs additions, not sure what yet.. P.G.
	bblack ; clear
	bold ; green ; figleft
		echo ; bred ; yellow
		echo "The INX installer wipes your hard drive before installing.                      "
		echo "Please save any data before continuing. Any existing install will be blown away!"
		
		if [ $FILESYSTEM_CHECK -gt 1 ] ; then
		bblack ; bold ; green
			echo "You seem to have some existing filesystem drives or partitions.         "
			echo "Checking...                                                             "
			echo
		yellow 
				fdisk -l | grep /dev 
		bblack
			echo 
		bred
			echo "If you proceed you will lose all data on existing devices.                      "
	# On the target drive at least. Multiple drive issue again. P.G.
		fi
			
			drivecheck ()
					{
					bblack
					echo
					white
					echo
					echo "Proceed? (yes|no)"
					echo
						read DEEP_BREATH
						case $DEEP_BREATH in
							N | n | no)
							green
							echo -e "\nOK\t\tINX installer exiting...\n"
							sleep 3
							exit
							;;
							Y | y | yes)
							# Let's move along then...
################ UNCOMMENT NEXT LINE TO AVOID DISASTERS, IF TESTING AS ROOT AND NOT IN QEMU  ETC. ###################
#							exit 1 # just in case, while testing  P.G.
							green
							echo -e "Partitioning, please wait..\n"
							;;
							*)
							yellow
							echo "Please type \"yes\" or \"no\""
							drivecheck
							;;
						esac
					}
			drivecheck
		
	}
		
	# We probably need incantations here to sort out the "multiple drives" issue P.G.

partition ()
	{
	# P.G.
	# "partition" does the deep magic required to set up two partitions, '/' and swap ;)
		
	# parted seemed to work fine, but fdisk and cfdisk complain about the actual partitions it makes. Looks bad.

	# Wish there was a "Linux" or "GNU" label - having "msdos" in my script makes me feel dirty. ;) P.G.
	
	# Turn any existing swap off first, or sfdisk will complain. sfdisk likes to complain...
	green
		echo -e "Checking for active swap, if any, on $DRIVE ...\n"
		swapoff -a
		echo -e "Making a valid label...\n"
		parted --script $DRIVE mklabel msdos > /dev/null 2>&1

	# Added 20-12-2007 P.G.
	# Calculate how much to leave at the end of $DRIVE for swap, 
	# then make two primaries /dev/?da1 (Linux), /dev/?da2 (Swap)
		ROOT_PART_SIZE=$(expr "$DRIVE_TOTAL_SIZE" '-' "$SWAP_SIZE") # needs checking - sfdisk hates this. P.G.
		
	# Do the partitions: use MB as per variables $DRIVE_TOTAL_SIZE , $SWAP_SIZE
	# Assuming this works, we probably want to send the final output to /dev/null and put in
	# something prettier and less confronting for the user to read. P.G.
		
	# sfdisk doesn't like $ROOT_PART_SIZE , so I'm doing this backwards for the moment. P.G. 2007-12-23
	# sfdisk reports all kinds of stuff that the user probably doesn't need to see...
	
echo -e "Partitioning $DRIVE ...\n"
sfdisk -uM $DRIVE > /dev/null 2>&1 << EOF
,$SWAP_SIZE,S
,,L
EOF

# Also, sfdisk is very picky, and claims we are feeding it rubbish input... not yet sure what the issue is. P.G.

# Check up on sfdisk, since we told it to shut up
if [ $? -ne 0 ] ; then
	echo -e "\nOops, looks like partitioning $DRIVE failed, sorry. Exiting.\n"
	exit 1
else
	yellow ; bred ; bold
	echo -e "$DRIVE now partitioned with a swap partition on $SWAP , ext3 partition on $SYSTEM .\n"
fi
	}

format ()
	{
	echo
	yellow ; bred ; bold
	# "format" creates swap and the ext3 / file system.
	echo -e "Go ahead and format swap on $SWAP and the INX filesystem on $SYSTEM ? [yes/no]\n"
	bblack ; white
	read HERE_WE_GO
		case $HERE_WE_GO in

			N | n | no)
			echo ; white
			echo -e "\nOK - exiting the install script. You now have *partitions*, but no filesystems"\!"\n"
			sleep 3
			exit
			;;

			Y | y | yes)
			echo -e "\nFormatting partitions... please wait.\n"
	# Some indication of progress might be nice... takes a few seconds per GB in qemu.
	# Also possibly silence the output, and substitute, in pretty colours ;p  P.G
	# format partitions
			$EXT3 $SYSTEM > /dev/null 2>&1 &
			
                           green                           
                           while test $(pidof $EXT3)   
                           do printf ' *' && sleep .1 
                           done 
                           
                           bred ; yellow
                           echo -e "\nFormat of $SYSTEM complete."
                           echo -e "Making swap...             \n"   
                           bblack ; white ; sleep 3
                           
			mkswap $SWAP # This happens fast, so skipping the pretty asterisks ;p
			;;

			*)
			echo -e "\nPlease type yes or no"
			format
			;;
		esac

	}
	

copy ()
	{
	
	# This works - the problem was getting grub to install. Once that happens, it boots... 2007-12-26
	green ; bold ; bblack ; clear 
	figleft
	yellow
	printf "\n\n\n"
	echo -e "This is the actual install - it may take a long time, depending on the speed of your machine.\n"
	echo -e "If the display blanks during this operation, just hit a key to see it again.\n\n\n"
	echo -e "You will see a lot of text scroll by, rather quickly. Do not be alarmed, this tells you that"
	echo -e "it's working"\!"\n\n\n\n"
	
	bred
	echo -e "Here we go... Hit any key to continue...\n"
	bblack ; green ; bold
		read -s -n 1
		mount $SYSTEM /mnt
	# With minimal RAM like 128 MB, having swap for the copy step is crucial - it falls over without it.
		swapon $SWAP 
	
		rsync -av /rofs/ /mnt/ # Currently a scary scroll-by experience :) 
			       # You do specify -v :) kk 
			       # Yes, I needed to know what was happening. Without -v , Tridge is silent. :) P.G.
			       
	bred ; yellow
	echo -e "\nThe system has been installed to $SYSTEM . We will now configure necessary files.\n"
	echo -e "Hit any key to continue...\n" # I think a stop here is A Good Thing, to reassure $user.
	bblack ; white ; bold
		read -s -n 1
		clear
	}


missing ()
	{
	bblack ; bold ; cyan
	
		echo "LANG=C" >> /mnt/etc/environment  
		
	# Copy some important files over, and edit /etc/hosts
		echo -e "\nCopying /etc/network/interfaces , /etc/hosts , /etc/hostname\n"
		sleep 2
		cp -a /etc/network/interfaces /mnt/etc/network/interfaces
		cp -a /etc/hosts /mnt/etc/hosts 
		echo "$NEW_HOSTNAME" > /mnt/etc/hostname 
		sed -i "s/inx/$NEW_HOSTNAME/g" /mnt/etc/hosts
		
	# Less important, but we want to clarify...
		sed -i 's/Ubuntu/INX - (Ubuntu)/g' /mnt/etc/issue
		
	# Very basic fstab: possibly add floppy and cdrom entries...
		echo -e "\nSetting up /etc/fstab file system table...\n"
		sleep 2
cat << EOF > /mnt/etc/fstab

$SYSTEM		/		ext3		defaults,errors=remount-ro	0	1
proc		/proc		proc		defaults			0	0
$SWAP		none		swap		sw				0	0

EOF

	# Grub can't find what it needs, so we give it a kick in the pants. P.G.
		echo -e "\nCreating necessary files for the grub bootloader.\n"
		sleep 2
		mkdir /mnt/boot/grub
		cp -a /mnt/usr/lib/grub/i386-pc/* /mnt/boot/grub/
		
	# We apparently need to make a device.map too. 
		echo "(hd0)   $DRIVE" > /mnt/boot/grub/device.map
		
	# Not certain this is necessary, but it ain't broke, so... P.G.
		echo -e "\nMounting /dev/ and /proc... mount --bind \n" 
		mount --bind /proc /mnt/proc
		mount --bind /dev /mnt/dev
		
		yellow
		echo -e "\nInstalling the grub bootloader... Please wait... This can take a few seconds... \n"
		cyan
	# grub-install /dev/?da <-- doesn't work. We need to dump stuff on the MBR ... and grub can't find it.
	# So we give grub another heartfelt kick... 
grub --batch << EOF 2> /dev/null 
root (hd0,1)
setup (hd0)
quit
EOF

# Not sure about the "if" below - possibly grub will exit with a non-zero return, but still work ("not fatal")
#if [ $? -ne 0 ] ; then
#	echo -e "\nGrub install failed. You will not be able to boot your system directly."
#	echo -e "Exiting the INX installer. Sorry, we tried..."
#	exit 1
#fi
	# Change the titles in the update-grub script so our kernel choices will say "INX"...
	echo -e "\nSetting INX bootloader titles..."
		sed -i 's/title="Ubuntu"/title="INX"/g' /mnt/usr/sbin/update-grub # Does nothing on hardy: script has changed

	# And update-grub
	# Don't bother the user with questions and output: this seems to work, to create a menu.lst 
	echo -e "\nCreating bootloader menu file..."
		chroot /mnt update-grub -y  > /dev/null 2>&1
		
	# Work around the "savedefault" not working (error 15 is the result when it craps out) 
	echo -e "\nSetting default... "
		chroot /mnt grub-set-default default > /dev/null 2>&1
		
	# Edit vga setting in defoptions.
	# Replace defoptions line, removing 'quiet splash' and adding vga=788
	echo -e "\nEnabling framebuffer... "
		# vga=788 is safer (16 bit) - for example, in qemu this fixes weird colour behaviour.
		sed -i 's/# defoptions=quiet splash/# defoptions=vga=788/g' /mnt/boot/grub/menu.lst
		 
	# Pretty colours ;-)
	echo -e "\nSetting up colour bootloader menu.."
		sed -i 's_#color cyan/blue white/blue_color yellow/green white/green_g' /mnt/boot/grub/menu.lst
	# Don't hide the grub menu by default. (default timeout is only 3 seconds)
		sed -i 's/hiddenmenu/#hiddenmenu/g' /mnt/boot/grub/menu.lst
		
		
	# We need to re-run update-grub to make this stick - this enables the framebuffer at vga=788 on boot.
	echo -e "\nUpdating framebuffer settings..."
		chroot /mnt update-grub -y > /dev/null 2>&1
			
	# Re-enable cron startup: - disabled on the feisty live CD, because it tried to run "cron daily" ;) P.G.
		chroot /mnt update-rc.d cron defaults > /dev/null 2>&1    # The user doesn't need to see this ;p P.G.
		
	# Probable addition: Set xlinks2 to use the "fb" driver rather than trying to use directfb,
	# which requires either setuid root, or multiple permissions-editing gymnastics with various device files.
	# Means editing the wrapper in /usr/bin/xlinks2. Not quite sure what to do about "links2 -g" yet... P.G.
	
	}

check ()
	{
	# New screen
	bblack ; yellow ; bold ; clear 
		figleft
		
	# 'check' makes sure everything is where it should be.
	# i.e. make sure the user does not end up with a broken system
		
	green
	echo -e "\nYour user \"$FIRST_USER\" will need a password to log in to the new INX system.            "
	echo -e "Please answer as prompted in this step: your password will not show on screen as you type it."
	echo -e "Choose a strong password with at least eight characters, and a mix of numbers and alphabet.\n"
	echo -e "There may be a warning message about locale - this is not fatal"\!"\n"
	yellow ; bred	
	echo "Hit any key to set up your user account and password."
	bblack
		read -s -n 1
		
	# Set up default user, add that user to the right groups, edit /etc/sudoers etc. etc.
	# Probably just leave this to the default utility. I usually hit enter, enter, enter, enter for user info ;-)
	# $FIRST_USER is automatically added to the 'fuse' group, since it is so configured in /etc/adduser.conf
	
		clear ; yellow ; bold
		figleft
		green
		
		echo -e "\nSetting up user account for $FIRST_USER ...\n"
		white
			chroot /mnt adduser $FIRST_USER 
		green
		echo -e "\nOK, adding $FIRST_USER to default groups...\n"
		sleep 3
		
	# Group "admin" doesn't exist - add it, with gid 116 ( consistency with Ubuntu's sudo method)
			chroot /mnt addgroup --gid 116 admin > /dev/null 2>&1
		
	# Now loop through the groups... 
		white
		for NEW_GROUPS in dialout fuse cdrom video audio admin plugdev floppy dip adm # Check this for hardy P.G. 080418
			do 
			# A simple export LC_ALL=C might do the trick, instead of gagging perl ( not implemented yet ) P.G. 080418
			chroot /mnt adduser $FIRST_USER $NEW_GROUPS 2> /dev/null # Gags Perl... what a relief... P.G.
		done		
		
	# Put the admin group in /etc/sudoers.
		green
		echo -e "\nMaking members of the \"admin\" group authorised \"sudoers\"...\n"
		white
			echo "# Members of the admin group may gain root privileges." >> /mnt/etc/sudoers
			echo "%admin ALL=(ALL) ALL" >> /mnt/etc/sudoers
		
	# OK - we now have a sudoer, with luck. So lock root...
			chroot /mnt passwd -l root > /dev/null 2>&1
		
	# Lecture on sudo in yellow and red :-)
			bred ; yellow ; bold ; echo
			cat << EOF		                                                         
For administrative tasks, the password you have just set for $FIRST_USER 
is what the system will expect when you are prompted for a password.                 
Make sure you remember that password!                                    
                                                                         
Hit any key to continue with the installation...                         
		                                                         
EOF
		read -s -n 1

	# Do the usual updates/upgrades... Check for internet connectivity first. e.g. dialup users etc.
		bblack ; yellow ; bold
		echo -e "\n\n\nYou can check for and install security fixes and updates to the system now, "
		echo -e "or skip this step and do it yourself later. Update now? (Recommended) (y/n)"
		white
	
	updates ()
		{
		read -s -n 1 UPDATES
		
			case $UPDATES in
			
				n | N )
					# Well, OK. Maybe $USER knows there is no Internet connection... 
					cyan ; bold
					echo -e "\nInstallation is complete, except for security and update fixes.\n"
					sleep 4
				;;
				
				y | Y )
					# links2 gives up after some seconds if it can't connect, and returns an error.
					echo -e "\nChecking for Internet access to the update server... Please wait."
					if links2 -dump http://archive.ubuntu.com > /dev/null ; then 
					
							cyan ; bold
							echo -e "\nUpdating package lists... please wait.\n"
							green
								chroot /mnt apt-get update  2> /dev/null
							
					# Check exit code : '2> /dev/null' is a kludge around locales issue. P.G.
						aptcheck ()
							{
							if [ $? -ne 0 ] ; then
								bred ; yellow ; bold
								printf "\n"
							echo "Oops, apt-get had a problem... try updating later."
							echo "Your system should still boot. This is not fatal..."
								unbold
								sleep 5
								success
							fi
							}
								aptcheck
							
							cyan
							echo -e "Updating software... This may take some time.\n"
							echo -e "You can safely answer \"yes\" to the updates...\n"
								green
								chroot /mnt apt-get upgrade 2> /dev/null 
								aptcheck
							cyan
							# Save some disc space
							echo -e "\nCleaning package cache to save disc space...\n"
								apt-get clean
								sleep 1
							echo -e "\nSoftware updates completed... install complete"\!""
								sleep 3
									
					# Might need apt-get dist-upgrade for the kernel, though... doubles download :(
		
					else
						bold ; green ; clear
						figright
						white
cat <<EOINTERNET

	You seem to be installing without a working internet connection, or the 
	update server is down. This is OK, but you will need to run
		
	"sudo aptitude update && sudo aptitude upgrade" 
		
	from the new INX hard drive install, as soon as possible, to ensure that 
	your system has security and bug-fix updates in place. 
		
	If you are using dialup, or direct DSL with PPPoE, INX has connection 
	setup entries under the "Net and Web" menu. 
		
	If you have a router, INX should automatically connect you, using dhcp.
	
	Press any key to continue without running these updates. 
	
	Just remember to do them, as above!
		
EOINTERNET

						read -s -n 1
					fi
				;;
				
				*)
					yellow
					echo -e "\nPlease type y for \"yes\" or n for \"no\".\n"
					white
					updates
				;;
			esac
			
		}
	updates
		
	}

	# Congratulations, you just dumped INX on your $SYSTEM... ;p If you are incredibly lucky, it might even boot!
	# Actually I think I will precede this with some simple instructions ( log in, differences etc.)
success ()
	{
	clear
                printf "\n\n\n\n\n\n"
                bold ; yellow
                figlet -c "    InXtalled    !"
                green ; bold
                # Know an elegant way to do spaces with echo -e? This stuff is about aesthetic layout ;p
        	echo -e "\n\n\n\n\t     Installation of INX to your hard drive is now complete.\n"
        	echo -e  "\t    Please quit the INX live session, remove the CD and reboot"\!"\n\n\n\n"
        	yellow
		echo -e "\tShut down this INX live session and try your new hard drive install? [y|n]\n\t\t\t\t"
	
		read -s -n 1 REBOOT
		
			case $REBOOT in
				y | Y)
					yellow
					echo -e "\n\t\t\tShutting down now! Good luck!"
					sleep 3
					shutdown -h now
					;;
				n | N)
					green
					echo -e "\n\t\t  OK, returning you to the main INX menu."
					sleep 3
					exec menu
					;;
				*)
					echo -e "\n\t\t\tPlease type y for \"yes\" or n for \"no\"\n"
					sleep 2
					success
					;;
			esac
	}

main ()
	{
	prepare
	sanity-checks
	partition
	format
	copy
	missing
	check
	sed -i 's/Ubuntu/INX/g' /mnt/boot/grub/menu.lst # This is a kludge - probably won't survive a kernel update
	chroot /mnt sync  # just belt-and-braces, because this is a "lazy umount" - shouldn't actually matter. P.G.
	umount -l /mnt/proc /mnt/dev /mnt
	success
	}

main



