~inx-devel/inx/karlswhackyideas

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
#!/bin/bash 

####################################################################################
# Script to build an "INX is Not X" live CD. Uses debootstrap, casper, squashfs etc.
# Copyright (C) 2008 Peter Garrett				inx-one [ nospam at ] optusnet.com.au
# Portions copyright (C) 2008 Karl Goetz		karl@kgoetz.id.au
# Acknowledgements to: Dan Mazzei, 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.
####################################################################################

#set -ex   # debug, exit on error: un-comment only if you know how to fix things :)
#set -vex  # absurdly verbose debug. Lots of scrolling... See also above ;)

# Colours, inevitably... and yes, I know I could use variables. I always forget to put in the $ sign :(
white ()	{ printf "\E[37m" ; }
green ()	{ printf "\E[32m" ; }
yellow ()	{ printf "\E[33m" ; }
red ()		{ printf "\E[31m" ; }
bblack ()	{ printf "\E[40m" ; }
bold ()		{ printf "\E[1m"  ; }

# The black terminal marks the script 'in action'
bblack ; clear ; bold ; white 

if [ "$#" -ne 2 ] ; then
	cat << EOUSAGE
buildinx:

Usage: sudo $0 <suite_name> <mirror>

Examples:

sudo $0 gutsy archive.ubuntu.com
sudo $0 feisty au.archive.ubuntu.com

EOUSAGE
	exit 1
elif [ $(id -u) -ne 0 ] ; then
	echo -e "\nYou must run this script as root."
	echo -e "Please run \"sudo "$0"\"" 
	echo -e "Or become root before running "$0"\n"
	exit 1
fi

green ; echo -e "\nBuildinx up and running...\n" ; sleep 1 ; white

# Variables for version to build, repo mirror etc.

export DEBOOTSTRAP_LATEST=1.0.8	# As of writing: March 2008 - Edit as appropriate
export DEV=hardy				# Development version as at March 2008 - Edit as appropriate
export SUITE=$1
export MIRROR=$2           
export DISTRO=ubuntu			# Might eventually work to sub debian, not tried.
export MAIN=main
export CONTRIB=universe			# Using Debian terms - more generic.
export NONFREE=multiverse		# Well, quite few of these are "libre" IMO
export EXTRAS=""  				# For debian you would probably need at least "multimedia" 
export DEBOOTSTRAP_PACKAGE=debootstrap_"$DEBOOTSTRAP_LATEST"_all.deb
export WORK_DIR="$1"-inx
export LC_ALL=C
export INX_SITE=inx.maincontent.net
export INX_SITE_ALT=thoreauputic.boinc.ch
export INX_DIR=buildinx
export INX_EXTRAS="inx-extras"
export SUITE_SCRIPTS="$SUITE"-scripts.tar.gz

# Make a general directory to contain all the Buildinx cruft ;-)
if ! [ -d BuildInxWorkingDirectory ] ; then mkdir BuildInxWorkingDirectory ; fi
cd BuildInxWorkingDirectory

if [ ! -f .inx_tools_check ] ; then # To avoid constant checking on re-runs
	green ; echo -e "\nRoutine check for needed tools...\n"
	sleep 3
	if ! which apt-get ; then
		yellow ; echo -e "\nAaaargh! No apt-get!! Exiting.\n" ; white
		exit 1
	fi
	# Let apt do the work for us here...
		white
	if ! apt-get install squashfs-tools mkisofs initramfs-tools wget binutils netcat ; then
		# Fail gracefully
		yellow ; echo -e "\nApt was unable to install the tools needed to continue. Exiting...\n" ; white  
		exit 1
	fi

fi

touch .inx_tools_check

if ! [ -d "$INX_EXTRAS" ] ; then
	green ; echo -e "\nChecking site $INX_SITE for needed INX extras...\n" ; sleep 3 ; white
	if ! nc -w 2 -z $INX_SITE 80 ; then
		green ; echo -e "\n$INX_SITE seems to be down ... trying an alternative ...\n" ; sleep 3 ; white
		if nc -w 2 -z $INX_SITE_ALT 80 ; then
			INX_SITE=$INX_SITE_ALT
		else
			yellow ; echo -e "\nNo luck... $INX_SITE_ALT is down too! Please try again later. Exiting.\n" ; white
			exit 1
		fi
	fi
	# Get the tarball of needed extra INX files etc. This only happens once...
	wget --continue -T 5 "$INX_SITE"/"$INX_DIR"/buildinx-extras.tar \
	&& tar xvf buildinx-extras.tar && rm buildinx-extras.tar
	if [ $? -ne 0 ] ; then
	yellow ; echo -e "\nThere was a problem obtaining the needed extras... Exiting.\n" ; white
	exit 1
	fi
