diff options
| author | Eugene Triguba <hello@eugenetriguba.com> | 2026-10-03 08:52:49 -0700 |
|---|---|---|
| committer | Eugene Triguba <hello@eugenetriguba.com> | 2026-10-11 18:33:35 -0700 |
| commit | de40b1e69eaabac3ca01774fa3a4e7abc463ac7c (patch) | |
| tree | 9e6ba70dd1f982f851c84a1aa542c1a28a55010f /build-openbsd-image.sh | |
| parent | Add prompt to remove build directory if it exists (diff) | |
| download | site-server-images-de40b1e69eaabac3ca01774fa3a4e7abc463ac7c.zip | |
Customize the disk layout via disklabel templates
Diffstat (limited to 'build-openbsd-image.sh')
| -rwxr-xr-x | build-openbsd-image.sh | 44 |
1 files changed, 34 insertions, 10 deletions
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 <<EOF +Usage: $(basename "$0") [OPTIONS] + +Create an OpenBSD image with Packer and QEMU. + +Options: + --version VERSION OpenBSD version to build (default: $VERSION) + --arch ARCH Target architecture: amd64 or arm64 (default: $ARCH) + --disk-size-gb SIZE Disk size in GB (default: $DISK_SIZE_GB) + --ssh-key PATH Path to SSH key (default: $SSH_KEY) + --disklabel-template PATH Path to a custom disklabel autopartition template. + If omitted, uses OpenBSD's default auto layout. + -h, --help Show this help message +EOF } main "$@" |