[PATCH builds.sr.ht v2] images/freebsd: add a custom install script

Message ID
Download raw message
Patch +76 -64
From: emersion <contact@emersion.fr>

 images/freebsd/12.0/genimg |   2 +-
 images/freebsd/genimg      | 103 +++++++++++++++++++++++++++----------
 images/freebsd/install     |  35 -------------
 3 files changed, 76 insertions(+), 64 deletions(-)
 delete mode 100644 images/freebsd/install

diff --git a/images/freebsd/12.0/genimg b/images/freebsd/12.0/genimg
index b85d949..13f136c 100755
--- a/images/freebsd/12.0/genimg
+++ b/images/freebsd/12.0/genimg
@@ -1,3 +1,3 @@
-export release=12.0
+export release=12.0-RELEASE
 exec ../genimg "$@"
diff --git a/images/freebsd/genimg b/images/freebsd/genimg
index 930b09f..74b6632 100755
--- a/images/freebsd/genimg
+++ b/images/freebsd/genimg
@@ -3,42 +3,89 @@
 echo "$release" >/dev/null # fail on -u if release unset
-export DISTRIBUTIONS="kernel.txz base.txz ports.txz"
-export BSDINSTALL_DISTSITE="https://download.freebsd.org/ftp/releases/$arch/$release/"
-export BSDINSTALL_DISTDIR="/usr/freebsd-dist/$arch/$release"
-export BSDINSTALL_LOG="/tmp/bsdinstall.log"
+dist_files="kernel.txz base.txz"
+mkdir -p "$dist_dir"
+for f in $dist_files
+	fetch -m -o "$dist_dir/$f" "$dist_base/$f"
 cleanup() {
-	cat "$BSDINSTALL_LOG" || true
-	# The order here is important if you don't want to hose your mounts
-	umount -f /mnt/dev/pts 2>/dev/null || true
-	umount -f /mnt/dev/shm 2>/dev/null || true
-	umount -f /mnt/dev 2>/dev/null || true
-	umount -f /mnt/proc 2>/dev/null || true
-	umount -f /mnt/run 2>/dev/null || true
-	umount -f /mnt/sys 2>/dev/null || true
-	umount -f /mnt/boot 2>/dev/null || true
-	umount -f /mnt 2>/dev/null || true 
-	mdconfig -d -u 0
+	sync || true
+	umount /mnt || true
+	mdconfig -du md0 || true
-# qemu-nbd is not supported, so we just create a raw image and convert it
-qemu-img create -f raw root.img.raw 6G
-mdconfig -a -t vnode -f root.img.raw -u 0
 trap cleanup EXIT
-export nonInteractive=YES
-bsdinstall distfetch
-bsdinstall checksum
-bsdinstall script ./install
+rm -f disk.img
+truncate -s 6G disk.img
+mdconfig -a -t vnode -f disk.img -u md0
+gpart create -s gpt /dev/md0
+gpart add -t freebsd-boot -l bootfs -b 40 -s 512K md0
+gpart bootcode -b /boot/pmbr -p /boot/gptboot -i 1 md0
+gpart add -t freebsd-ufs -l rootfs -b 1M -s 5G md0
+newfs -U /dev/md0p2
+mount /dev/md0p2 /mnt
+for f in $dist_files
+	tar -C /mnt -xJf "$dist_dir/$f"
+echo "/dev/ada0p2 / ufs rw,noatime 1 1" >/mnt/etc/fstab
+touch /mnt/firstboot
+echo 'autoboot_delay="-1"' >>/mnt/boot/loader.conf
+cat >>/mnt/etc/rc.conf <<EOF
+ifconfig_em0="inet netmask"
+echo "nameserver" >/mnt/etc/resolv.conf
+tzsetup -s -C /mnt UTC
+cat >>/mnt/etc/ssh/sshd_config <<EOF
+PermitRootLogin yes
+PasswordAuthentication yes
+PermitEmptyPasswords yes
+mkdir -p /mnt/usr/local/etc/pkg/repos/
+cat >/mnt/usr/local/etc/pkg/repos/FreeBSD.conf <<EOF
+FreeBSD: {
+	url: pkg+http://pkg.FreeBSD.org/\$\{ABI\}/latest
+	enabled: yes
+/usr/sbin/freebsd-update -b /mnt \
+	--currently-running 12.0-RELEASE \
+	--not-running-from-cron \
+	fetch install \
+	>/dev/null
+env ASSUME_ALWAYS_YES=YES pkg -c /mnt bootstrap -f
+# TODO: remove bash
+# Subversion is required for ports
+env ASSUME_ALWAYS_YES=YES pkg -c /mnt install git bash sudo curl subversion
+svn checkout -q https://svn.FreeBSD.org/ports/head /mnt/usr/ports
+pw -R /mnt groupadd sudo
+pw -R /mnt useradd -n build -u 1000 -s /usr/local/bin/bash -m -w none -G sudo
+echo "%sudo ALL=(ALL) NOPASSWD: ALL" >>/mnt/usr/local/etc/sudoers
-trap - EXIT
+trap : EXIT
-qemu-img convert -f raw -O qcow2 root.img.raw root.img.qcow2
-rm root.img.raw
+qemu-img convert -f raw -O qcow2 disk.img root.img.qcow2
+rm disk.img
 # Filesystem will be enlarged by growfs(7) on next startup
 qemu-img resize root.img.qcow2 16G
diff --git a/images/freebsd/install b/images/freebsd/install
deleted file mode 100644
index f9565df..0000000
--- a/images/freebsd/install
+++ /dev/null
@@ -1,35 +0,0 @@
-PARTITIONS="md0 GPT { 512K freebsd-boot, 2G freebsd-swap, auto freebsd-ufs / }"
-DISTRIBUTIONS="base.txz kernel.txz ports.txz"
-#!/bin/sh -eux
-sysrc ntpd_enable=YES
-sysrc sshd_enable=YES
-sysrc growfs_enable=YES
-sysrc 'ifconfig_em0="inet netmask"'
-sysrc 'defaultrouter=""'
-echo "nameserver" >/etc/resolv.conf
-echo 'autoboot_delay="-1"' >>/boot/loader.conf
-# Device names at runtime are different from the ones at install time
-sed -e s:/dev/md0:/dev/ada0: -i .orig /etc/fstab
-# Run firstboot scripts on next startup
-touch /firstboot
-cat <<EOF >>/etc/ssh/sshd_config
-PermitRootLogin yes
-PasswordAuthentication yes
-PermitEmptyPasswords yes
-ln -sf /usr/share/zoneinfo/UTC /etc/localtime
-# TODO: remove bash
-pkg install -y git bash sudo curl
-echo "build:1000:::::::/usr/local/bin/bash:" | adduser -w none -f -
-pw groupadd sudo
-pw groupmod sudo -M build
-echo "%sudo ALL=(ALL) NOPASSWD: ALL" >>/usr/local/etc/sudoers