The apps are developed apart from the OS now, each in its own repo under gitea.bluefox.support/fennec: - sdk: sf-app (the app contract: manifest, permissions, store rules, sandbox, launch; from sf-ipc), sf-ui, sf-pack, the app template, the developer guide. The OS depends on it by tag (v0.1.0). - youtube, steam: store apps. netflex (native) replaces the Netflex web app. - store: the Fennec catalog, the store source a new TV starts with. This repo keeps the OS and its own apps (Settings, App Store, AirPlay, Miracast). sf-ipc re-exports sf-app, so OS code is mostly unchanged. - Store apps may register for DIAL (the `dial` permission); an official app with the same DIAL name wins. - Built-in icon names are for official apps only. - The image installs the catalog apps at build time (factory-store.toml, sf-update store in mkosi.postinst.chroot). Steam's system part stays in the image: 32-bit libraries, controller udev rules (from Valve's apt repo), Valve's key. - Older TVs move over by themselves: sf-update adds the replacements to store.toml once, the old factory app stays until its replacement is installed, YouTube's and Steam's data folders move to the new ids, and the old sf-app-<id> packages are not installed any more. Shell 0.3.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
130 lines
4.8 KiB
Bash
130 lines
4.8 KiB
Bash
#!/usr/bin/env bash
|
|
# Builds, signs and uploads Fennec OS packages (protocol: docs/updates.md).
|
|
#
|
|
# tools/pkg/packages.sh [--upload] [shell] [app:<id>...] [apps]
|
|
#
|
|
# With no package names it does the shell and every app. A package whose
|
|
# version is already in the registry is skipped (bump the version to publish):
|
|
# shell version = [workspace.package] version in Cargo.toml
|
|
# app:<id> version = "version" in apps/<id>/app.toml
|
|
#
|
|
# Only the OS's own apps are packages here. Store apps (Netflex, YouTube,
|
|
# Steam...) are released from their own repos (docs/store.md).
|
|
#
|
|
# Environment:
|
|
# SF_SIGNING_KEY Ed25519 private key: the PEM file base64-encoded on one
|
|
# line (so CI logs mask it), or SF_SIGNING_KEY_FILE = the PEM
|
|
# SF_PACKAGE_TOKEN "user:token", or a token of SF_OWNER, with write:package (upload only)
|
|
# SF_GITEA default https://gitea.bluefox.support
|
|
# SF_OWNER default bluefox
|
|
# SF_OUT output folder, default target/packages
|
|
set -euo pipefail
|
|
|
|
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
|
|
GITEA="${SF_GITEA:-https://gitea.bluefox.support}"
|
|
OWNER="${SF_OWNER:-bluefox}"
|
|
OUT="${SF_OUT:-$ROOT/target/packages}"
|
|
# Binaries in the shell package (built with cargo --release).
|
|
SHELL_BINS=(sf-launcher sf-remote sf-core sf-miracast sf-compositor sf-update)
|
|
|
|
UPLOAD=0
|
|
WANT=()
|
|
for a in "$@"; do
|
|
case "$a" in
|
|
--upload) UPLOAD=1 ;;
|
|
shell | apps | app:*) WANT+=("$a") ;;
|
|
*) echo "unknown argument: $a" >&2; exit 2 ;;
|
|
esac
|
|
done
|
|
[ ${#WANT[@]} -gt 0 ] || WANT=(shell apps)
|
|
|
|
KEY_FILE="${SF_SIGNING_KEY_FILE:-}"
|
|
TMP=$(mktemp -d)
|
|
trap 'rm -rf "$TMP"' EXIT
|
|
if [ -z "$KEY_FILE" ]; then
|
|
[ -n "${SF_SIGNING_KEY:-}" ] || { echo "SF_SIGNING_KEY or SF_SIGNING_KEY_FILE is needed" >&2; exit 2; }
|
|
KEY_FILE="$TMP/key.pem"
|
|
(umask 077; printf '%s' "$SF_SIGNING_KEY" | base64 -d >"$KEY_FILE")
|
|
fi
|
|
|
|
auth() {
|
|
case "${SF_PACKAGE_TOKEN:-}" in
|
|
*:*) printf -- '-u\n%s\n' "$SF_PACKAGE_TOKEN" ;;
|
|
?*) printf -- '-u\n%s:%s\n' "$OWNER" "$SF_PACKAGE_TOKEN" ;;
|
|
esac
|
|
}
|
|
mapfile -t AUTH < <(auth)
|
|
|
|
url() { echo "$GITEA/api/packages/$OWNER/generic/$1/$2/$1-$2.tar.zst"; }
|
|
|
|
published() {
|
|
[ "$UPLOAD" = 1 ] || return 1
|
|
local code
|
|
code=$(curl -s -o /dev/null -w '%{http_code}' -I "${AUTH[@]}" "$(url "$1" "$2")")
|
|
[ "$code" = 200 ]
|
|
}
|
|
|
|
# pack <name> <version> <dir>: tar.zst + .sig in $OUT, uploaded with --upload.
|
|
pack() {
|
|
local name=$1 version=$2 dir=$3 file
|
|
printf 'name = "%s"\nversion = "%s"\n' "$name" "$version" >"$dir/pkg.toml"
|
|
mkdir -p "$OUT"
|
|
file="$OUT/$name-$version.tar.zst"
|
|
tar --sort=name --owner=0 --group=0 --numeric-owner --mtime=@0 -C "$dir" -cf - . | zstd -q -19 -T0 -f -o "$file"
|
|
openssl pkeyutl -sign -inkey "$KEY_FILE" -rawin -in "$file" -out "$file.sig"
|
|
echo "built $(basename "$file") ($(du -h "$file" | cut -f1))"
|
|
if [ "$UPLOAD" = 1 ]; then
|
|
for f in "$file" "$file.sig"; do
|
|
curl -fsS "${AUTH[@]}" --upload-file "$f" "$GITEA/api/packages/$OWNER/generic/$name/$version/$(basename "$f")" >/dev/null
|
|
done
|
|
echo "uploaded $name $version"
|
|
fi
|
|
}
|
|
|
|
toml_version() { sed -n 's/^version *= *"\(.*\)".*/\1/p' "$1" | head -1; }
|
|
|
|
do_shell() {
|
|
local version
|
|
version=$(sed -n '/^\[workspace.package\]/,/^\[/ s/^version *= *"\(.*\)"/\1/p' "$ROOT/Cargo.toml")
|
|
if published sf-shell "$version"; then
|
|
echo "sf-shell $version: already published"
|
|
return
|
|
fi
|
|
local args=()
|
|
for b in "${SHELL_BINS[@]}"; do args+=(-p "$b"); done
|
|
(cd "$ROOT" && cargo build --release --locked "${args[@]}")
|
|
local dir="$TMP/sf-shell"
|
|
rm -rf "$dir"
|
|
mkdir -p "$dir/bin"
|
|
for b in "${SHELL_BINS[@]}"; do install -m755 "${CARGO_TARGET_DIR:-$ROOT/target}/release/$b" "$dir/bin/$b"; done
|
|
install -m755 "$ROOT/tools/siri-remote/fastpair.py" "$dir/bin/sf-pair"
|
|
pack sf-shell "$version" "$dir"
|
|
}
|
|
|
|
do_app() {
|
|
local id=$1 src="$ROOT/apps/$1" version
|
|
[ -f "$src/app.toml" ] || { echo "no app $id" >&2; return 1; }
|
|
version=$(toml_version "$src/app.toml")
|
|
[ -n "$version" ] || { echo "apps/$id/app.toml has no version, skipped"; return; }
|
|
if published "sf-app-$id" "$version"; then
|
|
echo "sf-app-$id $version: already published"
|
|
return
|
|
fi
|
|
local dir="$TMP/sf-app-$id"
|
|
rm -rf "$dir"
|
|
cp -r "$src" "$dir"
|
|
chmod -R u=rwX,go=rX "$dir"
|
|
# Git on Windows loses the x bit: programs live in bin/.
|
|
[ -d "$dir/bin" ] && chmod -R a+x "$dir/bin"
|
|
pack "sf-app-$id" "$version" "$dir"
|
|
}
|
|
|
|
for w in "${WANT[@]}"; do
|
|
case "$w" in
|
|
shell) do_shell ;;
|
|
# A folder with its own .git is a store app developed in place: skipped.
|
|
apps) for d in "$ROOT"/apps/*/; do [ -e "$d/.git" ] || do_app "$(basename "$d")"; done ;;
|
|
app:*) do_app "${w#app:}" ;;
|
|
esac
|
|
done
|