#!/bin/sh set -o nounset set -o errexit _SCRIPT_DIR=$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd) . "$_SCRIPT_DIR/lib.sh" CPU="$(get_ncpus)" MEM=$(($(get_memsize 'mb') / 2)) DISPLAY='' TMP='' _ARCH_X86="x86_64" _ARCH_ARM="arm64" ARCH="$_ARCH_X86" _DISKFMT_RAW="raw" _DISKFMT_QCOW2="qcow2" DISKFMT="$_DISKFMT_RAW" main() { parse_args "$@" _ARCH_LABEL=amd64 [ "$ARCH" = "$_ARCH_ARM" ] && _ARCH_LABEL=arm64 if [ "$DISKFMT" = "$_DISKFMT_RAW" ]; then DRIVE="file=$_SCRIPT_DIR/build/openbsd-8.0-$_ARCH_LABEL.raw,if=virtio,format=raw" elif [ "$DISKFMT" = "$_DISKFMT_QCOW2" ]; then DRIVE="file=$_SCRIPT_DIR/build/openbsd-8.0-$_ARCH_LABEL.qcow2,if=virtio,format=qcow2" fi if [ "$ARCH" = "$_ARCH_X86" ]; then # shellcheck disable=SC2086 qemu-system-x86_64 \ -machine type=q35,accel=tcg \ -cpu max \ -m "$MEM" \ -smp "$CPU" \ ${TMP:+-snapshot} \ ${DISPLAY:+-display cocoa} \ -netdev user,id=net0,hostfwd=tcp::2222-:22 \ -device virtio-net,netdev=net0 \ -drive $DRIVE fi } parse_args() { while [ $# -gt 0 ]; do case "$1" in -h | --help) usage exit 0 ;; --mem) MEM="$2" shift 2 ;; --cpu) CPU="$2" shift 2 ;; --arch) ARCH="$2" shift 2 ;; --disk-fmt) DISKFMT="$2" shift 2 ;; --display) DISPLAY=1 shift 1 ;; --tmp) TMP=1 shift 1 ;; *) echo "Unknown option: $1" shift ;; esac done _parse_args_arch_options="$_ARCH_X86 $_ARCH_ARM" if ! validate_enum "$ARCH" "$_parse_args_arch_options"; then echo "[ERROR] Expected one of: '$_parse_args_arch_options'. Got '$ARCH'." >&2 return 1 fi _parse_args_diskfmt_options="$_DISKFMT_RAW $_DISKFMT_QCOW2" if ! validate_enum "$DISKFMT" "$_parse_args_diskfmt_options"; then echo "[ERROR] Expected one of: '$_parse_args_diskfmt_options'. Got '$DISKFMT'." >&2 return 1 fi } main "$@"