fi

# Check on-line status 
if ! nc -w 2 -z $MIRROR 80 ; then
	yellow
	echo -e "\nThe mirror address "$MIRROR" appears to be down, or not responding."
	echo -e "Try another mirror, check for errors, or re-run $0 later ... Exiting.\n"
	white
	exit 1
fi

# General hand-holding and warnings

if [ $SUITE != feisty ] && [ $SUITE != gutsy ] && [ $SUITE != hardy ] ; then
	echo -e "\nSo far this script builds feisty, gutsy or hardy INX versions."
	echo -e "$SUITE might build, but you would have to build manually, or hack the script. Sorry.\n"
	exit 1
fi

if [ $SUITE = feisty ] || [ $SUITE = gutsy ] && [ $(lsb_release -sc) = hardy ] ; then
	echo -e "\nThe feisty and gutsy versions of INX will not build successfully on Hardy, using this script."
	echo -e  "Since you are running Hardy, try building hardy-inx instead. Sorry.              Exiting...\n"
	exit 1
fi

warning ()
	{
	if [ "$SUITE" = "$DEV" ] ; then
		if ! [ -f .inx_dev ] ; then # Marker check
			bold ; yellow
			echo -e "\nYou have chosen to build INX from the development branch of Ubuntu."
			echo -e "The result might behave as expected... as in, *broken*. Continue? [y/n]\n"
			white
			risky ()
			{
			read -s -n 1 RISKY
			case $RISKY in
				n | N )
				echo -e "\nExiting now - maybe try the current Ubuntu version, instead...\n"
				exit 0
				;;
				y | Y )
				green ; echo -e "OK - don't say you weren't warned ;-)" ; white
				# Create a marker file so the risk-takers won't be nagged again...
				touch .inx_dev ; sleep 3
				;;
				*)
				echo -e "\nWe need a [y/n] ;-)."
				risky
				;;
			esac
			}
			risky
		fi
	fi
	
	if ! [ $(lsb_release -si) = "$DISTRO" 2> /dev/null ] ; then # Check that we are on Ubuntu
		yellow
		echo -e "\nThis script has only been tested on an Ubuntu system."
		echo -e "*Running* the script *probably* won't work on Debian, or other Debian derivatives.(Not tested)"
		echo -e "To *build* an INX-Debian or other-derivative, you would need to change the script."
		echo -e "Saying \"n\" for no here is the safe alternative, if you aren't sure..."
		echo -e "Go ahead and try anyway? [y/n]\n"
		white
		other ()
		{	
		read -s -n 1 GO
			case $GO in
				n | N)
				echo -e "OK -exiting now.\n"
				exit 0
				;;
				y | Y)
				echo -e "O.K. - Good luck!\n" ; sleep 3
				;;
				*)
				echo "We really need yes or no here :)"
				other
				;;
			esac
		}
		other
	fi

	# Check debootstrap version
	DEBOOTSTRAP_VERSION=$(debootstrap --version | awk '{print $2}')
	if [ "$DEBOOTSTRAP_VERSION" != "$DEBOOTSTRAP_LATEST" ] ; then
		green
		echo -e "\nYou need to install the most recent version of debootstrap:"
		echo -e "downloading & installing... Please wait.\n"
		white
		sleep 3

		wget --continue -T 5 http://"$MIRROR"/ubuntu/pool/main/d/debootstrap/$DEBOOTSTRAP_PACKAGE 
		dpkg -i $DEBOOTSTRAP_PACKAGE  # Shell script - only needs binutils. Deb only for now.
		if [ $? -ne 0 ] ; then
			yellow ; echo -e "\nOops! Unable to install the latest debootstrap... Exiting.\n" ; white
			exit 1
		fi
	fi
	}

