diff options
| author | Eugene Triguba <hello@eugenetriguba.com> | 2026-09-22 17:00:53 -0700 |
|---|---|---|
| committer | Eugene Triguba <hello@eugenetriguba.com> | 2026-10-11 18:33:35 -0700 |
| commit | c9cfdbf86f2bf620c986abb2f67dcaabf5b01047 (patch) | |
| tree | 23be01d9eb5cee38e1919e83d633ceff977f8f78 /build-hcloud-snapshot.sh | |
| parent | Remove need for explicit memory var override (diff) | |
| download | site-server-images-c9cfdbf86f2bf620c986abb2f67dcaabf5b01047.zip | |
Add support for hcloud openbsd image snapshot
Diffstat (limited to 'build-hcloud-snapshot.sh')
| -rwxr-xr-x | build-hcloud-snapshot.sh | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/build-hcloud-snapshot.sh b/build-hcloud-snapshot.sh new file mode 100755 index 0000000..40f3dcb --- /dev/null +++ b/build-hcloud-snapshot.sh @@ -0,0 +1,69 @@ +#!/bin/sh +# +# DESCRIPTION: +# Create a OpenBSD snapshot in Hetzner Cloud. +# +# USAGE: +# ./build-openbsd-image.sh +# export HCLOUD_TOKEN="xxxxx-xxxxx" +# ./build-hcloud-snapshot.sh +# +set -o nounset +set -o errexit + +export PACKER_LOG=1 +SCRIPTDIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P) + +VERSION=7.9 +ARCH=amd64 +PUBLIC_SSH_KEY="$HOME/.ssh/id_rsa.pub" + +main() ( + parse_args "$@" + img_path="${SCRIPTDIR}/openbsd-image/build/openbsd-${VERSION}-${ARCH}.raw" + build_compressed_image "$img_path" + cd "$SCRIPTDIR/hcloud-snapshot/" + packer init . + packer build \ + -var "hcloud_token=${HCLOUD_TOKEN:?}" \ + -var "image_path=${img_path}.zst" \ + -var "version=$VERSION" \ + -var "arch=$ARCH" \ + -var "ssh_key=$(get_ssh_key_name "$PUBLIC_SSH_KEY")" \ + . +) + +parse_args() { + while [ $# -gt 0 ]; do + case "$1" in + --version) + VERSION="$2" + shift 2 + ;; + --arch) + ARCH="$2" + shift 2 + ;; + --public-ssh-key) + PUBLIC_SSH_KEY="$2" + shift 2 + ;; + *) + echo "Unknown option: $1" + shift + ;; + esac + done +} + +build_compressed_image() ( + if [ ! -e "$1.zst" ]; then + zstd -T0 "$1" -o "$1.zst" + fi +) + +get_ssh_key_name() { + awk '{print $3}' "$1" +} + +main "$@" |