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
|
2017-12-21 01:04:17 +00:00
|
|
|
source_installer=old_iso/casper/installer.squashfs
|
|
|
|
source_filesystem=
|
2019-02-28 20:13:05 +00:00
|
|
|
# Path on disk to a custom snapd (e.g. one that trusts the test keys)
|
|
|
|
snapd_pkg=
|
|
|
|
store_url=
|
2019-03-06 00:28:21 +00:00
|
|
|
tracking=stable
|
|
|
|
while getopts ":ifc:s:n:p:u:t:" 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-12-21 01:04:17 +00:00
|
|
|
s)
|
|
|
|
source_installer="$(readlink -f "${OPTARG}")"
|
|
|
|
;;
|
|
|
|
n)
|
|
|
|
source_filesystem="$(readlink -f "${OPTARG}")"
|
|
|
|
;;
|
2019-02-28 20:13:05 +00:00
|
|
|
p)
|
|
|
|
snapd_pkg="$(readlink -f "${OPTARG}")"
|
|
|
|
;;
|
|
|
|
u)
|
|
|
|
store_url="${OPTARG}"
|
|
|
|
;;
|
2019-03-06 00:28:21 +00:00
|
|
|
t)
|
|
|
|
tracking="${OPTARG}"
|
|
|
|
;;
|
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-21 01:04:17 +00:00
|
|
|
OLD_ISO="$(readlink -f "${1}")"
|
|
|
|
SUBIQUITY_SNAP_PATH="$(readlink -f "${2}")"
|
2017-12-20 23:02:08 +00:00
|
|
|
SUBIQUITY_SNAP="$(basename $SUBIQUITY_SNAP_PATH)"
|
2019-03-01 00:20:17 +00:00
|
|
|
SUBIQUITY_ASSERTION="${SUBIQUITY_SNAP_PATH%.snap}.assert"
|
|
|
|
if [ ! -f "$SUBIQUITY_ASSERTION" ]; then
|
|
|
|
SUBIQUITY_ASSERTION=
|
|
|
|
fi
|
2017-12-21 01:04:17 +00:00
|
|
|
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
|
|
|
|
2021-01-06 01:04:50 +00:00
|
|
|
do_mount_existing () {
|
2017-12-20 23:02:08 +00:00
|
|
|
local mountpoint="${!#}"
|
|
|
|
mount "$@"
|
|
|
|
_MOUNTS=("${mountpoint}" "${_MOUNTS[@]+"${_MOUNTS[@]}"}")
|
2017-08-22 00:02:33 +00:00
|
|
|
}
|
|
|
|
|
2021-01-06 01:04:50 +00:00
|
|
|
do_mount () {
|
|
|
|
local mountpoint="${!#}"
|
|
|
|
mkdir "${mountpoint}"
|
|
|
|
do_mount_existing "$@"
|
|
|
|
}
|
|
|
|
|
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}")"
|
2019-02-28 20:13:05 +00:00
|
|
|
if [ -n "${3-}" ]; then
|
|
|
|
local upper="${3}"
|
|
|
|
else
|
|
|
|
local upper="$(mktemp -dp "${tmpdir}")"
|
|
|
|
fi
|
2017-12-20 23:02:08 +00:00
|
|
|
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-21 01:04:17 +00:00
|
|
|
do_mount -t iso9660 -o loop,ro "${OLD_ISO}" old_iso
|
2021-01-06 01:04:50 +00:00
|
|
|
unsquashfs -d new_installer "${source_installer}"
|
|
|
|
do_mount -t squashfs ${source_filesystem:-old_iso/casper/filesystem.squashfs} old_filesystem
|
|
|
|
add_overlay old_filesystem tree new_installer
|
|
|
|
do_mount_existing dev-live -t devtmpfs "tree/dev"
|
|
|
|
do_mount_existing devpts-live -t devpts "tree/dev/pts"
|
|
|
|
do_mount_existing proc-live -t proc "tree/proc"
|
|
|
|
do_mount_existing sysfs-live -t sysfs "tree/sys"
|
|
|
|
do_mount_existing securityfs-live -t securityfs "tree/sys/kernel/security"
|
2019-02-28 20:13:05 +00:00
|
|
|
|
2017-08-22 00:02:33 +00:00
|
|
|
|
2020-01-29 18:00:52 +00:00
|
|
|
python3 -c '
|
2019-03-01 00:20:17 +00:00
|
|
|
import os, sys, yaml
|
2021-01-06 01:04:50 +00:00
|
|
|
with open("tree/var/lib/snapd/seed/seed.yaml") as fp:
|
2019-03-26 00:59:38 +00:00
|
|
|
old_seed = yaml.safe_load(fp)
|
2018-12-18 23:23:05 +00:00
|
|
|
new_snaps = []
|
|
|
|
|
2019-03-01 00:20:17 +00:00
|
|
|
subiquity_snap = {
|
|
|
|
"name": "subiquity",
|
|
|
|
"classic": True,
|
|
|
|
"file": sys.argv[1],
|
2019-03-06 00:28:21 +00:00
|
|
|
"channel": sys.argv[3],
|
2019-03-01 00:20:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if sys.argv[2] == "":
|
|
|
|
subiquity_snap["unasserted"] = True
|
|
|
|
|
2018-12-18 23:23:05 +00:00
|
|
|
for snap in old_seed["snaps"]:
|
|
|
|
if snap["name"] == "subiquity":
|
2019-03-06 00:28:21 +00:00
|
|
|
new_snaps.append(subiquity_snap)
|
2018-12-18 23:23:05 +00:00
|
|
|
else:
|
|
|
|
new_snaps.append(snap)
|
|
|
|
|
2021-01-06 01:04:50 +00:00
|
|
|
with open("tree/var/lib/snapd/seed/seed.yaml", "w") as fp:
|
2018-12-18 23:23:05 +00:00
|
|
|
yaml.dump({"snaps": new_snaps}, fp)
|
2019-03-23 08:43:08 +00:00
|
|
|
' "$SUBIQUITY_SNAP" "$SUBIQUITY_ASSERTION" "$tracking"
|
2017-08-22 00:02:33 +00:00
|
|
|
|
2021-01-06 01:04:50 +00:00
|
|
|
rm -f tree/var/lib/snapd/seed/assertions/subiquity*.assert
|
|
|
|
rm -f tree/var/lib/snapd/seed/snaps/subiquity*.snap
|
|
|
|
cp "${SUBIQUITY_SNAP_PATH}" tree/var/lib/snapd/seed/snaps/
|
2019-03-01 00:20:17 +00:00
|
|
|
if [ -n "${SUBIQUITY_ASSERTION}" ]; then
|
2021-01-06 01:04:50 +00:00
|
|
|
cp "${SUBIQUITY_ASSERTION}" tree/var/lib/snapd/seed/assertions/
|
2019-03-01 00:20:17 +00:00
|
|
|
fi
|
|
|
|
|
2019-02-28 20:13:05 +00:00
|
|
|
if [ -n "$store_url" ]; then
|
2021-01-06 01:04:50 +00:00
|
|
|
STORE_CONFIG=tree/etc/systemd/system/snapd.service.d/store.conf
|
2019-02-28 20:13:05 +00:00
|
|
|
mkdir -p "$(dirname $STORE_CONFIG)"
|
|
|
|
cat > "$STORE_CONFIG" <<EOF
|
|
|
|
[Service]
|
|
|
|
Environment=SNAPD_DEBUG=1 SNAPD_DEBUG_HTTP=7 SNAPPY_TESTING=1
|
2019-03-01 00:20:17 +00:00
|
|
|
Environment=SNAPPY_FORCE_API_URL=$store_url
|
2019-02-28 20:13:05 +00:00
|
|
|
EOF
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$snapd_pkg" ]; then
|
2021-01-06 01:04:50 +00:00
|
|
|
cp "$snapd_pkg" tree/
|
|
|
|
chroot tree dpkg -i $(basename "$snapd_pkg")
|
|
|
|
rm tree/$(basename "$snapd_pkg")
|
2019-02-28 20:13:05 +00:00
|
|
|
fi
|
|
|
|
|
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-21 01:04:17 +00:00
|
|
|
do_mount -t squashfs ${source_filesystem:-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
|
|
|
|
|
2021-01-06 01:04:50 +00:00
|
|
|
/usr/lib/snapd/snap-preseed --reset $(realpath tree)
|
|
|
|
/usr/lib/snapd/snap-preseed $(realpath tree)
|
|
|
|
chroot tree apparmor_parser --skip-read-cache --write-cache --skip-kernel-load --verbose -j `nproc` /etc/apparmor.d
|
|
|
|
|
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
|
2017-12-21 01:04:17 +00:00
|
|
|
elif [ -n "${source_filesystem}" ]; then
|
|
|
|
rm new_iso/casper/filesystem.squashfs
|
|
|
|
cp "${source_filesystem}" new_iso/casper/filesystem.squashfs
|
2017-12-19 02:51:39 +00:00
|
|
|
fi
|
|
|
|
|
2020-07-29 21:50:10 +00:00
|
|
|
rm new_iso/casper/installer.squashfs new_iso/casper/installer.squashfs.gpg
|
2017-08-22 00:02:33 +00:00
|
|
|
mksquashfs new_installer new_iso/casper/installer.squashfs
|
|
|
|
|
2020-07-29 21:50:10 +00:00
|
|
|
(
|
|
|
|
cd new_iso
|
|
|
|
sed -i'' '/\.\/casper\/installer.squashfs/d' md5sum.txt
|
|
|
|
md5sum ./casper/installer.squashfs >> md5sum.txt
|
|
|
|
)
|
|
|
|
|
2021-02-23 12:11:54 +00:00
|
|
|
opts="$(xorriso -indev ${OLD_ISO} -report_el_torito as_mkisofs)"
|
2021-02-12 02:42:31 +00:00
|
|
|
eval set -- ${opts}
|
2020-11-03 20:30:52 +00:00
|
|
|
xorriso -as mkisofs "$@" -o ${NEW_ISO} -V Ubuntu\ custom new_iso
|