debootstrapping ()
	{
	if ! [ -d "$WORK_DIR" ] ; then
		mkdir -p "$WORK_DIR"/{chroot,master}
		cd "$WORK_DIR"

		# Put isolinux and casper dirs in place, for the INX start screen, boot etc.
		tar -C master/ -xvzf ../"$INX_EXTRAS"/isolinux.tar.gz
		mkdir master/casper

		# Do the debootstrap in $WORK_DIR
		green
		echo -e "\nDownloading and installing a minimal bootstrap chroot. Please wait.\n"
		sleep 3
		white
		if ! debootstrap $SUITE ./chroot http://$MIRROR/$DISTRO ; then
			echo -e "\nDebootstrap failed... Cleaning up... exiting.\n"
			# Clean up
			cd .. ; rm -rf "$WORK_DIR"
			exit 1
		fi

		# Mount, edit ./chroot/etc/apt/sources.list, update apt list

		chroot ./chroot mount -t proc proc /proc
		chroot ./chroot mount -t sysfs sys /sys
		chroot ./chroot mount -t devpts devpts /dev/pts
		chroot ./chroot apt-get clean

		cat << EOS >> ./chroot/etc/apt/sources.list #debootstrap already placed a basic "$MAIN" line

# Lines below autogenerated by $0

deb http://$MIRROR/$DISTRO $SUITE $CONTRIB $NONFREE
deb http://$MIRROR/$DISTRO "$SUITE"-updates $MAIN $CONTRIB $NONFREE
deb http://$MIRROR/$DISTRO "$SUITE"-security $MAIN $CONTRIB $NONFREE
EOS

		# Install extra repositories if enabled
		if [[ -n $EXTRAS ]]; then echo "deb $PACKAGEMIRROR $EXTRAS" >> ./chroot/etc/apt/sources.list fi

		if ! chroot ./chroot apt-get update ; then
			echo -e "\nApt-get update in the chroot failed. Please check your mirror and network. Exiting...\n"
			exit 1
		fi

		if [ $SUITE = hardy ] ; then
			# Makes setting LANG easier. Whiptail is not installed early enough.
			chroot ./chroot apt-get install dialog 
		fi

		# Grab and install the lot.

		chroot ./chroot dpkg --set-selections < ../"$INX_EXTRAS"/"$SUITE"-selections
		yellow
		echo -e "\nThe next step is to retrieve and install necessary packages."
		echo -e "This requires 100 MB or so of downloading, and could take a while.\n"
		echo -e "You may be asked about kernel symlinks and locale. Say yes to the symlinks,"
		echo -e "and select only 'en' for the locale question, unless you want to experiment..."
		echo -e "The kernel configuration questions may ask if you \"Want to abort\" . Say no."
		echo -e "You probably want to leave the time zone as \"unknown\"\n"
		green
		echo -e "\nHit any key to continue. Apt will show a long list, then ask you if you want to proceed."
		echo -e "The answer is probably \"yes\", unless you plan to subvert the INX menus. ;-)"
		read -s -n 1
		white

		if ! chroot ./chroot apt-get dselect-upgrade ; then
			# Try to fix unconfigured packages - e.g. vim causes some issues with hardy
			chroot ./chroot aptitude -f install	# 'apt-get -f install' seems to fail here, though it isn't fatal.
			chroot ./chroot apt-get clean		#  We don't want cache bloating the final ISO
		else
			chroot ./chroot apt-get clean
		fi
	else
		cd "$WORK_DIR"
	fi

	if ! [ -f .scripts_installed ] ; then
		bold ; green ; echo -e "\nInstalling INX scripts in chroot/usr/local...\n" ; white ; sleep 4
		tar -C chroot/usr/ -xvzf ../"$INX_EXTRAS"/"$SUITE_SCRIPTS"
		touch .scripts_installed
	fi
	}

