The image job built as root and uploaded as the deploy user, so publish-image.sh could not write SHA256SUMS (v0.3.0's image job failed). The job hands the directory over after the build, and publish-image.sh checks the SHA256SUMS build-image.sh wrote instead of rewriting it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
26 lines
1.7 KiB
Bash
Executable File
26 lines
1.7 KiB
Bash
Executable File
#!/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"
|