diff options
Diffstat (limited to 'build-hcloud-snapshot.sh')
| -rwxr-xr-x | build-hcloud-snapshot.sh | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/build-hcloud-snapshot.sh b/build-hcloud-snapshot.sh index 00ec32d..aff6c1c 100755 --- a/build-hcloud-snapshot.sh +++ b/build-hcloud-snapshot.sh @@ -12,7 +12,7 @@ set -o nounset set -o errexit export PACKER_LOG=1 -SCRIPTDIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P) +_SCRIPT_DIR=$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd) VERSION=7.9 ARCH=amd64 @@ -20,9 +20,9 @@ SSH_KEY="default-key" main() ( parse_args "$@" - img_path="${SCRIPTDIR}/openbsd-image/build/openbsd-${VERSION}-${ARCH}.raw" + img_path="${_SCRIPT_DIR}/openbsd-image/build/openbsd-${VERSION}-${ARCH}.raw" build_compressed_image "$img_path" - cd "$SCRIPTDIR/hcloud-snapshot/" + cd "$_SCRIPT_DIR/hcloud-snapshot/" packer init . packer build \ -var "hcloud_token=${HCLOUD_TOKEN:?}" \ @@ -36,6 +36,10 @@ main() ( parse_args() { while [ $# -gt 0 ]; do case "$1" in + -h | --help) + usage + exit 0 + ;; --version) VERSION="$2" shift 2 @@ -56,6 +60,22 @@ parse_args() { done } +usage() { + cat <<EOF +Usage: $(basename "$0") [OPTIONS] + +Create an OpenBSD snapshot in Hetzner Cloud. +Requires HCLOUD_TOKEN to be set in the environment. +Run ./build-openbsd-image.sh first to produce the local image. + +Options: + --version VERSION OpenBSD version (must match the built image) (default: $VERSION) + --arch ARCH Target architecture: amd64 or arm64 (default: $ARCH) + --ssh-key NAME Hetzner SSH key name to add to the snapshot (default: $SSH_KEY) + -h, --help Show this help message +EOF +} + build_compressed_image() ( if [ ! -e "$1.zst" ]; then zstd -T0 "$1" -o "$1.zst" |