# This is where the fun starts... we get here if the working $SUITE dir has been set up.
##debug### Rewrite this, and use at crucial points in the flow. P.G.
choices ()
	{
	bblack ; clear ; green ; bold 
	echo -e "\nIf you are seeing this, you should have a working debootstrapped chroot."
	echo -e "Here you can choose what to do next...\n" ; yellow
	echo -e "Select by number... \"1\" is suggested, if you have no idea: - or just panic ;-)" ; green
	echo -e "1: Let the script complete a clone of INX for you.\n" ; yellow
	echo -e "Advanced:" ; green
	echo "2: Enter the chroot to customise your INX file system. 
	(add applications, edit configuration etc)." ; yellow
	echo -e "\nUltra Advanced :-) " ; red
	echo "3: Panic!" ; green
	echo -e "\n4: Exit buildinx. (You will need to know what to do next...)\n" ; white
		read -s -n 1 CHOICES
		case $CHOICES in
			1)
			 : # No op... next in "main ()" is "add_inx_examples ()"
			;;
			2)
			green ; echo -e "\nWhen you exit the chroot, you will come back to this menu." ; sleep 2
			tput sgr0 ; clear
			HOME=/root chroot ./chroot
			choices
			;;
			3)
			red ; echo -e "\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAARRRGH!!!!!!!!\n"
			sleep 2
			choices
			;;
			4)
			echo -e "\nOK - exiting now...\n" ; sleep 2
			if ! chroot ./chroot umount /proc /sys /dev/pts > /dev/null 2>&1 ; then
				# This is a bit brutal.
				chroot ./chroot umount -l /proc /sys /dev/pts > /dev/null 2>&1
			fi
			reset_and_exit
			;;
			*)
			echo -e "\nTry again... the idea is to *bang the rocks together*... ;-)"
			sleep 3
			choices
			;;
		esac
	}

add_inx_examples ()
	{
	# Check if example directories already exist from previous runs (do this bit, if not)
	if ! ls -ld chroot/usr/share/{video,graphics,example-content} ; then
		tar -C chroot/usr/share/ -xvzf ../"$INX_EXTRAS"/graphics.tar.gz
		tar -C chroot/usr/share/ -xvzf ../"$INX_EXTRAS"/video.tar.gz
		tar -C chroot/usr/share/ -xvzf ../"$INX_EXTRAS"/example-content.tar.gz
		if [ $? -ne 0 ] ; then echo -e "\nOops... exiting\n" ; exit 1 ; fi
	else
		bold ; green
		echo -e "\nYou seem to have the INX example directories set up already:"
		echo -e " moving on to the next step.\n"
		white
		sleep 4
	fi
	}

