From de40b1e69eaabac3ca01774fa3a4e7abc463ac7c Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sat, 3 Oct 2026 08:52:49 -0700 Subject: Customize the disk layout via disklabel templates --- build-openbsd-image.sh | 44 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) (limited to 'build-openbsd-image.sh') diff --git a/build-openbsd-image.sh b/build-openbsd-image.sh index faa6bc1..0e14e54 100755 --- a/build-openbsd-image.sh +++ b/build-openbsd-image.sh @@ -8,16 +8,22 @@ set -o nounset set -o errexit +_SCRIPT_DIR=$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd) +. "$_SCRIPT_DIR/lib.sh" + VERSION=7.9 ARCH=amd64 DISK_SIZE_GB=36 -PUBLIC_SSH_KEY="$HOME/.ssh/id_rsa.pub" +SSH_KEY="$HOME/.ssh/id_rsa.pub" +DISKLABEL_TEMPLATE="" export PACKER_LOG=1 main() ( parse_args "$@" cd openbsd-image/ + require_readable_file "$SSH_KEY" + require_readable_file "$DISKLABEL_TEMPLATE" if [ -d build/ ]; then printf 'Build directory exists. Must delete before re-building. Proceed? (y/N)' read -r answer @@ -38,14 +44,19 @@ main() ( -var "arch=$ARCH" \ -var "disk_size=$DISK_SIZE_GB" \ -var "version=$VERSION" \ - -var "ssh_key=$(cat "$PUBLIC_SSH_KEY")" \ + -var "ssh_key=$(cat "$SSH_KEY")" \ -var "cpus=$(get_ncpus)" \ + ${DISKLABEL_TEMPLATE:+-var "disklabel_template=$(cat "$DISKLABEL_TEMPLATE")"} \ . ) parse_args() { while [ $# -gt 0 ]; do case "$1" in + -h | --help) + usage + exit 0 + ;; --version) VERSION="$2" shift 2 @@ -58,8 +69,12 @@ parse_args() { DISK_SIZE_GB="$2" shift 2 ;; - --public-ssh-key) - PUBLIC_SSH_KEY="$2" + --ssh-key) + SSH_KEY="$2" + shift 2 + ;; + --disklabel-template) + DISKLABEL_TEMPLATE="$(realpath "$2")" shift 2 ;; *) @@ -70,12 +85,21 @@ parse_args() { done } -get_ncpus() { - if [ "$(uname -s)" = 'Darwin' ]; then - sysctl -n hw.ncpu - else - nproc - fi +usage() { + cat <