File: addpreseed.sh

package info (click to toggle)
android-cuttlefish 1.0.1-0~exp2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 7,192 kB
  • sloc: cpp: 39,149; sh: 2,523; javascript: 242; exp: 152; python: 125; makefile: 88
file content (88 lines) | stat: -rwxr-xr-x 2,509 bytes parent folder | download
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
#!/bin/sh

BASEDIR=$(dirname $(realpath "$0"))

orig_iso=mini.iso
auto_extract_efi=1
efi_img=efi.img

new_files=iso_unpacked_and_modified
new_iso=preseed-mini.iso

PRESEEDFILE=$(realpath "${BASEDIR}"/preseed/preseed.cfg)
AFTERINSTALLSCRIPT=$(realpath "${BASEDIR}"/preseed/after_install_1.sh)

part_img_ready=1
if test "$auto_extract_efi" = 1; then
  start_block=$(/sbin/fdisk -l "$orig_iso" | fgrep "$orig_iso"2 | \
                awk '{print $2}')
  block_count=$(/sbin/fdisk -l "$orig_iso" | fgrep "$orig_iso"2 | \
                awk '{print $4}')
  if test "$start_block" -gt 0 -a "$block_count" -gt 0 2>/dev/null
  then
    dd if="$orig_iso" bs=512 skip="$start_block" count="$block_count" \
       of="$efi_img"
  else
    echo "Cannot read plausible start block and block count from fdisk" >&2
    part_img_ready=0
  fi
fi

# add preseed
mkdir ${new_files}
bsdtar -C ${new_files} -xf "$orig_iso"
cd ${new_files}
cp -f "${PRESEEDFILE}" preseed.cfg
cp -f "${AFTERINSTALLSCRIPT}" after_install_1.sh
chmod a+rx after_install_1.sh

# add preseed to console based installer
chmod ug+w initrd.gz
gzip -d -f initrd.gz
echo preseed.cfg | cpio -H newc -o -A -F initrd
echo after_install_1.sh | cpio -H newc -o -A -F initrd
gzip -9 initrd
chmod a-w initrd.gz
# add preseed to GTK based installer
chmod ug+w gtk
cd gtk
chmod ug+w initrd.gz
gzip -d -f initrd.gz
cp -f ../preseed.cfg .
cp -f ../after_install_1.sh .
echo preseed.cfg | cpio -H newc -o -A -F initrd
echo after_install_1.sh | cpio -H newc -o -A -F initrd
gzip -9 initrd
chmod a-w initrd.gz
rm -f preseed.cfg after_install_1.sh
cd ..
chmod a-w gtk
# modify Graphical installer to use tty1
chmod ug+w boot
chmod ug+w boot/grub
chmod ug+w boot/grub/grub.cfg
sed -i '0,/menuentry/{s#menuentry#menuentry '\''Ampere Install'\'' {\n    set background_color=black\n    linux    /linux --- quiet console=tty1\n    initrd   /gtk/initrd.gz\n}\nmenuentry#}' boot/grub/grub.cfg
sed -i '0,/insmod gzio/{s#insmod gzio#set timeout=120\n\ninsmod gzio#}' boot/grub/grub.cfg
chmod a-w boot/grub/grub.cfg
chmod a-w boot/grub
chmod a-w boot
cd ..

rm -f "${new_iso}"

# Create the new ISO image if not partition extraction failed
test "$part_img_ready" = 1 && \
xorriso -as mkisofs \
   -r -V 'Debian arm64 n' \
   -o "$new_iso" \
   -J -joliet-long -cache-inodes \
   -e boot/grub/efi.img \
   -no-emul-boot \
   -append_partition 2 0xef "$efi_img" \
   -partition_cyl_align all \
   "$new_files"

# clean
rm -f efi.img
chmod ug+w -R "${new_files}"
rm -rf "${new_files}"