#!/bin/sh # Publish this region's commissioning image as assets of a Gitea release, so new # installations download it (bootstrap.sh --image-url .../releases/download/TAG). # GITEA_TOKEN=... ./publish-image.sh v0.2.0 [https://gitea.example/api/v1/repos/OWNER/REPO] # Files are uploaded as commissioning-{vmlinuz,initrd.img,filesystem.squashfs,SHA256SUMS}. set -eu TAG=${1:?usage: publish-image.sh TAG [API]} API=${2:-https://gitea.mynodes.xyz/api/v1/repos/ilker/rollcall} IMG=${IMG:-/srv/rollcall/image} : "${GITEA_TOKEN:?set GITEA_TOKEN (write:repository)}" HDR=$(mktemp); trap 'rm -f "$HDR"' EXIT printf 'Authorization: token %s\n' "$GITEA_TOKEN" > "$HDR" # not on curl's command line (ps) cd "$IMG" # build-image.sh writes SHA256SUMS; check it, or make it for an image without one if [ -f SHA256SUMS ]; then sha256sum -c --quiet SHA256SUMS; else sha256sum vmlinuz initrd.img filesystem.squashfs > SHA256SUMS; fi id=$(curl -fsS -H "@$HDR" "$API/releases/tags/$TAG" | python3 -c 'import json,sys;print(json.load(sys.stdin)["id"])') existing=$(curl -fsS -H "@$HDR" "$API/releases/$id/assets" | python3 -c 'import json,sys;[print(a["id"],a["name"]) for a in json.load(sys.stdin)]') for f in vmlinuz initrd.img filesystem.squashfs SHA256SUMS; do name=commissioning-$f old=$(echo "$existing" | awk -v n="$name" '$2==n{print $1}') [ -n "$old" ] && curl -fsS -X DELETE -H "@$HDR" "$API/releases/$id/assets/$old" >/dev/null echo "uploading $name ($(du -h "$f" | cut -f1))" curl -fsS -H "@$HDR" -F "attachment=@$f" "$API/releases/$id/assets?name=$name" >/dev/null done echo "done: bootstrap.sh --image-url ${API%/api/v1/repos/*}/$(echo "$API" | sed 's#.*/repos/##')/releases/download/$TAG"