mirror of
https://github.com/storytold/craft-launcher.git
synced 2026-11-16 23:24:31 +00:00
apps/craft-ai-mcp builds the gateway from storytold/craft-ai-integrations (crates/ai-mcp, craft_ai_mcp::cli) as craft-ai-mcp, and every package puts it beside the launcher, where Settings › AI agents finds it: - Windows: built with the launcher, PE-checked as a console program, signed, in the MSI (the launcher's component) and the portable zip; listed in the install policy's payloads - macOS: lipo'd and placed in Contents/MacOS, signed with the hardened runtime before the main executable - Linux: /usr/bin in the deb and rpm (nfpm), the tarball and the AppImage; /app/bin in both Flatpak manifests - FreeBSD: bin/, checked like the launcher The gateway needs only serde, serde_json and dirs. It is pinned to the head of storytold/craft-ai-integrations#197 until that merges.
213 lines
9.9 KiB
Bash
Executable File
213 lines
9.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
||
# Build and package ArtCraft Launcher for Linux (<arch> is x86_64, aarch64 or riscv64):
|
||
#
|
||
# $DIST/artcraft-launcher-<version>-linux-<arch>.AppImage any distro with glibc >= the build host's
|
||
# $DIST/artcraft-launcher-<version>-linux-<arch>.AppImage.zsync delta updates (needs zsyncmake)
|
||
# $DIST/artcraft-launcher-<version>-linux-<arch>.deb Debian, Ubuntu, Mint, Pop!_OS, ...
|
||
# $DIST/artcraft-launcher-<version>-linux-<arch>.rpm Fedora, openSUSE, RHEL, ...
|
||
# $DIST/artcraft-launcher-<version>-linux-<arch>.tar.gz plain FHS-style tree (bin/, share/)
|
||
#
|
||
# Usage: packaging/linux/package.sh [--skip-build] [--formats "appimage deb rpm tar" or appimage,deb,rpm,tar]
|
||
#
|
||
# Needs: cargo; nfpm for deb/rpm (https://nfpm.goreleaser.com); appimagetool for the AppImage
|
||
# (downloaded into $CARGO_TARGET_DIR if missing). Build on an old distro (CI: Ubuntu 22.04,
|
||
# glibc 2.35) so the binaries run on newer ones. RISC-V CI uses Ubuntu 24.04 (glibc 2.39)
|
||
# and sets GLIBC_FLOOR accordingly. Set it for other build baselines too. Optional:
|
||
# desktop-file-validate, appstreamcli, zsyncmake (the zsync package) for the AppImage's .zsync.
|
||
#
|
||
# Cross builds (CI: riscv64, deb/rpm/tar.gz): set CROSS_ARCH (riscv64), CROSS_TARGET (the Rust
|
||
# triple), CROSS_COMPILE (binutils prefix, for strip) and optionally EMULATOR (e.g. qemu-riscv64)
|
||
# to smoke-test the CLI.
|
||
set -euo pipefail
|
||
# shellcheck source=../env.sh
|
||
. "$(dirname "${BASH_SOURCE[0]}")/../env.sh"
|
||
HERE="$ROOT/packaging/linux"
|
||
APP_ID=ai.storyteller.artcraft-launcher
|
||
PKG=artcraft-launcher
|
||
# Verify a downloaded file's sha256 against its expected hex digest.
|
||
check_sha256() {
|
||
local expected="$1"
|
||
local target="$2"
|
||
printf '%s %s\n' "$expected" "$target" | sha256sum -c -
|
||
}
|
||
|
||
SKIP_BUILD=0
|
||
FORMATS="appimage deb rpm tar"
|
||
while [[ $# -gt 0 ]]; do
|
||
case "$1" in
|
||
--skip-build) SKIP_BUILD=1; shift ;;
|
||
--formats) FORMATS="$2"; shift 2 ;;
|
||
-h | --help) sed -n '2,19p' "$0"; exit 0 ;;
|
||
*) echo "unknown argument: $1" >&2; exit 2 ;;
|
||
esac
|
||
done
|
||
# Accept "deb,rpm,tar" as well as "deb rpm tar" (craft-common-actions passes commas).
|
||
FORMATS="$(printf %s "$FORMATS" | tr ',' ' ')"
|
||
for fmt in $FORMATS; do
|
||
case "$fmt" in
|
||
appimage | deb | rpm | tar) ;;
|
||
*) echo "unknown format: $fmt (expected appimage, deb, rpm or tar)" >&2; exit 2 ;;
|
||
esac
|
||
done
|
||
|
||
ARCH="${CROSS_ARCH:-$(uname -m)}"
|
||
case "$ARCH" in
|
||
riscv64) DEB_ARCH=riscv64 ;;
|
||
x86_64) DEB_ARCH=amd64 ;;
|
||
aarch64 | arm64) ARCH=aarch64; DEB_ARCH=arm64 ;;
|
||
*) echo "unsupported architecture $ARCH" >&2; exit 2 ;;
|
||
esac
|
||
export ARTCRAFT_LAUNCHER_MAINTAINER="${ARTCRAFT_LAUNCHER_MAINTAINER:-ArtCraft Launcher maintainers <craft-launcher@storyteller.ai>}"
|
||
BASENAME="$PKG-$VERSION-linux-$ARCH"
|
||
|
||
echo "==> ArtCraft Launcher $VERSION for Linux $ARCH ($FORMATS)"
|
||
|
||
if [[ "$SKIP_BUILD" = 0 ]]; then
|
||
if [[ -n "${CROSS_TARGET:-}" ]]; then
|
||
(cd "$ROOT" && cargo build --release --locked -p "$PKG" -p artcraft-launcher-mcp --target "$CROSS_TARGET")
|
||
else
|
||
(cd "$ROOT" && cargo build --release --locked -p "$PKG" -p artcraft-launcher-mcp)
|
||
fi
|
||
fi
|
||
BIN="$CARGO_TARGET_DIR/${CROSS_TARGET:+$CROSS_TARGET/}release"
|
||
WORK="$CARGO_TARGET_DIR/linux-package"
|
||
STAGE="$WORK/root"
|
||
rm -rf "$WORK"
|
||
|
||
# ---- stage an FHS tree (shared by every format) -------------------------------------------------
|
||
install -Dm755 "$BIN/$PKG" "$STAGE/usr/bin/$PKG"
|
||
"${CROSS_COMPILE:-}strip" "$STAGE/usr/bin/$PKG" 2>/dev/null || true
|
||
# The craft-ai-mcp gateway the launcher ships (Settings › AI agents), beside the launcher.
|
||
install -Dm755 "$BIN/craft-ai-mcp" "$STAGE/usr/bin/craft-ai-mcp"
|
||
"${CROSS_COMPILE:-}strip" "$STAGE/usr/bin/craft-ai-mcp" 2>/dev/null || true
|
||
install -Dm644 "$HERE/$APP_ID.desktop" "$STAGE/usr/share/applications/$APP_ID.desktop"
|
||
mkdir -p "$STAGE/usr/share/metainfo"
|
||
sed -e "s/@VERSION@/$VERSION/g" -e "s/@DATE@/$ARTCRAFT_LAUNCHER_BUILD_DATE/g" \
|
||
"$HERE/$APP_ID.metainfo.xml.in" >"$STAGE/usr/share/metainfo/$APP_ID.metainfo.xml"
|
||
mkdir -p "$STAGE/usr/share/icons"
|
||
cp -R "$ROOT/assets/app-icon/hicolor" "$STAGE/usr/share/icons/"
|
||
mkdir -p "$STAGE/usr/share/doc/$PKG"
|
||
copy_docs "$STAGE/usr/share/doc/$PKG"
|
||
|
||
if command -v desktop-file-validate >/dev/null; then
|
||
desktop-file-validate "$STAGE/usr/share/applications/$APP_ID.desktop"
|
||
fi
|
||
if command -v appstreamcli >/dev/null; then
|
||
appstreamcli validate --no-net --explain "$STAGE/usr/share/metainfo/$APP_ID.metainfo.xml"
|
||
fi
|
||
|
||
has() { local format="$1"; case " $FORMATS " in *" $format "*) return 0 ;; *) return 1 ;; esac; }
|
||
|
||
# ---- .tar.gz ------------------------------------------------------------------------------------
|
||
if has tar; then
|
||
mkdir -p "$WORK/tar"
|
||
cp -R "$STAGE/usr" "$WORK/tar/$BASENAME"
|
||
tar -C "$WORK/tar" -czf "$DIST/$BASENAME.tar.gz" "$BASENAME"
|
||
echo "wrote $DIST/$BASENAME.tar.gz"
|
||
fi
|
||
|
||
# ---- .deb / .rpm --------------------------------------------------------------------------------
|
||
if has deb || has rpm; then
|
||
command -v nfpm >/dev/null || { echo "error: nfpm not found (https://nfpm.goreleaser.com/install/)" >&2; exit 1; }
|
||
export VERSION
|
||
export NFPM_ARCH="$DEB_ARCH"
|
||
# Match the build runner: Ubuntu 22.04 normally, Ubuntu 24.04 for RISC-V in CI.
|
||
export GLIBC_FLOOR="${GLIBC_FLOOR:-2.35}"
|
||
# nfpm expands env vars in fields like `version` and `arch`, but not in `contents[].src`.
|
||
sed "s|\${STAGE}|$STAGE|g" "$HERE/nfpm.yaml" >"$WORK/nfpm.yaml"
|
||
for fmt in deb rpm; do
|
||
if has "$fmt"; then (cd "$ROOT" && nfpm package -f "$WORK/nfpm.yaml" -p "$fmt" -t "$DIST/$BASENAME.$fmt"); fi
|
||
done
|
||
fi
|
||
|
||
# ---- AppImage -----------------------------------------------------------------------------------
|
||
if has appimage; then
|
||
APPIMAGETOOL_VERSION=1.9.1
|
||
case "$ARCH" in
|
||
x86_64) APPIMAGETOOL_SHA256=ed4ce84f0d9caff66f50bcca6ff6f35aae54ce8135408b3fa33abfc3cb384eb0 ;;
|
||
aarch64) APPIMAGETOOL_SHA256=f0837e7448a0c1e4e650a93bb3e85802546e60654ef287576f46c71c126a9158 ;;
|
||
*) APPIMAGETOOL_SHA256="" ;;
|
||
esac
|
||
# appimagetool otherwise fetches the unpinned type2-runtime `continuous` build and embeds it.
|
||
APPIMAGE_RUNTIME_VERSION=20251108
|
||
case "$ARCH" in
|
||
x86_64) APPIMAGE_RUNTIME_SHA256=2fca8b443c92510f1483a883f60061ad09b46b978b2631c807cd873a47ec260d ;;
|
||
aarch64) APPIMAGE_RUNTIME_SHA256=00cbdfcf917cc6c0ff6d3347d59e0ca1f7f45a6df1a428a0d6d8a78664d87444 ;;
|
||
*) APPIMAGE_RUNTIME_SHA256="" ;;
|
||
esac
|
||
if [[ -z "$APPIMAGE_RUNTIME_SHA256" ]]; then
|
||
echo "no pinned AppImage runtime for $ARCH; build the AppImage on x86_64 or aarch64" >&2
|
||
exit 2
|
||
fi
|
||
APPDIR="$WORK/ArtCraftLauncher.AppDir"
|
||
cp -R "$STAGE" "$APPDIR"
|
||
# AppRun is a script, not a symlink: it installs the .desktop entry and icons into
|
||
# $XDG_DATA_HOME before launching, so Wayland compositors can resolve the window's
|
||
# app_id to our icon instead of the generic Wayland logo (opt-out env in the
|
||
# script header). Logic is covered by packaging/linux/apprun-test.sh.
|
||
install -Dm755 "$HERE/AppRun" "$APPDIR/AppRun"
|
||
cp "$HERE/$APP_ID.desktop" "$APPDIR/$APP_ID.desktop"
|
||
cp "$ROOT/assets/app-icon/hicolor/256x256/apps/$APP_ID.png" "$APPDIR/$APP_ID.png"
|
||
ln -s "$APP_ID.png" "$APPDIR/.DirIcon"
|
||
|
||
TOOL="${APPIMAGETOOL:-$(command -v appimagetool || true)}"
|
||
if [[ -z "$TOOL" ]]; then
|
||
if [[ -z "$APPIMAGETOOL_SHA256" ]]; then
|
||
echo "no pinned appimagetool for $ARCH; set APPIMAGETOOL or put appimagetool on PATH" >&2
|
||
exit 2
|
||
fi
|
||
TOOL="$CARGO_TARGET_DIR/appimagetool-$APPIMAGETOOL_VERSION-$ARCH.AppImage"
|
||
if [[ ! -x "$TOOL" ]]; then
|
||
download="$TOOL.download"
|
||
curl --proto '=https' -fsSL -o "$download" \
|
||
"https://github.com/AppImage/appimagetool/releases/download/$APPIMAGETOOL_VERSION/appimagetool-$ARCH.AppImage"
|
||
check_sha256 "$APPIMAGETOOL_SHA256" "$download"
|
||
chmod 755 "$download"
|
||
mv "$download" "$TOOL"
|
||
fi
|
||
check_sha256 "$APPIMAGETOOL_SHA256" "$TOOL"
|
||
fi
|
||
RUNTIME="$CARGO_TARGET_DIR/appimage-runtime-$APPIMAGE_RUNTIME_VERSION-$ARCH"
|
||
if [[ ! -f "$RUNTIME" ]]; then
|
||
download="$RUNTIME.download"
|
||
curl --proto '=https' -fsSL -o "$download" \
|
||
"https://github.com/AppImage/type2-runtime/releases/download/$APPIMAGE_RUNTIME_VERSION/runtime-$ARCH"
|
||
check_sha256 "$APPIMAGE_RUNTIME_SHA256" "$download"
|
||
mv "$download" "$RUNTIME"
|
||
fi
|
||
check_sha256 "$APPIMAGE_RUNTIME_SHA256" "$RUNTIME"
|
||
# Absolute, because appimagetool runs in $DIST below (CARGO_TARGET_DIR or APPIMAGETOOL may be
|
||
# relative, e.g. target/agent-<name>).
|
||
OUT="$(cd "$DIST" && pwd)/$BASENAME.AppImage"
|
||
APPDIR="$(cd "$APPDIR" && pwd)"
|
||
TOOL="$(cd "$(dirname "$TOOL")" && pwd)/$(basename "$TOOL")"
|
||
RUNTIME="$(cd "$(dirname "$RUNTIME")" && pwd)/$(basename "$RUNTIME")"
|
||
# A .zsync left by an earlier run would hide a missing zsyncmake and describe another file.
|
||
rm -f "$OUT.zsync"
|
||
# Update information: AppImageUpdate, AppImageLauncher and the like read it from the
|
||
# file and fetch only the blocks that changed in a newer release, through the .zsync published
|
||
# next to each AppImage on GitHub Releases. `latest` is the newest published release that is
|
||
# not a pre-release. A fork's builds point at its own releases through GITHUB_REPOSITORY.
|
||
# The repo is craft-launcher while the files are artcraft-launcher-*.
|
||
REPO="${GITHUB_REPOSITORY:-storytold/craft-launcher}"
|
||
UPDATE_INFO="gh-releases-zsync|${REPO%%/*}|${REPO#*/}|latest|$PKG-*-linux-$ARCH.AppImage.zsync"
|
||
# Extract-and-run: works without FUSE (containers, CI). The output embeds the static runtime,
|
||
# so users don't need libfuse2 either. With zsyncmake on the host (CI installs the zsync
|
||
# package) appimagetool also writes the .zsync, into its working directory, hence the cd.
|
||
(cd "$DIST" && ARCH="$ARCH" APPIMAGE_EXTRACT_AND_RUN=1 "$TOOL" --no-appstream --runtime-file "$RUNTIME" -u "$UPDATE_INFO" "$APPDIR" "$OUT")
|
||
echo "wrote $OUT"
|
||
if [[ -s "$OUT.zsync" ]]; then
|
||
echo "wrote $OUT.zsync"
|
||
else
|
||
warn "zsyncmake not found, so $OUT.zsync was not written; AppImage delta updates need it"
|
||
fi
|
||
fi
|
||
|
||
if [[ -z "${CROSS_TARGET:-}" ]]; then
|
||
"$STAGE/usr/bin/$PKG" --version
|
||
elif [[ -n "${EMULATOR:-}" ]]; then
|
||
"$EMULATOR" "$STAGE/usr/bin/$PKG" --version
|
||
fi
|
||
echo "==> done"
|
||
ls -lh "$DIST"
|