Files
OrcaSlicer/scripts/sparkle_appcast.sh
Lam Wei Lun e38aef0f33 Drop the Nightly update channel and serve the appcast from Cloudflare KV
The macOS update feed moves from GitHub Pages to the orcaslicer_updater
worker's Cloudflare KV, served at
https://check-version.orcaslicer.com/appcast.xml. publish_appcast.yml
uploads the generated feed to the KV namespace instead of pushing to
gh-pages, and version.inc advertises the new URL.

The Nightly channel is removed everywhere: UpdateChannel::Nightly and its
resolver branches, the Preferences option, the helper and GUI labels, the
skip_artifact setting, the nightly appcast CI job, and the docs. Only
Stable and Pre-Release remain; a -dev version counts as Pre-Release.
2026-12-04 20:10:13 +08:00

190 lines
6.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# Build a signed Sparkle appcast from a directory of DMGs.
#
# The Sparkle release that deps/deps-macos.cmake pins also ships
# bin/generate_appcast, so the tool is the same version as the framework and is
# checked against the same SHA256. The version and hash are read from that file
# instead of being repeated here.
#
# generate_appcast merges an existing feed only when it is already at the
# output path; with -o the output is what it reads from. The live feed is
# therefore written there first and gains the new entries.
#
# Runs on macOS: it mounts each DMG with hdiutil to check its bundle.
#
# Usage:
# sparkle_appcast.sh [--channel NAME] <dmg-dir> <download-url-prefix> \
# <output.xml> <ed-key-file>
set -euo pipefail
die() {
echo "sparkle_appcast: $*" >&2
exit 1
}
usage() {
echo "usage: sparkle_appcast.sh [--channel NAME] <dmg-dir> <download-url-prefix> <output.xml> <ed-key-file>"
}
# The signing key is read by generate_appcast, never echoed. set -x would print
# the command line but not the key's contents; still, do not enable it here.
channel=
while [[ $# -gt 0 ]]; do
case "$1" in
--channel)
[[ $# -ge 2 ]] || die "--channel needs a value"
channel=$2
shift 2
;;
-h|--help)
usage
exit 0
;;
--)
shift
break
;;
-*)
die "unknown option: $1"
;;
*)
break
;;
esac
done
[[ $# -eq 4 ]] || { usage >&2; exit 2; }
dmg_dir=$1
url_prefix=$2
output=$3
key_file=$4
[[ -d $dmg_dir ]] || die "not a directory: $dmg_dir"
[[ -s $key_file ]] || die "private key file is missing or empty: $key_file"
# Sparkle joins the prefix and the archive name, so the slash is required.
[[ $url_prefix == */ ]] || url_prefix="$url_prefix/"
repo_root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
deps_file="$repo_root/deps/deps-macos.cmake"
[[ -f $deps_file ]] || die "not found: $deps_file"
sparkle_version=$(sed -n 's/^set(SPARKLE_VERSION "\([^"]*\)".*/\1/p' "$deps_file")
sparkle_sha256=$(sed -n 's/^set(SPARKLE_SHA256 "\([^"]*\)".*/\1/p' "$deps_file")
[[ -n $sparkle_version && -n $sparkle_sha256 ]] \
|| die "could not read SPARKLE_VERSION and SPARKLE_SHA256 from $deps_file"
work_dir=$(mktemp -d "${TMPDIR:-/tmp}/sparkle-appcast.XXXXXX")
mount_dir=
cleanup() {
if [[ -n $mount_dir ]]; then
hdiutil detach "$mount_dir" -quiet >/dev/null 2>&1 || true
rm -rf -- "${mount_dir:?}"
fi
rm -rf -- "${work_dir:?}"
}
trap cleanup EXIT
sha256_of() {
if command -v shasum >/dev/null 2>&1; then
shasum -a 256 "$1" | awk '{print $1}'
else
sha256sum "$1" | awk '{print $1}'
fi
}
tool_dir="${SPARKLE_APPCAST_CACHE:-${TMPDIR:-/tmp}/sparkle-appcast-${sparkle_version}}"
tool="$tool_dir/bin/generate_appcast"
if [[ ! -x $tool ]]; then
archive="$work_dir/Sparkle-${sparkle_version}.tar.xz"
url="https://github.com/sparkle-project/Sparkle/releases/download/${sparkle_version}/Sparkle-${sparkle_version}.tar.xz"
echo "Fetching $url"
curl -fsSL --retry 3 --retry-all-errors -o "$archive" "$url" \
|| die "could not download $url"
actual=$(sha256_of "$archive")
[[ $actual == "$sparkle_sha256" ]] \
|| die "Sparkle archive SHA256 is $actual, expected $sparkle_sha256"
mkdir -p "$tool_dir"
tar -xf "$archive" -C "$tool_dir" ./bin/generate_appcast \
|| die "could not extract bin/generate_appcast"
fi
[[ -x $tool ]] || die "Sparkle archive did not provide bin/generate_appcast"
# plutil rather than defaults: defaults reads the live user's domain, not the
# plist inside a mounted image.
plist_value() {
local plist=$1 key=$2 name value
name=$(basename "$3")
if ! value=$(plutil -extract "$key" raw -o - "$plist" 2>/dev/null); then
die "$name: Info.plist has no $key"
fi
[[ -n $value ]] || die "$name: Info.plist has an empty $key"
}
shopt -s nullglob
dmgs=("$dmg_dir"/*.dmg)
shopt -u nullglob
[[ ${#dmgs[@]} -gt 0 ]] || die "no .dmg files in $dmg_dir"
for dmg in "${dmgs[@]}"; do
dmg_name=$(basename "$dmg")
mount_dir=$(mktemp -d "${TMPDIR:-/tmp}/sparkle-mount.XXXXXX")
hdiutil attach -nobrowse -readonly -mountpoint "$mount_dir" "$dmg" >/dev/null \
|| die "could not mount $dmg_name"
shopt -s nullglob
apps=("$mount_dir"/*.app)
shopt -u nullglob
[[ ${#apps[@]} -eq 1 ]] \
|| die "$dmg_name: expected one .app at the image root, found ${#apps[@]}"
plist="${apps[0]}/Contents/Info.plist"
[[ -f $plist ]] || die "$dmg_name: the app has no Contents/Info.plist"
plist_value "$plist" CFBundleVersion "$dmg"
plist_value "$plist" SUFeedURL "$dmg"
plist_value "$plist" SUPublicEDKey "$dmg"
hdiutil detach "$mount_dir" -quiet >/dev/null
rm -rf -- "${mount_dir:?}"
mount_dir=
done
output_dir=$(dirname "$output")
mkdir -p "$output_dir"
# generate_appcast replaces the feed's items with the ones it just generated,
# so an entry it did not see is dropped without a word. Count them either side
# and refuse a feed that shrinks.
item_count() {
[[ -f $1 ]] || { echo 0; return 0; }
{ grep -o '<item>' "$1" || true; } | wc -l | tr -d '[:space:]'
}
# --maximum-versions 0 keeps every version in the feed; --maximum-deltas 0
# disables deltas, which this feed does not publish.
args=(--ed-key-file "$key_file" --download-url-prefix "$url_prefix"
--maximum-versions 0 --maximum-deltas 0 -o "$output")
[[ -z $channel ]] || args+=(--channel "$channel")
items_before=$(item_count "$output")
"$tool" "${args[@]}" "$dmg_dir"
[[ -s $output ]] || die "generate_appcast wrote no appcast to $output"
items_after=$(item_count "$output")
[[ $items_after -ge $items_before ]] \
|| die "$output lost entries: $items_before <item> elements before, $items_after after"
# --channel only tags a new item. If the entry already existed without one,
# the feed would quietly stay on the default channel, so check the marker is
# really there when a channel was asked for.
if [[ -n $channel ]]; then
grep -qF "<sparkle:channel>${channel}</sparkle:channel>" "$output" \
|| die "$output has no <sparkle:channel>${channel}</sparkle:channel> entry"
fi
echo "Wrote $output"