summaryrefslogtreecommitdiff
path: root/packages/buildvm/setup.sh
blob: 49312bd3addfab82a8df14ea8cc7399aefa6e6b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/bash
# Create and configure an OpenBSD QEMU/KVM VM for native package builds.
#
# Fully automated via expect driving the serial console installer.
# The expect script is in install-expect.exp (separate file avoids
# bash/expect quoting issues with password prompts).
#
# Prerequisites: qemu-system-x86_64, expect, KVM (/dev/kvm)

set -e

VMDIR="$(cd "$(dirname "$0")" && pwd)"
DISK="$VMDIR/openbsd-build.qcow2"
OBSD_VERSION="7.8"
ISO="$VMDIR/install${OBSD_VERSION//./}.iso"
SSH_PORT=2222
RAM=1024
CPUS=2

if [ -f "$DISK" ]; then
    echo "Disk $DISK already exists. Delete it first to reinstall."
    exit 1
fi

# Download install ISO if not cached
if [ ! -f "$ISO" ]; then
    echo "Downloading OpenBSD $OBSD_VERSION install ISO..."
    curl -L -o "$ISO" "https://cdn.openbsd.org/pub/OpenBSD/$OBSD_VERSION/amd64/install${OBSD_VERSION//./}.iso"
fi

echo "Creating ${DISK}..."
qemu-img create -f qcow2 "$DISK" 4G

echo ""
echo "Starting automated OpenBSD install (takes ~5 minutes)..."
echo ""

expect "$VMDIR/install-expect.exp" "$DISK" "$ISO" "$RAM" "$CPUS" "$SSH_PORT"

echo ""
echo "OpenBSD install complete. Now run: $VMDIR/provision.sh"