-
Notifications
You must be signed in to change notification settings - Fork 7
/
make-preseed-iso.sh
executable file
·90 lines (76 loc) · 2.56 KB
/
make-preseed-iso.sh
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
#!/bin/bash
set -e
function extract_iso() {
echo "Extracting iso: $1..."
mkdir isofiles
bsdtar -C isofiles -xf "$1"
}
function add_preseed_to_initrd() {
echo "Adding preseed.cfg to initrd..."
chmod +w isofiles/install.amd/ -R
gunzip isofiles/install.amd/initrd.gz
echo preseed.cfg | cpio -H newc -o -A -F isofiles/install.amd/initrd
gzip isofiles/install.amd/initrd
chmod -w isofiles/install.amd/ -R
}
function make_auto_the_default_isolinux_boot_option() {
tmp_isolinux_cfg=$(mktemp --tmpdir isolinux.XXXXX)
echo "Setting 'auto' as default ISOLINUX boot entry..."
sed 's/timeout 0/timeout 3/g' isofiles/isolinux/isolinux.cfg >$tmp_isolinux_cfg
echo "default auto" >>$tmp_isolinux_cfg
chmod +w isofiles/isolinux/isolinux.cfg
cat $tmp_isolinux_cfg >isofiles/isolinux/isolinux.cfg
chmod -w isofiles/isolinux/isolinux.cfg
rm $tmp_isolinux_cfg
}
function make_auto_the_default_grub_boot_option() {
echo "Setting 'auto' as default GRUB boot entry..."
chmod +w isofiles/boot/grub/grub.cfg
# The index for the grub menus is zero-based for the
# Root menu, but 1-based for the rest, so 2>5 is the
# second menu (advanced options) => fifth option (auto)
echo 'set default="2>5"' >>isofiles/boot/grub/grub.cfg
echo "set timeout=3" >>isofiles/boot/grub/grub.cfg
chmod -w isofiles/boot/grub/grub.cfg
}
function recompute_md5_checksum() {
echo "Calculating new md5 checksum..."
echo " -- You can safely ignore the warning about a 'file system loop' below"
cd isofiles
chmod +w md5sum.txt
find . -follow -type f ! -name md5sum.txt -print0 | xargs -0 md5sum >md5sum.txt
chmod -w md5sum.txt
cd ..
}
function generate_new_iso_and_cleanup() {
local orig_iso="$1"
local new_iso="$2"
echo "Generating new iso: $new_iso..."
dd if="$orig_iso" bs=1 count=432 of=mbr_template.bin
chmod +w isofiles/isolinux/isolinux.bin
xorriso -as mkisofs -r \
-V 'Debian AUTO amd64' \
-o "$new_iso" \
-J -joliet-long \
-cache-inodes \
-isohybrid-mbr mbr_template.bin \
-b isolinux/isolinux.bin \
-c isolinux/boot.cat \
-boot-load-size 4 -boot-info-table \
-no-emul-boot -eltorito-alt-boot \
-e boot/grub/efi.img -no-emul-boot \
-isohybrid-gpt-basdat \
-isohybrid-apm-hfsplus \
isofiles
chmod +w isofiles -R
rm -rf isofiles mbr_template.bin
}
orig_iso="$1"
new_iso="./preseed-$(basename $orig_iso)"
extract_iso "$orig_iso"
add_preseed_to_initrd
make_auto_the_default_isolinux_boot_option
make_auto_the_default_grub_boot_option
recompute_md5_checksum
generate_new_iso_and_cleanup "$orig_iso" "$new_iso"
echo "DONE."