#!/bin/sh -eux
set -o pipefail
cd "$(dirname "$0")"

# work around PR281520 zfs panic
curl -s https://download.freebsd.org/ftp/snapshots/arm64/aarch64/15.0-CURRENT/base.txz -o - | tar xzpf - -C /tmp
# back to sanity

# re-enable FreeBSD initial boot loader
sed -EI -e "/(logo|beastie)/d" /boot/loader.conf

# enable ssh as root again via pubkey
sed -EI -e s/.+ssh-/ssh-/ /root/.ssh/authorized_keys
cat keys/*.pub | tee -a /root/.ssh/authorized_keys

# more packages
pkg upgrade -yr FreeBSD
pkg install -Uyr FreeBSD net/mosh sysutils/tmux \
	editors/neovim devel/git@lite \
	ftp/curl www/gurl textproc/jq \
	textproc/ripgrep sysutils/fd \
	sysutils/htop sysutils/podman-suite \
	benchmarks/wrk

# tmpfs
echo "tmpfs /tmp tmpfs rw,mode=01777,size=1g 0 0" | tee -a /etc/fstab
zfs destroy -fr zroot/tmp

# preserve for eternity
zfs snapshot -r zroot@post-deploy
# notify the world that box is ready
curl -sd "$(hostname -s): $(curl -s jsonip.com | jq -r .ip)" ntfy.sh/eurojails
shutdown -r +5s

