From c9353f173622002fe9e21e28c11b97daa1d79ca4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rn=20=C3=85ne=20de=20Jong?= Date: Fri, 27 May 2022 22:13:42 +0200 Subject: [PATCH] Install firstboot script through ports --- .../freebsd-build-opennebula-image.sh | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/opennebula-images/freebsd-build-opennebula-image.sh b/opennebula-images/freebsd-build-opennebula-image.sh index 3081154..d801698 100755 --- a/opennebula-images/freebsd-build-opennebula-image.sh +++ b/opennebula-images/freebsd-build-opennebula-image.sh @@ -16,14 +16,11 @@ IMAGE_PATH_UFS="freebsd-ufs-$RELEASE-$(date -I).img.qcow2" IMAGE_SIZE=10G DIST_BASE="https://download.freebsd.org/ftp/releases/$ARCH/$RELEASE" -CLOUDSETUP_COMMIT=4ac15b8647d5525048c5faa5fd4b28491905d000 -CLOUDSETUP_URL="https://git.sr.ht/~jornane/cloudsetup/archive/$CLOUDSETUP_COMMIT.tar.gz" ZPOOL=zroot ZPOOL_TMP="zinstalling" ZFSTARGET="$(mktemp -d /var/tmp/zfsbuild.XXXXX)" UFSTARGET="$(mktemp -d /var/tmp/ufsbuild.XXXXX)" -CLOUDSETUP_WORK="$(mktemp -d /var/tmp/cloudsetup.XXXXX)" if zpool list -Ho name "$ZPOOL_TMP" 2>/dev/null; then echo "The pool $ZPOOL_TMP is already imported." >&2 @@ -59,7 +56,18 @@ then env ASSUME_ALWAYS_YES=YES pkg install -y qemu-tools fi -fetch -qo- "$CLOUDSETUP_URL" | tar -C "$CLOUDSETUP_WORK" --strip-components 1 -xzf- +portsnap fetch +if [ -f /usr/ports/README ] +then + portsnap update || portsnap extract +else + portsnap extract +fi +make -C /usr/ports/sysutils/firstboot-cloudsetup clean package +CLOUDSETUP_VERSION="$(fgrep VERSION /usr/ports/sysutils/firstboot-cloudsetup/Makefile | cut -f2- | tr -d \\t)" +CLOUDSETUP_PKG="/usr/ports/sysutils/firstboot-cloudsetup/work/pkg/firstboot-cloudsetup-${CLOUDSETUP_VERSION}.pkg" +tar -tzf "$CLOUDSETUP_PKG" >/dev/null # check that it's a valid tar, or we crash due to set -e +# tar -t lists the contents of a tar file, but does not extract ufsdisk="$(mktemp /var/tmp/ufsdisk.XXXXX)" truncate -s 6G "$ufsdisk" @@ -132,7 +140,11 @@ mount_nullfs /tmp "$UFSTARGET/tmp" mount_nullfs /var/tmp "$UFSTARGET/var/tmp" # Install the first-boot script that configures the network and ssh key -make -C "$CLOUDSETUP_WORK/" PREFIX="$UFSTARGET/usr/local" install +# We must use --rootdir and not --chroot, because the file is read from within the chroot +# --automatic means that the package is considered to be installed "automatically", +# aka as a dependency of something, so pkg autoremove will remove it. +# We do not run pkg autoremove ourselves, that's up to the administrator. +pkg --rootdir "$UFSTARGET" add --automatic "$CLOUDSETUP_PKG" # Configure new system. touch "$UFSTARGET/firstboot"