diff --git a/scripts/build_image/build_alpine.bash b/scripts/build_image/build_alpine.bash index d6c46f7..c4dc69b 100755 --- a/scripts/build_image/build_alpine.bash +++ b/scripts/build_image/build_alpine.bash @@ -7,12 +7,27 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" ############## Setup ######################### function cleanup { + for f in "${jails[@]}"; do + >&2 echo "Stopping jail $f" + sudo jail -r "$f" + done + for f in "${mountedfolders[@]}"; do + >&2 echo "Unmounting folder $f" + umount "$f" + done + for f in "${memorydevices[@]}"; do + >&2 echo "Removing memory device $f" + mdconfig -d -u "$f" + done for f in "${folders[@]}"; do >&2 echo "Deleting $f" - rm -rf "$f" + sudo rm -rf "$f" done } folders=() +jails=() +memorydevices=() +mountedfolders=() for sig in EXIT INT QUIT HUP TERM; do trap "set +e; cleanup" "$sig" done @@ -123,20 +138,6 @@ function precheck { done } -function make_chroot { - bsdtar -C "$chroot" -xpf "${download_directory}/${ALPINE_TARBALL}" - - # Steal the DNS info from the host - (umask 022 && resolvconf -l > "${chroot}/etc/resolv.conf") - - # Enter the jail - # install mkinitfs - sudo jail -c path="$chroot" ip4=inherit ip6=inherit host=inherit allow.raw_sockets=true command=/bin/sh - - # Remove the resolv.conf file since it should get populated via dhcp - rm "${chroot}/etc/resolv.conf" -} - function download_alpine { if [ "$LOCAL_DEV" == "true" ] && [ -e "${NETIZEN_CACHE}/${ALPINE_TARBALL}" ]; then # Cache for local development to avoid stressing alpine servers @@ -156,6 +157,43 @@ function download_alpine { gpg --no-default-keyring --keyring "$keyring" --trust-model always --verify <(cat <<<"$ALPINE_SIGNATURE") "${download_directory}/${ALPINE_TARBALL}" } +function make_chroot { + bsdtar -C "$chroot" -xpf "${download_directory}/${ALPINE_TARBALL}" + + # Steal the DNS info from the host + (umask 022 && resolvconf -l > "${chroot}/etc/resolv.conf") + + # Enter the jail + # install mkinitfs + jid=$(sudo jail -c -i path="$chroot" ip4=inherit ip6=inherit host=inherit allow.raw_sockets=true persist) + jails+=("$jid") + + sudo jexec "$jid" apk add --no-cache mkinitfs docker linux-virt + sudo jexec "$jid" apk add --no-cache --repository 'http://dl-cdn.alpinelinux.org/alpine/edge/testing' refind + sudo jexec "$jid" mkinitfs -c /etc/mkinitfs/mkinitfs.conf -b / 5.15.16-0-virt + sudo jexec "$jid" mkdir /boot/efi + sudo jexec "$jid" cp -r /usr/share/refind /boot/efi/boot + sudo jexec "$jid" cp /boot/efi/boot/refind_x64.efi /boot/efi/boot/bootx64.efi + (umask 022 && sudo tee "${chroot}/boot/refind_linux.conf" <