#! /bin/sh set -e export LC_ALL=C ( . "${LIVE_BUILD}/scripts/build.sh" > /dev/null 2>&1 || true ) || . /usr/lib/live/build.sh Arguments "${@}" Read_conffiles config/all config/common config/bootstrap config/chroot config/binary config/source Set_defaults # Setup cleanup function Setup_cleanup preinstall_snaps() { lb chroot_resolv install chroot chroot sh -c ' set -x; cd /var/lib/snapd/seed; SNAPPY_STORE_NO_CDN=1 snap download core' for snap in "$@"; do chroot chroot sh -c " set -x; cd /var/lib/snapd/seed; SNAPPY_STORE_NO_CDN=1 snap download \"${snap%/*}\"" done lb chroot_resolv remove CORE_SNAP=$(cd chroot/var/lib/snapd/seed; ls -1 core_*.snap) cat < chroot/var/lib/snapd/seed/seed.yaml snaps: - name: core channel: stable file: ${CORE_SNAP} EOF for snap in "$@"; do snap_name=${snap%/*} cat <> chroot/var/lib/snapd/seed/seed.yaml - name: ${snap_name} channel: stable EOF case ${snap} in */classic) echo " classic: true" >> chroot/var/lib/snapd/seed/seed.yaml;; esac echo -n " file: " >> chroot/var/lib/snapd/seed/seed.yaml (cd chroot/var/lib/snapd/seed; ls -1 ${snap_name}_*.snap) \ >> chroot/var/lib/snapd/seed/seed.yaml done mkdir -p chroot/var/lib/snapd/seed/snaps \ chroot/var/lib/snapd/seed/assertions mv chroot/var/lib/snapd/seed/*.assert \ chroot/var/lib/snapd/seed/assertions/ mv chroot/var/lib/snapd/seed/*.snap chroot/var/lib/snapd/seed/snaps/ } rm -f binary.success ( lb bootstrap "$@" Chroot chroot "dpkg-divert --quiet --add \ --divert /usr/sbin/update-initramfs.REAL --rename \ /usr/sbin/update-initramfs" cat > chroot/usr/sbin/update-initramfs <<'EOF' #! /bin/sh if [ $# != 1 ] || [ "$1" != -u ]; then exec update-initramfs.REAL "$@" fi echo "update-initramfs: diverted by livecd-rootfs (will be called later)" >&2 exit 0 EOF chmod +x chroot/usr/sbin/update-initramfs cat > config/hooks/999-undivert-update-initramfs.chroot <<'EOF' #! /bin/sh rm -f /usr/sbin/update-initramfs dpkg-divert --quiet --remove --rename /usr/sbin/update-initramfs EOF cat > config/hooks/fixvmlinuz.binary <<'EOF' #! /bin/sh kernel=$(ls binary/casper/vmlinuz-*-generic | grep -v efi | sort -r | head -1) kernel_efi=$(ls binary/casper/vmlinuz-* | grep efi | sort -r | head -1) if [ ! -z $kernel ]; then cp $kernel binary/casper/vmlinuz fi if [ ! -z $kernel_efi ]; then cp $kernel_efi binary/casper/vmlinuz.efi fi cp binary/casper/initrd.img*-generic binary/casper/initrd.lz EOF [ ! -e "/usr/share/isomaker/defaultsettings" ] || . "/usr/share/isomaker/defaultsettings" [ ! -e "auto/settings" ] || . auto/settings cat > pooltemplatevariables < config/hooks/generatepoolefi.binary <<'EOF' #! /bin/sh sed -i -f pooltemplatevariables binary/conf/distributions sed -i -f pooltemplatevariables binary/conf/updates rm pooltemplatevariables cd binary reprepro update reprepro retrack reprepro export cd .. EOF lb chroot "$@" echo "===== Checking size of /usr/share/doc =====" echo BEGIN docdirs (cd chroot && find usr/share/doc -maxdepth 1 -type d | xargs du -s | sort -nr) echo END docdirs rm chroot/etc/apt/sources.list.d/* || true rm -rf chroot/var/lib/apt/lists/lliurex.net* || true cp -r config/final_apt/* chroot/etc/apt/ 2>/dev/null || true if [ -e "config/seeded-snaps" ]; then assertions_dir="chroot/var/lib/snapd/seed/assertions" model_assertion="$assertions_dir/generic-classic.model" account_key_assertion="$assertions_dir/generic.account-key" account_assertion="$assertions_dir/generic.account" mkdir -p "$assertions_dir" snap known --remote model series=16 model=generic-classic brand-id=generic > "$model_assertion" account_key=$(sed -n -e's/sign-key-sha3-384: //p' < "$model_assertion") snap known --remote account-key public-key-sha3-384="$account_key" > "$account_key_assertion" account=$(sed -n -e's/account-id: //p' < "$account_key_assertion") snap known --remote account account-id=generic > "$account_assertion" snap_list=$(cat config/seeded-snaps) preinstall_snaps $snap_list fi # If the image pre-installs network-manager, let it manage all devices by # default. Installing NM on an existing system only manages wifi and wwan via # /usr/lib/NetworkManager/conf.d/10-globally-managed-devices.conf. When setting # the global backend to NM, netplan overrides that file. if [ -d chroot/usr/lib/NetworkManager ]; then echo "===== Enabling all devices in NetworkManager ====" mkdir -p chroot/etc/netplan cat < chroot/etc/netplan/01-network-manager-all.yaml # Let NetworkManager manage all devices on this system network: version: 2 renderer: NetworkManager EOF else echo "==== NetworkManager not installed ====" fi cp /usr/lib/live/build/lb_binary custom_binary cp /usr/lib/live/build/lb_binary_disk custom_binary_disk chmod +x custom_binary custom_binary_disk # Enabling custom_binary_disk sed -i -e 's%^lb binary_disk ${\*}%./custom_binary_disk ${*}%g' custom_binary # Fixing disk/info sed -i -e "s%Ubuntu%${DISTRIBUTION_NAME}%g" custom_binary_disk sed -i -e 's%^lb binary_iso ${\*}%auto/custombuildiso ${*}%g' custom_binary ./custom_binary "$@" touch binary.success ) 2>&1 | tee binary.log # bash has trouble with the build.sh sourcing arrangement at the top of this # file, so we use this cheap-and-cheerful approach rather than the more # correct 'set -o pipefail'. if [ -e binary.success ]; then rm -f binary.success else exit 1 fi # Link output files somewhere BuildLiveCD will be able to find them. PREFIX="livecd.$PROJECT${SUBARCH:+-$SUBARCH}" case $LB_INITRAMFS in casper) INITFS="casper" ;; live-boot) INITFS="live" ;; *) INITFS="boot" ;; esac for OUTPUT in ext2 ext3 ext4 manifest manifest-remove size squashfs; do [ -e "binary/$INITFS/filesystem.$OUTPUT" ] || continue ln "binary/$INITFS/filesystem.$OUTPUT" "$PREFIX.$OUTPUT" chmod 644 "$PREFIX.$OUTPUT" done for ISO in binary.iso binary.hybrid.iso; do [ -e "$ISO" ] || continue ln "$ISO" "$PREFIX.iso" chmod 644 "$PREFIX.iso" break done if [ -e "binary/$INITFS/filesystem.dir" ]; then (cd "binary/$INITFS/filesystem.dir/" && tar -c *) | \ gzip -9 --rsyncable > "$PREFIX.rootfs.tar.gz" chmod 644 "$PREFIX.rootfs.tar.gz" elif [ -e binary-tar.tar.gz ]; then cp -a binary-tar.tar.gz "$PREFIX.rootfs.tar.gz" fi # '--initramfs none' produces different manifest names. if [ -e "binary/$INITFS/filesystem.packages" ]; then ln "binary/$INITFS/filesystem.packages" "$PREFIX.manifest" chmod 644 "$PREFIX.manifest" fi if [ -e "binary/$INITFS/filesystem.packages-remove" ]; then # Not a typo, empty manifest-remove has a single LF in it. :/ if [ $(cat binary/$INITFS/filesystem.packages-remove | wc -c) -gt 1 ]; then ln "binary/$INITFS/filesystem.packages-remove" "$PREFIX.manifest-remove" chmod 644 "$PREFIX.manifest-remove" fi fi for FLAVOUR in $LB_LINUX_FLAVOURS; do if [ -z "$LB_LINUX_FLAVOURS" ] || [ "$LB_LINUX_FLAVOURS" = "none" ]; then continue fi if [ "$FLAVOUR" = "virtual" ]; then # The virtual kernel is named generic in /boot FLAVOUR="generic" fi KVERS="$( (cd "binary/$INITFS"; ls vmlinu?-* 2>/dev/null || true) | (fgrep -v .efi || true) | sed -n "s/^vmlinu.-\\([^-]*-[^-]*-$FLAVOUR\\)$/\\1/p" )" if [ -z "$KVERS" ]; then if [ -e "binary/$INITFS/vmlinuz" ]; then # already renamed by ubuntu-defaults-image break fi echo "No kernel output for $FLAVOUR!" >&2 exit 1 fi NUMKVERS="$(set -- $KVERS; echo $#)" if [ "$NUMKVERS" -gt 1 ]; then echo "Cannot handle more than one kernel for $FLAVOUR ($KVERS)!" >&2 exit 1 fi ln "binary/$INITFS/"vmlinu?-"$KVERS" "$PREFIX.kernel-$FLAVOUR" if [ -e "binary/$INITFS/"vmlinu?-"$KVERS.efi.signed" ]; then ln "binary/$INITFS/"vmlinu?-"$KVERS.efi.signed" "$PREFIX.kernel-$FLAVOUR.efi.signed" chmod 644 "$PREFIX.kernel-$FLAVOUR.efi.signed" fi chmod 644 "$PREFIX.kernel-$FLAVOUR" if [ -e "binary/$INITFS/initrd.img-$KVERS" ]; then ln "binary/$INITFS/initrd.img-$KVERS" "$PREFIX.initrd-$FLAVOUR" chmod 644 "$PREFIX.initrd-$FLAVOUR" fi done NUMFLAVOURS="$(set -- $LB_LINUX_FLAVOURS; echo $#)" if [ "$NUMFLAVOURS" = 1 ] && [ "$LB_LINUX_FLAVOURS" != "none" ]; then # only one kernel flavour if [ -e "binary/$INITFS/vmlinuz" ]; then ln "binary/$INITFS/vmlinuz" "$PREFIX.kernel" chmod 644 "$PREFIX.kernel" else ln -sf "$PREFIX.kernel-$LB_LINUX_FLAVOURS" "$PREFIX.kernel" fi if [ -e "binary/$INITFS/initrd.lz" ]; then ln "binary/$INITFS/initrd.lz" "$PREFIX.initrd" chmod 644 "$PREFIX.initrd" else ln -sf "$PREFIX.initrd-$LB_LINUX_FLAVOURS" "$PREFIX.initrd" fi fi