Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/usr-remaster.sh
blob: 6d6a823f9bf9c07448a9c40620fc3aa53a39eaba (plain)
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
#!/bin/bash
##
## usr.sh
## 
## Made by David Farning
## Login   <dfarning@acer>
## 
## Started on  Wed Dec 23 17:25:39 2009 David Farning
## Last update Sat Jan 16 05:04:46 2010 David Farning
##
set -eu

function check_if_user_is_root()
{
    if [ $UID != 0 ]; then
    	echo "You need root privileges"
    	exit 2
    fi
}

function unmount_directory()
{
    DIR_TO_UNMOUNT="$1"
    if mountpoint -q ${DIR_TO_UNMOUNT}; then #FIXME should be able to detect in tmp is mounted
    	echo "Unmounting directory ${DIR_TO_UNMOUNT}..."
    	umount -l ${DIR_TO_UNMOUNT} || failure "Cannot unmount directory ${DIR_TO_UNMOUNT}, error=$?"
    fi
}

function unmount_pseudofilesystems()
{
    if [ -n ${REMASTER_DIR} ]; then
    	unmount_directory ${REMASTER_DIR}/tmp
      	unmount_directory ${REMASTER_DIR}/lib/modules/*/volatile
    	unmount_directory ${REMASTER_DIR}/proc
    	unmount_directory ${REMASTER_DIR}/sys
    	unmount_directory ${REMASTER_DIR}/dev/pts
    	unmount_directory ${REMASTER_DIR}/var/run
    fi
}

function unmount_loopfilesystems()
{
    if [ -n ${SQUASHFS_MOUNT_DIR} ]; then
    	unmount_directory ${SQUASHFS_MOUNT_DIR}
    fi
    if [ -n ${ISO_MOUNT_DIR} ]; then
    	unmount_directory ${ISO_MOUNT_DIR}
    fi
}

function unmount_all()
{
    unmount_pseudofilesystems
    unmount_loopfilesystems
}

function failure()
{
    unmount_all
    echo "$@"
    exit 2
}

function script_cancelled_by_user()
{
    failure "Script cancelled by user"
}

function remove_directory()
{
    DIR_TO_REMOVE="$1"
    if [ ${DIR_TO_REMOVE} = "/" ]; then
	failure "Trying to remove root directory"
    fi
    rm -rf ${DIR_TO_REMOVE}
}
function unpack_initrd()
{
    remove_remaster_initrd
    mkdir -p ${INITRD_REMASTER_DIR} || failure "Cannot create directory ${INITRD_REMASTER_DIR}"

    if [ -e ${ISO_REMASTER_DIR}/casper/initrd.lz ]; then
	INITRD_FILE=${ISO_REMASTER_DIR}/casper/initrd.lz
    else
	failure "Can't find initrd.lz file"
    fi

    echo "Unpacking initrd image..."
    pushd ${INITRD_REMASTER_DIR} || failure "Failed to change directory to ${INITRD_REMASTER_DIR}, error=$?"
    
    lzma -dcq -S .lz ${INITRD_FILE} | cpio -imvd --no-absolute-filenames
    #cat ${INITRD_FILE} | gzip -d | cpio -i  FIXME
    RESULT=$?
    if [ $RESULT -ne 0 ]; then
	failure "Failed to unpack ${INITRD_FILE} to ${INITRD_REMASTER_DIR}, error=$RESULT"
    fi

    popd
}

function pack_initrd()
{
    echo "Packing initrd image..."
    pushd ${INITRD_REMASTER_DIR} || failure "Failed to change directory to ${INITRD_REMASTER_DIR}, error=$?"
    
    find | cpio -H newc -o | lzma -7  > ${REMASTER_HOME}/initrd.lz
    #find | cpio -H newc -o | gzip >${REMASTER_HOME}/initrd.lz    
    
    RESULT=$?
    if [ $RESULT -ne 0 ]; then
    	rm ${REMASTER_HOME}/initrd.lz
    	failure "Failed to compress initird image $INITRD_REMASTER_DIR to ${REMASTER_HOME}/initrd.lz, error=$RESULT"
    fi
    popd

    if [ -e ${ISO_REMASTER_DIR}/casper ]; then
    	INITRD_FILE=${ISO_REMASTER_DIR}/casper/initrd.gz
    else
    	failure "Can't find where to copy the initrd.gz file"
    fi

    mv ${REMASTER_HOME}/initrd.lz ${INITRD_FILE} || failure "Failed to move ${NEW_FILES_DIR}/initrd.lz to ${INITRD_FILE}, error=$?"
}

function mount_iso()
{
    echo "Mounting ISO image..."
    mkdir -p ${ISO_MOUNT_DIR} || failure "Cannot create directory ${ISO_MOUNT_DIR}, error=$?"
    mount ${ISO_IMAGE} ${ISO_MOUNT_DIR} -o loop || failure "Cannot mount ${ISO_IMAGE} in ${ISO_MOUNT_DIR}, error=$?"
}

function unmount_iso()
{
    if [ -e ${ISO_MOUNT_DIR} ] ; then
    	echo "Unmounting ISO image..."
    	umount ${ISO_MOUNT_DIR} || echo "Failed to unmount ISO mount directory ${ISO_MOUNT_DIR}, error=$?"
    	rmdir ${ISO_MOUNT_DIR} || echo "Failed to remove ISO mount directory ${ISO_MOUNT_DIR} error=$?"
    fi
}

function unpack_iso()
{
    echo "Unpacking ISO image..."
    cp -a ${ISO_MOUNT_DIR} ${ISO_REMASTER_DIR} || failure "Failed to unpack ISO from ${ISO_MOUNT_DIR} to ${ISO_REMASTER_DIR}"
	
    #can't trap errors with diff because of its return codes,
    #we pass the diff's output to cut cause we strip the version number
    if [ -e ${ISO_REMASTER_DIR}/casper/filesystem.manifest ]; then
    	diff --unchanged-group-format='' ${ISO_REMASTER_DIR}/casper/filesystem.manifest ${ISO_REMASTER_DIR}/casper/filesystem.manifest-desktop | cut -d ' ' -f 1 > ${ISO_REMASTER_DIR}/casper/manifest.diff
    fi
}

function mount_squashfs()
{
    echo "Mounting SquashFS image..."
    mkdir -p ${SQUASHFS_MOUNT_DIR} || failure "Cannot create directory ${SQUASHFS_MOUNT_DIR}, error=$?"
    mount -t squashfs ${SQUASHFS_IMAGE} ${SQUASHFS_MOUNT_DIR} -o loop || failure "Cannot mount ${SQUASHFS_IMAGE} in ${SQUASHFS_MOUNT_DIR}, error=$?"
}

function unmount_squashfs()
{
    if [ -e ${SQUASHFS_MOUNT_DIR} ] ; then
    	echo "Unmounting SquashFS image..."
    	umount ${SQUASHFS_MOUNT_DIR} || echo "Failed to unmount SquashFS mount directory ${SQUASHFS_MOUNT_DIR}, error=$?"
    	rmdir ${SQUASHFS_MOUNT_DIR} || echo "Failed to remove SquashFS mount directory ${SQUASHFS_MOUNT_DIR}, error=$?"
    fi
}

function unpack_rootfs()
{
    echo "Unpacking SquashFS image..."
    cp -a ${SQUASHFS_MOUNT_DIR} ${REMASTER_DIR} || failure "Cannot copy files from ${SQUASHFS_MOUNT_DIR} to ${REMASTER_DIR}, error=$?"
}

function remove_remaster_dir()
{
    if [ -e "$REMASTER_DIR" ] ; then
    	unmount_pseudofilesystems
    	echo "Removing remastering root dir..."
    	remove_directory "$REMASTER_DIR"
    fi
}

function prepare_new_files_directories()
{
    echo "Preparing directory for new files"
    if [ -e ${NEW_FILES_DIR} ]; then
    	remove_directory ${NEW_FILES_DIR} || failure "Failed to remove directory ${NEW_FILES_DIR}"
    fi
    mkdir -p ${NEW_FILES_DIR}
}

function prepare_rootfs_for_chroot()
{
    mount -t proc proc "$REMASTER_DIR/proc" || echo "Failed to mount $REMASTER_DIR/proc, error=$?"
    mount -t sysfs sysfs "$REMASTER_DIR/sys" || echo "Failed to mount $REMASTER_DIR/sys, error=$?"
    mount -t devpts none "$REMASTER_DIR/dev/pts" || failure "Failed to mount $REMASTER_DIR/dev/pts, error=$?"
    mount -o bind /var/run "$REMASTER_DIR/var/run"
    #mount -o bind /tmp "$REMASTER_DIR/tmp" FIXME do we need temp

    #create backup of root directory
    chroot "$REMASTER_DIR" cp -a /root /root.saved || failure "Failed to create backup of /root directory, error=$?"
 
#    if [ -e $REMASTER_HOME/customization-scripts ]; then
#        echo "Copying customization scripts..."
#        cp -a "$REMASTER_HOME/customization-scripts" "$REMASTER_DIR/tmp" || failure "Cannot copy files from $CUSTOMIZE_DIR to $REMASTER_CUSTOMIZE_DIR, error=$?"
#    fi

    echo "Copying resolv.conf..."
    cp -f /etc/resolv.conf "$REMASTER_DIR/etc/resolv.conf" || failure "Failed to copy resolv.conf to image directory, error=$?"

    echo "Copying local apt cache, if available"
    if [ -e "$APT_CACHE_SAVE_DIR" ]; then
	mv "$REMASTER_DIR/var/cache/apt/" "$REMASTER_DIR/var/cache/apt.original" || failure "Cannot move $REMASTER_DIR/var/cache/apt/ to $REMASTER_DIR/var/cache/apt.original, error=$?"
	mv "$APT_CACHE_SAVE_DIR" "$REMASTER_DIR/var/cache/apt" || failure "Cannot copy apt cache dir $APT_CACHE_SAVE_DIR to $REMASTER_DIR/var/cache/apt/, error=$?"
    else
	cp -a "$REMASTER_DIR/var/cache/apt/" "$REMASTER_DIR/var/cache/apt.original" || failure "Cannot copy $REMASTER_DIR/var/cache/apt/ to $REMASTER_DIR/var/cache/apt.original, error=$?"
    fi

    echo "Creating DBUS uuid"
    chroot "$REMASTER_DIR" dbus-uuidgen --ensure 1>/dev/null 2>&1

    if [ -e "$REMASTER_HOME/customization-scripts/Xcookie" ] ; then
	UCK_USER_HOME_DIR=`xauth info|grep 'Authority file'| sed "s/[ \t]//g" | sed "s/\/\.Xauthority//" | cut -d ':' -f2`
	if [ `echo $UCK_USER_HOME_DIR | cut -d '/' -f2` == 'home' ] ; then
	    echo "Creating user directory..."
	    chroot "$REMASTER_DIR" mkdir -p "$UCK_USER_HOME_DIR" >/dev/null 2>&1
	    echo "Copying X authorization file to chroot filesystem..."
	    cat "$REMASTER_HOME/customization-scripts/Xcookie" | chroot "$REMASTER_DIR" xauth -f /root/.Xauthority merge - || failure "Failed to merge X authorization file, error=$?"
	    cat "$REMASTER_HOME/customization-scripts/Xcookie" | chroot "$REMASTER_DIR" xauth merge - || failure "Failed to merge X authorization file in user directory, error=$?"
	fi
    fi
}

function chroot_rootfs()
{
    cp -f ${WHAT_TO_EXTECUTE} ${REMASTER_DIR}/chroot.sh 
    chroot ${REMASTER_DIR} /chroot.sh
    chroot ${REMASTER_DIR} /bin/bash
}

function clean_rootfs_after_chroot()
{
    unmount_pseudofilesystems
    save_apt_cache

    echo "Cleaning up apt"
    chroot "$REMASTER_DIR" apt-get clean || failure "Failed to run apt-get clean, error=$?"

#	echo "Removing customize dir..."
#	#Run in chroot to be on safe side
#	chroot "$REMASTER_DIR" rm -rf "$REMASTER_CUSTOMIZE_RELATIVE_DIR" || failure "Cannot remove customize dir $REMASTER_CUSTOMIZE_RELATIVE_DIR, error=$?"

    echo "Cleaning up temporary directories..."
    #Run in chroot to be on safe side
    chroot "$REMASTER_DIR" rm -rf '/tmp/*' '/tmp/.*' '/var/tmp/*' '/var/tmp/.*' #2>/dev/null
 
    echo "Restoring /root directory..."
    chroot "$REMASTER_DIR" rm -rf /root || failure "Cannot remove /root directory, error=$?"
    chroot "$REMASTER_DIR" mv /root.saved /root

    echo "Removing /home/username directory, if created..."
    UCK_USER_HOME_DIR=`xauth info|grep 'Authority file'| sed "s/[ \t]//g" | sed "s/\/\.Xauthority//" | cut -d ':' -f2`
    if [ `echo $UCK_USER_HOME_DIR | cut -d '/' -f2` == 'home' ] ; then
	chroot "$REMASTER_DIR" rm -rf "$UCK_USER_HOME_DIR" || failure "Cannot create user directory, error=$?"
    fi
    chroot "$REMASTER_DIR" rm -rf /var/lib/dbus/machine-id # 2>/dev/null
    
    echo "Restoring resolv.conf..."
    rm -f "$REMASTER_DIR/etc/resolv.conf" || failure "Failed to remove resolv.conf, error=$?"
}

function save_apt_cache()
{
    echo "Saving apt cache"
    if [ -e "$APT_CACHE_SAVE_DIR" ]; then
	mv -f "$APT_CACHE_SAVE_DIR" "$APT_CACHE_SAVE_DIR.old" || failure "Cannot save old apt-cache $APT_CACHE_SAVE_DIR to $APT_CACHE_SAVE_DIR.old, error=$?"
    fi
    mv "$REMASTER_DIR/var/cache/apt/" "$APT_CACHE_SAVE_DIR" || failure "Cannot move current apt-cache $REMASTER_DIR/var/cache/apt/ to $APT_CACHE_SAVE_DIR, error=$?"
    mv "$REMASTER_DIR/var/cache/apt.original" "$REMASTER_DIR/var/cache/apt" || failure "Cannot restore original apt-cache $REMASTER_DIR/var/cache/apt.original to $REMASTER_DIR/var/cache/apt, error=$?"
}

function pack_rootfs()
{
    echo "Updating files lists..."
    chroot "$REMASTER_DIR" dpkg-query -W --showformat='${Package} ${Version}\n' > "$ISO_REMASTER_DIR/casper/filesystem.manifest" || failure "Cannot update filesystem.manifest, error=$?"
   
    cp  ${ISO_REMASTER_DIR}/casper/filesystem.manifest ${ISO_REMASTER_DIR}/casper/filesystem.manifest-desktop

    sed -i '/ubiquity/d' ${ISO_REMASTER_DIR}/casper/filesystem.manifest-desktop
    sed -i '/casper/d' ${ISO_REMASTER_DIR}/casper/filesystem.manifest-desktop

    echo "Packing SquashFS image..."
    if [ -e "$ISO_REMASTER_DIR/casper/filesystem.squashfs" ]; then
        rm -f "$ISO_REMASTER_DIR/casper/filesystem.squashfs" || failure "Cannot remove $ISO_REMASTER_DIR/casper/filesystem.squashfs to make room for created squashfs image, error=$?"
    fi

    EXTRA_OPTS=""
#    if [ -e "$CUSTOMIZE_DIR/rootfs.sort" ] ; then
#        #FIXME: space not allowed in $CUSTOMIZE_DIR
#	EXTRA_OPTS="-sort $CUSTOMIZE_DIR/rootfs.sort"
#    fi

    mksquashfs "$REMASTER_DIR" "$ISO_REMASTER_DIR/casper/filesystem.squashfs" $EXTRA_OPTS || failure "Failed to create squashfs image to $ISO_REMASTER_DIR/casper/filesystem.squashfs, error=$?"
}

function pack_iso()
{
    if [ ! -e ${ISO_REMASTER_DIR} ]; then
    	failure "ISO remastering directory does not exists"
    fi

    #skip boot.cat, isolinux.bin, md5sums.txt
    #mismatches are for those files, because they are generated by mkisofs or by generating MD5 sums:
    EXCLUDED_FROM_MD5="./isolinux/isolinux.bin ./isolinux/boot.cat ./md5sum.txt ./manifest.diff"
    EXCLUDED_FROM_MD5_EXPRESSION=$(echo $EXCLUDED_FROM_MD5 | tr ' ' '|')
    EXCLUDED_FROM_MD5_EXPRESSION="($EXCLUDED_FROM_MD5_EXPRESSION)"

    echo "Updating md5sums..."
    pushd ${ISO_REMASTER_DIR}
    find . -type f -print0 | grep --null-data -v -E "$EXCLUDED_FROM_MD5_EXPRESSION" | xargs -0 md5sum > md5sum.txt
    popd

    echo "Packing ISO image..."

    LIVECD_ISO_DESCRIPTION="Remastered Ubuntu LiveCD"

    if [ -e ${CUSTOMIZE_DIR}/iso_description ] ; then
    	LIVECD_ISO_DESCRIPTION=`cat ${CUSTOMIZE_DIR}/iso_description`
    fi

    echo "ISO description set to: ${LIVECD_ISO_DESCRIPTION}"

    MKISOFS_EXTRA_OPTIONS=""
    if [ -e ${CUSTOMIZE_DIR}/mkisofs_extra_options ] ; then
    	MKISOFS_EXTRA_OPTIONS=`cat ${CUSTOMIZE_DIR}/mkisofs_extra_options`
    fi

    if [ "$1" = "ppc" ]; then
    	mkisofs -o "$NEW_FILES_DIR/$NEW_ISO_FILE_NAME" \
    		-p "Ubuntu Customization Kit - http://uck.sf.net" \
    		-probe -map "$UCK_LIBRARIES_DIR/hfs.map" -chrp-boot -iso-level 2 \
    		-part -no-desktop -r --netatalk -hfs \
    		-hfs-bless "$ISO_REMASTER_DIR/install" \
    		-x "$ISO_REMASTER_DIR"/casper/manifest.diff \
    		-V "$LIVECD_ISO_DESCRIPTION" \
    		$MKISOFS_EXTRA_OPTIONS \
    		"$ISO_REMASTER_DIR"
    elif [ "$1" = "x86_64" ]; then
	mkisofs -o "$NEW_FILES_DIR/$NEW_ISO_FILE_NAME" \
		-b "isolinux/isolinux.bin" -c "isolinux/boot.cat" \
		-p "Ubuntu Customization Kit - http://uck.sf.net" \
		-no-emul-boot -V "$LIVECD_ISO_DESCRIPTION" -r -J -l \
		-x "$ISO_REMASTER_DIR"/casper/manifest.diff \
		$MKISOFS_EXTRA_OPTIONS \
		"$ISO_REMASTER_DIR"
    elif [ "$1" = "ia64" ]; then
	mkisofs -o "$NEW_FILES_DIR/$NEW_ISO_FILE_NAME" \
		-b "isolinux/isolinux.bin" -c "isolinux/boot.cat" \
		-no-emul-boot -V "$LIVECD_ISO_DESCRIPTION" -J -r \
		-x "$ISO_REMASTER_DIR"/casper/manifest.diff \
		$MKISOFS_EXTRA_OPTIONS \
		"$ISO_REMASTER_DIR"
    else
    	mkisofs -o "$NEW_FILES_DIR/$NEW_ISO_FILE_NAME" \
		-b "isolinux/isolinux.bin" -c "isolinux/boot.cat" \
		-p "Ubuntu Customization Kit - http://uck.sf.net" \
		-no-emul-boot -boot-load-size 4 -boot-info-table \
		-V "$LIVECD_ISO_DESCRIPTION" -cache-inodes -r -J -l \
		-x "$ISO_REMASTER_DIR"/casper/manifest.diff \
		$MKISOFS_EXTRA_OPTIONS \
		"$ISO_REMASTER_DIR"
    fi

    RESULT=$?
    if [ $RESULT -ne 0 ]; then
    	failure "Failed to pack ISO image, error=${RESULT}"
    fi
}

function generate_md5_for_new_iso()
{
    echo "Generating md5sum for newly created ISO..."
    cd ${NEW_FILES_DIR}
    md5sum ${NEW_ISO_FILE_NAME} > ${NEW_ISO_FILE_NAME}.md5
}

function remove_iso_remaster_dir()
{
    if [ -e "$ISO_REMASTER_DIR" ] ; then
	echo "Removing ISO remastering dir..."
	remove_directory "$ISO_REMASTER_DIR" || failure "Failed to remove directory $ISO_REMASTER_DIR, error=$?"
fi
}

function remove_remaster_dir()
{
    if [ -e "$REMASTER_DIR" ] ; then
	unmount_pseudofilesystems
	echo "Removing remastering root dir..."
	remove_directory "$REMASTER_DIR"
    fi
}

function remove_remaster_initrd()
{
    if [ -e  "$INITRD_REMASTER_DIR" ]; then
    	echo "Removing initrd remastering dir..."
	remove_directory "$INITRD_REMASTER_DIR"
    fi
}

export LANG=C
check_if_user_is_root
trap unmount_all EXIT
trap script_cancelled_by_user SIGINT

REMASTER_HOME=/home/dfarning/usr
ISO_IMAGE=lucid-netbook-i386.iso

#############
# unpacking #
#############

ISO_REMASTER_DIR=${REMASTER_HOME}/remaster_iso
ISO_MOUNT_DIR=${REMASTER_HOME}/iso_mount
mount_iso
unpack_iso
unmount_iso

#FIXME initrd should come before rootfs 
REMASTER_DIR=${REMASTER_HOME}/remaster_root
SQUASHFS_MOUNT_DIR=${REMASTER_HOME}/squashfs_mount
SQUASHFS_IMAGE=${REMASTER_HOME}/remaster_iso/casper/filesystem.squashfs
remove_remaster_dir
mount_squashfs
unpack_rootfs
unmount_squashfs

INITRD_REMASTER_DIR=${REMASTER_HOME}/remaster_initrd
unpack_initrd

###############
# customizing #
###############

WHAT_TO_EXTECUTE=/home/dfarning/usr/bin/usr-chroot.sh
APT_CACHE_SAVE_DIR=${REMASTER_HOME}/remaster_apt_cache
prepare_rootfs_for_chroot
chroot_rootfs
CHROOT_EXIT_CODE=$?
clean_rootfs_after_chroot

## create text.cfg ##
cat << EOF > ${ISO_REMASTER_DIR}/isolinux/text.cfg
default live
label live
  menu label ^Try Ubuntu Sugar Remix without any change to your computer
  kernel /casper/vmlinuz
  append  file=/cdrom/preseed/ubuntu-netbook.seed boot=casper apparmor=0 initrd=/casper/initrd.lz quiet splash --
label live-install
  menu label ^Install Ubuntu Sugar Remix
  kernel /casper/vmlinuz
  append  file=/cdrom/preseed/ubuntu-netbook.seed boot=casper apparmor=0 only-ubiquity initrd=/casper/initrd.lz quiet splash --
EOF



###########
# packing #
###########

pack_initrd

pack_rootfs

NEW_ISO_FILE_NAME=ubuntu-sugar-remix.iso
NEW_FILES_DIR=${REMASTER_HOME}/remaster_new_files
CUSTOMIZE_DIR=${REMASTER_HOME}/customization_scripts
ARCH=x86
prepare_new_files_directories
pack_iso ${ARCH}
generate_md5_for_new_iso

#############
# finishing #
#############

remove_remaster_initrd
remove_remaster_dir
remove_iso_remaster_dir