2017-08-22 00:02:33 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -eux
|
|
|
|
|
2017-11-16 23:34:23 +00:00
|
|
|
cmds=
|
2017-11-16 21:25:08 +00:00
|
|
|
interactive=no
|
2017-12-19 02:51:39 +00:00
|
|
|
edit_filesystem=no
|
|
|
|
while getopts ":ifc:" opt; do
|
2017-11-16 21:25:08 +00:00
|
|
|
case "${opt}" in
|
|
|
|
i)
|
|
|
|
interactive=yes
|
|
|
|
;;
|
2017-11-16 23:34:23 +00:00
|
|
|
c)
|
2017-12-20 23:02:08 +00:00
|
|
|
cmds="${OPTARG}"
|
2017-11-16 23:34:23 +00:00
|
|
|
;;
|
2017-12-19 02:51:39 +00:00
|
|
|
f)
|
|
|
|
edit_filesystem=yes
|
|
|
|
;;
|
2017-11-16 21:25:08 +00:00
|
|
|
\?)
|
|
|
|
echo "Invalid option: -$OPTARG" >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift $((OPTIND-1))
|
|
|
|
|
2017-08-22 22:26:09 +00:00
|
|
|
# inject-subiquity-snap.sh $old_iso $subiquity_snap $new_iso
|
2017-08-22 00:02:33 +00:00
|
|
|
|
2017-12-20 23:02:08 +00:00
|
|
|
OLD_ISO="$(readlink -f $1)"
|
|
|
|
SUBIQUITY_SNAP_PATH="$(readlink -f $2)"
|
|
|
|
SUBIQUITY_SNAP="$(basename $SUBIQUITY_SNAP_PATH)"
|
|
|
|
NEW_ISO="$(readlink -f $3)"
|
2017-08-22 00:02:33 +00:00
|
|
|
|
2017-12-20 23:02:08 +00:00
|
|
|
tmpdir="$(mktemp -d)"
|
|
|
|
cd "${tmpdir}"
|
2017-08-22 00:02:33 +00:00
|
|
|
|
2017-12-19 03:03:53 +00:00
|
|
|
_MOUNTS=()
|
2017-08-22 00:02:33 +00:00
|
|
|
|
2017-12-20 23:02:08 +00:00
|
|
|
do_mount () {
|
|
|
|
local mountpoint="${!#}"
|
|
|
|
mkdir "${mountpoint}"
|
|
|
|
mount "$@"
|
|
|
|
_MOUNTS=("${mountpoint}" "${_MOUNTS[@]+"${_MOUNTS[@]}"}")
|
2017-08-22 00:02:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cleanup () {
|
2017-12-20 23:02:08 +00:00
|
|
|
for m in "${_MOUNTS[@]+"${_MOUNTS[@]}"}"; do
|
|
|
|
umount "${m}"
|
2017-08-22 00:02:33 +00:00
|
|
|
done
|
2017-12-20 23:02:08 +00:00
|
|
|
rm -rf "${tmpdir}"
|
2017-08-22 00:02:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
trap cleanup EXIT
|
|
|
|
|
|
|
|
add_overlay() {
|
2017-12-20 23:02:08 +00:00
|
|
|
local lower="$1"
|
|
|
|
local mountpoint="$2"
|
|
|
|
local work="$(mktemp -dp "${tmpdir}")"
|
|
|
|
local upper="$(mktemp -dp "${tmpdir}")"
|
|
|
|
chmod go+rx "${work}" "${upper}"
|
|
|
|
do_mount -t overlay overlay -o lowerdir="${lower}",upperdir="${upper}",workdir="${work}" "${mountpoint}"
|
2017-08-22 00:02:33 +00:00
|
|
|
}
|
|
|
|
|
2017-12-20 23:02:08 +00:00
|
|
|
do_mount -t iso9660 -o loop "${OLD_ISO}" old_iso
|
|
|
|
do_mount -t squashfs old_iso/casper/installer.squashfs old_installer
|
2017-08-22 00:02:33 +00:00
|
|
|
add_overlay old_installer new_installer
|
|
|
|
|
|
|
|
|
2017-12-20 23:02:08 +00:00
|
|
|
CORE_SNAP="$(cd old_installer/var/lib/snapd/seed/snaps/; ls -1 core*.snap)"
|
2017-08-22 00:02:33 +00:00
|
|
|
|
|
|
|
cat <<EOF > new_installer/var/lib/snapd/seed/seed.yaml
|
|
|
|
snaps:
|
|
|
|
- name: core
|
|
|
|
channel: stable
|
2017-12-20 23:02:08 +00:00
|
|
|
file: "${CORE_SNAP}"
|
2017-08-22 00:02:33 +00:00
|
|
|
- name: subiquity
|
|
|
|
unasserted: true
|
|
|
|
classic: true
|
2017-12-20 23:02:08 +00:00
|
|
|
file: "${SUBIQUITY_SNAP}"
|
2017-08-22 00:02:33 +00:00
|
|
|
EOF
|
|
|
|
|
|
|
|
rm -f new_installer/var/lib/snapd/seed/assertions/subiquity*.assert
|
|
|
|
rm -f new_installer/var/lib/snapd/seed/snaps/subiquity*.snap
|
2017-12-20 23:02:08 +00:00
|
|
|
cp "${SUBIQUITY_SNAP_PATH}" new_installer/var/lib/snapd/seed/snaps/
|
2017-08-22 00:02:33 +00:00
|
|
|
|
|
|
|
add_overlay old_iso new_iso
|
2017-11-16 21:25:08 +00:00
|
|
|
|
2017-12-19 02:51:39 +00:00
|
|
|
if [ "$edit_filesystem" = "yes" ]; then
|
2017-12-20 23:02:08 +00:00
|
|
|
do_mount -t squashfs old_iso/casper/filesystem.squashfs old_filesystem
|
2017-12-19 02:51:39 +00:00
|
|
|
add_overlay old_filesystem new_filesystem
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2017-11-16 23:34:23 +00:00
|
|
|
if [ -n "$cmds" ]; then
|
|
|
|
bash -c "$cmds"
|
|
|
|
fi
|
2017-11-16 21:25:08 +00:00
|
|
|
if [ "$interactive" = "yes" ]; then
|
|
|
|
bash
|
|
|
|
fi
|
|
|
|
|
2017-12-19 02:51:39 +00:00
|
|
|
if [ "$edit_filesystem" = "yes" ]; then
|
|
|
|
rm new_iso/casper/filesystem.squashfs
|
|
|
|
mksquashfs new_filesystem new_iso/casper/filesystem.squashfs
|
|
|
|
fi
|
|
|
|
|
2017-08-22 00:02:33 +00:00
|
|
|
rm new_iso/casper/installer.squashfs
|
|
|
|
mksquashfs new_installer new_iso/casper/installer.squashfs
|
|
|
|
|
|
|
|
xorriso -as mkisofs -r -checksum_algorithm_iso md5,sha1 \
|
|
|
|
-V Ubuntu\ custom\ amd64 \
|
2017-12-20 23:02:08 +00:00
|
|
|
-o "${NEW_ISO}" \
|
2017-08-22 00:02:33 +00:00
|
|
|
-cache-inodes -J -l \
|
|
|
|
-b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot \
|
|
|
|
-boot-load-size 4 -boot-info-table \
|
|
|
|
-eltorito-alt-boot -e boot/grub/efi.img -no-emul-boot \
|
|
|
|
-isohybrid-gpt-basdat -isohybrid-apm-hfsplus \
|
|
|
|
-isohybrid-mbr /usr/lib/ISOLINUX/isohdpfx.bin \
|
|
|
|
new_iso/boot new_iso
|
|
|
|
|
|
|
|
|