# Add scripts and tweak settings (/etc/skel , start-up hacks ... )
configure_inx ()
	{
	bold ; green
	echo -e "\nTweaking system settings..." ; sleep 2
	white
	if ! [ -d ./chroot/etc/skel/plait ] ; then
	# If /etc/skel/plait/ exists, we assume /etc/skel is populated... else...
		green
		echo -e "\nInstalling custom /etc/skel settings...\n" ; sleep 3
		white
		tar -C chroot/etc/ -xvzf ../"$INX_EXTRAS"/etc.skel.tar.gz
	fi

# These are the really fiddly bits :/

##### This 'if' section applies only for feisty and/or gutsy ###################################

	if [ $SUITE = feisty ] || [ $SUITE = gutsy ] ; then
#		##debug## ******************************************************************************
		# For some reason, Feisty and Gutsy insist on printing final startup messages
		# *after* autologin, thus making a mess of the initial INX screens. This tells the log_* messages to shut up.

#		* N.B. This is a horrible hack! If you know how to fix it *properly*, please mail me. P.G.
		green
		echo -e "\nFixing start-up scripts...\n" ; sleep 1
		white
		cp ../"$INX_EXTRAS"/{atd,gpm,cron,dbus,klogd,rc.local,skeleton,sysklogd} ./chroot/etc/init.d/
		cp ../"$INX_EXTRAS"/20hal ./chroot/etc/dbus-1/event.d/20hal

#		****************************************************************************************

		# Also add fuse group to the adduser configuration (Hardy does this by default).
		green
		echo -e "\nAdding default user to the fuse group - needed for sshfs" ; sleep 3
		white

		echo "EXTRA_GROUPS=fuse" >> ./chroot/etc/adduser.conf
		echo "ADD_EXTRA_GROUPS=1" >> ./chroot/etc/adduser.conf

		# Gutsy kernels fail the frame buffer test... this workaround seems to be O.K. though..
		if [ $SUITE = gutsy ] ; then
			green ; echo -e "\nReconfiguring frame buffer settings... This takes a while, please wait." ; white
			sleep 3
			# *Sigh*. This should *not* be necessary... see http://launchpad.net/bugs/129910 for the complete saga...
			echo "fbcon" >> ./chroot/etc/initramfs-tools/modules
			echo "vesafb" >> ./chroot/etc/initramfs-tools/modules
			sed -i 's/blacklist vesafb/# blacklist vesafb/g' ./chroot/etc/modprobe.d/blacklist-framebuffer
			chroot ./chroot update-initramfs -u
		fi

	fi
#######################################################################################
	
	# The usbmount config needs additions to recognise and handle FAT usb file systems...
	if ! [ -f .usb ] ; then
		green ; echo -e "\nConfiguring usbmount...\n" ; white ; sleep 2
		sed -i 's/FILESYSTEMS="ext2 ext3"/FILESYSTEMS="ext2 ext3 vfat"/g' \
		./chroot/etc/usbmount/usbmount.conf
		sed -i 's/FS_MOUNTOPTIONS=""/FS_MOUNTOPTIONS="-fstype=vfat,gid=floppy,dmask=0007,fmask=0117"/g' \
		./chroot/etc/usbmount/usbmount.conf
		touch .usb
	fi

	if ! [ -f .general_tweaks ] ; then
		green ; echo -e "General tweaks for themes, media playing, etcetera..." ; sleep 2
		# Add greengold theme for MOC
		cp ../"$INX_EXTRAS"/moc-theme-inx ./chroot/usr/share/moc/themes/greengold
		# Green theme for irssi...
		mv chroot/usr/share/irssi/themes/default.theme chroot/usr/share/irssi/themes/blue.theme
		cp ../"$INX_EXTRAS"/default.theme chroot/usr/share/irssi/themes/default.theme
		# Switch mplayer to fbdev video, specify full screen by default (fbdev and fs are better in INX)
		sed -i 's/vo=xv/vo=fbdev/g' chroot/etc/mplayer/mplayer.conf
		sed -i 's/#fs=yes/fs=yes/g' chroot/etc/mplayer/mplayer.conf
		# Comment out ogg123 line in /etc/mailcap - ogg is not just audio!
		sed -i 's_application/ogg_#application/ogg_g' chroot/etc/mailcap
		echo 'application/ogg; playinx '%s'; test=test -z "$DISPLAY"; needsterminal' >> chroot/etc/mailcap
		echo 'application/x-ogg; playinx '%s'; test=test -z "$DISPLAY"; needsterminal' >> chroot/etc/mailcap
		touch .general_tweaks
	fi

# The following are idempotent. [ I've always wanted to use that word in a comment. ;-) ] P.G.

	# Run links2 -g / xlinks2  suid root: I *really* don't like this, but tweaking permissions
	# on various devices (/dev/fb0, /dev/tty0 and so forth) still fails for xlinks2 when
	# run from INX scripts. Total wedge is the result...  So far I have no idea why...
	chroot ./chroot chmod u+s /usr/bin/links2

	# Fix the xlinks2 wrapper - the 'exec' is left out (known unfixed bug)
	# This probably *ought* to be done with dpkg-divert or something... Also maybe try full path. Note to self P.G.
	echo '#!/bin/sh' > chroot/usr/bin/xlinks2
	echo 'exec links2 -g "$@"' >> chroot/usr/bin/xlinks2

	# Set the user and system name to "inx@inx".
	sed -i 's/ubuntu/inx/g' chroot/etc/casper.conf

	# Remove contents of these files, which are misleading for inx. Also makes starts a fraction quicker ;)
	echo "" > chroot/etc/motd
	echo "" > chroot/etc/motd.tail

	# Keep nano as default editor for now. Possible change to jed ? Needs INX script changes... P.G. 
	chroot ./chroot update-alternatives --set editor /bin/nano
	}

