scripts/appcast-add.sh
40 lines · 2043 bytes · executable
1#!/bin/sh
2# Adds a release to the Sparkle appcast, newest first: signs the DMG with the EdDSA key in the
3# keychain (sign_update, from the Sparkle package in .build/artifacts) and writes the item.
4# Usage: scripts/appcast-add.sh <appcast.xml> <version> <build> <dmg> <notes-file>
5set -eu
6
7appcast="${1:?usage: appcast-add.sh <appcast.xml> <version> <build> <dmg> <notes-file>}"
8version="${2:?version}"
9build="${3:?build}"
10dmg="${4:?dmg}"
11notes="${5:?notes-file}"
12cd "$(dirname "$0")/.."
13
14! grep -q "<sparkle:shortVersionString>$version<" "$appcast" || { echo "$appcast already has $version." >&2; exit 1; }
15# SIGN_UPDATE names another signer, for a dry run without the key.
16sign_update="${SIGN_UPDATE:-$(find .build/artifacts -path '*/Sparkle/bin/sign_update' | head -1)}"
17[ -n "$sign_update" ] || { echo "sign_update not in .build/artifacts; swift build fetches Sparkle." >&2; exit 1; }
18signature="$("$sign_update" "$dmg")" # sparkle:edSignature="..." length="..."
19date="$(LC_ALL=C date -R)"
20name="$(basename "$dmg")"
21
22item="$(mktemp)"
23{
24 echo " <item>"
25 echo " <title>orgstar $version</title>"
26 echo " <link>https://gitbay.org/krz/orgstar/releases/tag/v$version</link>"
27 echo " <sparkle:version>$build</sparkle:version>"
28 echo " <sparkle:shortVersionString>$version</sparkle:shortVersionString>"
29 echo " <sparkle:minimumSystemVersion>26.0</sparkle:minimumSystemVersion>"
30 echo " <pubDate>$date</pubDate>"
31 echo " <description><![CDATA[$(cat "$notes")]]></description>"
32 echo " <enclosure url=\"https://gitbay.org/krz/orgstar/releases/download/v$version/$name\" type=\"application/octet-stream\" $signature/>"
33 echo " </item>"
34} > "$item"
35# After the channel's <link>, so the newest release comes first.
36awk -v item="$item" 'BEGIN { done = 0 } { print } /<\/link>/ && !done { while ((getline line < item) > 0) print line; done = 1 }' "$appcast" > "$appcast.new"
37mv "$appcast.new" "$appcast"
38rm -f "$item"
39xmllint --noout "$appcast"
40echo "$appcast: added $version"