Install firstboot script through ports

This commit is contained in:
Jørn Åne de Jong 2022-05-27 22:13:42 +02:00 committed by Nico Schottelius
parent 906754e841
commit c9353f1736
1 changed files with 17 additions and 5 deletions

View File

@ -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"