#!/bin/sh # # DESCRIPTION: # Create an OpenBSD image with Packer and QEMU. # # USAGE: # ./build-openbsd-image.sh 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 SSH_KEY="$HOME/.ssh/id_rsa.pub" DISKLABEL_TEMPLATE="" export PACKER_LOG=1 main() ( parse_args "$@" cd openbsd-image/ require_readable_file "$SSH_KEY" if [ -n "$DISKLABEL_TEMPLATE" ]; then require_readable_file "$DISKLABEL_TEMPLATE" fi if [ -d build/ ]; then printf 'Build directory exists. Must delete before re-building. Proceed? (y/N)' read -r answer case $answer in [yY]) echo "Removing build/.." rm -r build/ ;; *) echo "Aborting.." exit 0 ;; esac fi packer init . packer build \ -only "qemu.openbsd-$ARCH" \ -var "arch=$ARCH" \ -var "disk_size=$DISK_SIZE_GB" \ -var "version=$VERSION" \ -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 ;; --arch) ARCH="$2" shift 2 ;; --disk-size-gb) DISK_SIZE_GB="$2" shift 2 ;; --ssh-key) SSH_KEY="$2" shift 2 ;; --disklabel-template) DISKLABEL_TEMPLATE="$(realpath "$2")" shift 2 ;; *) echo "Unknown option: $1" shift ;; esac done } usage() { cat <