aboutsummaryrefslogtreecommitdiffstats
path: root/preseed.sh
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem@fripost.org>2013-10-28 19:50:41 +0100
committerGuilhem Moulin <guilhem@fripost.org>2015-06-07 04:27:43 +0200
commite596091daf51443248a0cb427832be62552eaf27 (patch)
tree947c9dbe584746aa8a20d0f39a42ad0703bc5e6a /preseed.sh
parentea9414878e7613f33b7808feb390d3dd49aefb6c (diff)
Reorganization.
Move preseed-related stuff in ./preseed/, and vm-related stuff in ./virtualenv/.
Diffstat (limited to 'preseed.sh')
-rwxr-xr-xpreseed.sh93
1 files changed, 93 insertions, 0 deletions
diff --git a/preseed.sh b/preseed.sh
new file mode 100755
index 0000000..b3d8362
--- /dev/null
+++ b/preseed.sh
@@ -0,0 +1,93 @@
+#!/bin/sh
+#
+# Usage: preseed.sh preseeded.iso source.iso [udebs]
+#
+# Credits: https://wiki.debian.org/DebianInstaller/Preseed/EditIso
+# https://wiki.debian.org/DebianInstaller/Modify/CD
+#
+# Install with 'Advanced options > Automated install'
+
+set -ue
+
+newiso=$(readlink -f "$1")
+[ -e "$newiso" ] && rm -f "$newiso"
+
+iso="$2"
+test -r "$iso" || exit 1
+shift; shift
+pwd=$(pwd)
+
+for prog in fuseiso fusermount rsync md5sum genisoimage find; do
+ if ! which "$prog" >/dev/null; then
+ echo "Error: Missing $prog" >&2
+ exit 1
+ fi
+done
+
+mountdir=$(mktemp -d)
+fuseiso "$iso" "$mountdir"
+
+isoeditdir=$(mktemp -d)
+rsync -aH --exclude=TRANS.TBL --chmod=u+w "$mountdir"/ "$isoeditdir"/
+
+fusermount -u "$mountdir"
+rmdir "$mountdir"
+
+cp preseed.cfg "$isoeditdir/"
+md5sum ./preseed.cfg >> "$isoeditdir/md5sum.txt"
+
+isolinux=isolinux/adtxt.cfg
+sed -ri "s@^\s+append\s(.*\s)?auto=true\b@& file=/cdrom/preseed.cfg @" \
+ "$isoeditdir/$isolinux"
+# ^ no need to update the checksum, $isolinux is not in './md5sum.txt'.
+
+mkdir "$isoeditdir/include"
+rsync -aL ./include/ "$isoeditdir/include"/
+find ./include \( \! -name '.*' -a -type f \) -print0 | \
+ xargs -r0 md5sum >> "$isoeditdir/md5sum.txt"
+
+# TODO: that's ugly
+dist=$(for x in "$isoeditdir"/dists/*; do [ -h "$x" ] && continue; [ -d "$x" ] && echo ${x##*/} && break; done)
+arch=$(for x in "$isoeditdir/dists/$dist/main"/binary-*; do test -d "$x" && echo ${x##*/binary-} && break; done)
+packages="dists/$dist/main/debian-installer/binary-$arch/Packages"
+while [ $# -gt 0 ]; do
+ cd "${1%%_*}-udeb"; shift
+ name="$(sed -n 's/Package:\s\s*//p' ./debian/control)"
+ udeb=$(cut -d' ' -f1,1 ./debian/files)
+ dir="pool/main/$(expr substr "$name" 1 1)/$name"
+ mkdir -p "$isoeditdir/$dir/"
+ cp ../"$udeb" "$isoeditdir/$dir/"
+
+ cat "./debian/$name/DEBIAN/control" >> "$isoeditdir/$packages"
+ echo "Filename: $dir/$udeb" >> "$isoeditdir/$packages"
+ echo "MD5sum: $(md5sum ../"$udeb" | cut -d' ' -f1,1)" >> "$isoeditdir/$packages"
+ echo "SHA1: $(sha1sum ../"$udeb" | cut -d' ' -f1,1)" >> "$isoeditdir/$packages"
+ echo "SHA256: $(sha256sum ../"$udeb" | cut -d' ' -f1,1)" >> "$isoeditdir/$packages"
+ echo >> "$isoeditdir/$packages"
+
+ cd "$isoeditdir"
+ md5sum "./$dir/$udeb" >> "$isoeditdir/md5sum.txt"
+ cd "$pwd"
+done
+
+cd "$isoeditdir"
+gzip -fk ./"$packages"
+
+md5sums=$(mktemp)
+while read sum file; do
+ if [ "$file" = "./${packages}" -o \
+ "$file" = "./${packages}.gz" ]; then
+ md5sum "$file"
+ else
+ echo "$sum $file"
+ fi
+done < ./md5sum.txt > "$md5sums"
+mv "$md5sums" "$isoeditdir/md5sum.txt"
+
+genisoimage -o "$newiso" -quiet -r -J \
+ -no-emul-boot -boot-load-size 4 \
+ -boot-info-table \
+ -b isolinux/isolinux.bin \
+ -c isolinux/boot.cat \
+ ./
+rm -rf "$isoeditdir"