make_inx ()
	{
	yellow
	# If this is a re-run, there might have been a kernel upgrade. We don't *allow* more than one kernel... ;)
	if [ $(chroot ./chroot dpkg -l linux-image-2* | grep -c ^ii) -gt 1 ] ; then
		echo -e "\nYou appear to have more than one chroot kernel installed. This confuses matters, and takes CD space."
		echo -e "Please enter the chroot and remove redundant kernels with \"aptitude purge <kernel package name>\"..."
		echo -e "Hit any key to return to the menu.\n"
		read -s -n 1
		choices
	fi

	green
	echo -e "\nPutting the kernel files in place, and generating the compressed file system."
	echo -e "This will take some minutes, and show a *lot* of output on the screen - please wait...\n"
	sleep 3

	# Do the mkinitramfs in chroot to pick up casper config changes etc.
	echo -e "Regenerating initrd, and configuring initrd and kernel for isolinux/casper."
	echo -e "Nothing much will appear to happen for a moment or so, then all hell breaks loose ;-)\n"
	sleep 3

	LINUX_VERSION=$(ls ./chroot/boot/vmlinuz* | cut -d'-' -f1 --complement)
	chroot ./chroot mkinitramfs -o boot/initrd.gz $LINUX_VERSION
	# Get rid of any backup initrd image in chroot/boot - it just takes space, and does nothing.
	rm chroot/boot/initrd*.bak > /dev/null 2>&1

	# Copy the initrd and vmlinuz across.
	# Any extra vmlinuz* in chroot/boot has already been nuked, hopefully...
	mv chroot/boot/initrd.gz  master/casper/initrd.gz
	cp chroot/boot/vmlinuz* master/casper/vmlinuz

	# Check for existing filesystem.squashfs: - remove it, or everything goes pear-shaped.
	if [ -f master/casper/filesystem.squashfs ] ; then
		rm master/casper/filesystem.squashfs
	fi

	# Make *sure* nothing is mounted in the chroot, before making the squashfs!
	if ! chroot ./chroot umount /proc /sys /dev/pts > /dev/null 2>&1 ; then
		# This is a bit brutal. Once is not enough, apparently. There's probably a better way ;)
		chroot ./chroot umount -l /proc /sys /dev/pts > /dev/null 2>&1
	fi

	# OK, time to rock and roll...
	yellow ; echo -e "\nHold on to your hat... here we go!"
	green ; echo -e "Building compressed file system. Please wait...\n" ; sleep 2
	white
	mksquashfs chroot master/casper/filesystem.squashfs -info

	# Check for existing ISO from previous run...
	if [ -f "$SUITE"-inx.iso ] ; then
		yellow
		echo -e "\nYou have a file "$SUITE"-inx.iso already."
		echo -e "Moving it to $(date +%y%m%d-%H:%M)."$SUITE"-inx.iso as a time-stamped version."
		green
		mv "$SUITE"-inx.iso $(date +%y%m%d-%H:%M)."$SUITE"-inx.iso
		sleep 5
	fi

	green ; echo -e "\nMaking the ISO image "$SUITE"-inx.iso - please wait...\n"
	white ; sleep 4
	mkisofs -l -r -J -V ""$SUITE"-inx" -hide-rr-moved -v \
	-b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
	-boot-info-table -o "$SUITE"-inx.iso master
	}

# This is the final "Congratulations!" to the user for letting the script do all the thinking :)
success ()
	{
	clear ; bold ; green
	echo -e "\nWell, it looks like you made it. Congratulations!\n"
	echo -e "If all went as planned, you will find \""$SUITE"-inx.iso\" "
	echo -e "in the \""$PWD"\" directory.\n"
	echo -e "Here is a listing of that directory:\n"
	white
	ls -Al
	}

iso_write ()
	{
	bold ; yellow
	if ! test $DISPLAY ; then
		echo -e "\nHit any key to exit Buildinx.\n"
		read -s -n 1
		reset_and_exit
	fi

	echo -e "\nWould you like to burn a CD of $SUITE-inx.iso ? [y/n]\n"
	white
	read -s -n 1 BURN
	if [ $BURN = y ] ; then
		if which nautilus-cd-burner > /dev/null 2>&1 ; then
			echo -e "\nExiting Buildinx and starting nautilus-cd-burner for you...\n"
			sleep 3
			exec nautilus-cd-burner --source-iso="$SUITE"-inx.iso &
		elif which k3b > /dev/null 2>&1 ; then
			echo -e "\nExiting Buildinx and starting k3b for you...\n"
			sleep 3
			exec k3b "$SUITE"-inx.iso &
		else
			echo -e "\nI looked for nautilus-cd-burner or k3b... Looks like you prefer something else :)"
			echo -e "Exiting the Buildinx script - have fun!\n"
			sleep 4
		fi
	else
		echo -e "\nOK, exiting the Buildinx script - have fun!\n"
		sleep 3
	fi
	}

reset_and_exit ()
	{
	tput sgr0 # reset terminal to original state
	clear
	exit 0
	}

main ()
	{
	warning
	debootstrapping
	choices
	add_inx_examples
	configure_inx
	make_inx
	success
	iso_write
	reset_and_exit
	}

# Here we go...
main