Skip to content

armgit / soju

Public Imported from GitHub
0

Play Windows games on Apple Silicon Macs. Free, open-source app that installs the official Battle.net, Steam, Epic and GOG launchers and lists your games in one library.

Install and update only checked downloads (#63)

Mikek5fe8481dfe98
diff --git a/docs/install.sh b/docs/install.sh
index f19d1ccfcf9..8365c98ef80 100644
--- a/docs/install.sh
+++ b/docs/install.sh
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
# Short-URL entry point for the Soju installer (GitHub Pages, fronted by soju.snack-wrap.com).
# curl -fsSL soju.snack-wrap.com/install.sh | bash
-# Downloads and runs the real installer from the main branch.
+# Runs install.sh from main, which installs the newest release zip after checking its SHA-256.
set -euo pipefail
curl -fsSL "https://raw.githubusercontent.com/BCD1210/soju/main/install.sh" | bash
diff --git a/install.sh b/install.sh
index 1d02186012a..180c7f57f42 100644
--- a/install.sh
+++ b/install.sh
@@ -19,6 +19,52 @@ TTY=/dev/tty
say(){ printf '\n\033[1m%s\033[0m\n' "$*"; }
+# The prebuilt engine is pinned: a new engine release only reaches users once
+# these two lines (here and in scripts/update.sh) name it.
+ENGINE_TAG="engine-v1.5"
+ENGINE_SHA256="7b96a4407308493ae92bebe96039bbc8d0bf3b86c22cb99c782f73cf7be3738e"
+ENGINE_URL="https://github.com/$REPO/releases/download/$ENGINE_TAG/wine-engine-x86_64.tar.xz"
+
+# Download to a .part file and keep it only when its SHA-256 matches.
+fetch_verified(){ # url, dest, sha256
+ local got
+ rm -f "$2.part"
+ curl -fL "$1" -o "$2.part" || { rm -f "$2.part"; return 1; }
+ got=$(shasum -a 256 "$2.part" | awk '{print $1}')
+ if [ "$got" != "$3" ]; then
+ rm -f "$2.part"
+ printf 'Checksum mismatch for %s\n expected %s\n got %s\n' "$1" "$3" "$got"
+ return 1
+ fi
+ mv -f "$2.part" "$2"
+}
+
+# Newest stable vX.Y.Z release whose app zip has a SHA-256 recorded by GitHub.
+# Prints "<tag> <zip url> <sha256>". The zip carries the scripts and this
+# installer, so a one-line install runs released code, never main.
+latest_release(){
+ local json i j tag name n digest
+ json=$(mktemp) || return 1
+ if ! curl -fsSL "https://api.github.com/repos/$REPO/releases?per_page=30" -o "$json"; then
+ rm -f "$json"; return 1
+ fi
+ for i in $(seq 0 29); do
+ tag=$(plutil -extract "$i.tag_name" raw -o - "$json" 2>/dev/null) || break
+ [[ "$tag" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]] || continue
+ [ "$(plutil -extract "$i.prerelease" raw -o - "$json" 2>/dev/null)" = false ] || continue
+ name="Soju-${tag#v}-macos-arm64.zip"
+ for j in $(seq 0 19); do
+ n=$(plutil -extract "$i.assets.$j.name" raw -o - "$json" 2>/dev/null) || break
+ [ "$n" = "$name" ] || continue
+ digest=$(plutil -extract "$i.assets.$j.digest" raw -o - "$json" 2>/dev/null) || break
+ [[ "$digest" =~ ^sha256:[0-9a-f]{64}$ ]] || break
+ echo "$tag https://github.com/$REPO/releases/download/$tag/$name ${digest#sha256:}"
+ rm -f "$json"; return 0
+ done
+ done
+ rm -f "$json"; return 1
+}
+
# ---------- 1. Choose launchers before any download ----------
ALL="battlenet steam epic gog"
if [ -n "${SOJU_PLATFORMS:-}" ]; then
@@ -62,6 +108,37 @@ fi
mkdir -p "$BASE"
+# ---------- Soju scripts ----------
+# A checkout, the app bundle or Homebrew runs its own copy. The one-line
+# installer has none: it fetches the newest release zip, checks its SHA-256,
+# and hands over to the installer inside it, so scripts and installer match.
+SELF_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" 2>/dev/null && pwd || true)"
+if [ -n "$SELF_DIR" ] && [ -f "$SELF_DIR/scripts/play.sh" ]; then
+ SOJU_DIR="$SELF_DIR"
+ # Homebrew: the Cellar path carries the version and goes away on `brew
+ # upgrade`, which would leave every app bundle pointing at nothing. Bake the
+ # stable opt/ path into the bundles instead.
+ case "$SOJU_DIR" in
+ */Cellar/soju/*/libexec) SOJU_DIR="$(brew --prefix 2>/dev/null || echo /opt/homebrew)/opt/soju/libexec" ;;
+ esac
+else
+ SOJU_DIR="$BASE/soju"
+ REL=$(latest_release) || { echo "Could not find a Soju release with a recorded checksum (offline?)"; exit 1; }
+ read -r REL_TAG REL_URL REL_SHA <<<"$REL"
+ say "Fetching the Soju scripts ($REL_TAG) into $SOJU_DIR"
+ STAGE="$SOJU_DIR.tmp"
+ rm -rf "$STAGE"; mkdir -p "$STAGE"
+ fetch_verified "$REL_URL" "$STAGE/soju.zip" "$REL_SHA" || { rm -rf "$STAGE"; exit 1; }
+ ditto -x -k "$STAGE/soju.zip" "$STAGE/app"
+ [ -f "$STAGE/app/Soju.app/Contents/Resources/soju/install.sh" ] \
+ || { echo "The $REL_TAG zip does not contain the Soju scripts"; rm -rf "$STAGE"; exit 1; }
+ rm -rf "$SOJU_DIR"; mv "$STAGE/app/Soju.app/Contents/Resources/soju" "$SOJU_DIR"
+ rm -rf "$STAGE"
+ chmod +x "$SOJU_DIR"/install.sh "$SOJU_DIR"/scripts/*.sh "$SOJU_DIR"/scripts/soju 2>/dev/null || true
+ SOJU_PLATFORMS="${PLATFORMS# }" exec /bin/bash "$SOJU_DIR/install.sh" "$@"
+fi
+chmod +x "$SOJU_DIR"/scripts/*.sh "$SOJU_DIR"/scripts/soju 2>/dev/null || true
+
# ---------- Apple GPTK helpers ----------
# Installed means all three parts: the Metal side, and Apple's PE shims in
# place of Wine's d3d11 (the shim carries Apple's build path string).
@@ -98,20 +175,13 @@ if [ -x "$ENGINE/bin/wine" ] && DYLD_FALLBACK_LIBRARY_PATH="$ENGINE/lib:/usr/lib
say "[2/4] Engine already present - skipping"
else
say "[2/4] Downloading prebuilt engine (~350MB, GPL - built from CodeWeavers' published Wine sources)"
- # The engine ships on its own "engine-*" release, which is not necessarily the
- # newest release: scan all releases and take the first (newest) engine asset.
- URL=$(curl -fsSL "https://api.github.com/repos/$REPO/releases?per_page=30" \
- | grep -o '"browser_download_url": *"[^"]*wine-engine[^"]*"' | head -1 | grep -o 'https[^"]*')
- [ -n "$URL" ] || { echo "Could not find the engine release asset."; exit 1; }
- # Download to a .part file and extract into a staging directory, so an
- # interrupted run leaves nothing that a re-run would mistake for done.
- curl -fL "$URL" -o "$BASE/engine.tar.xz.part"
- mv -f "$BASE/engine.tar.xz.part" "$BASE/engine.tar.xz"
+ # Download and check the pinned engine, then extract into a staging directory,
+ # so an interrupted run leaves nothing that a re-run would mistake for done.
+ fetch_verified "$ENGINE_URL" "$BASE/engine.tar.xz" "$ENGINE_SHA256" || exit 1
rm -rf "$ENGINE.new"; mkdir -p "$ENGINE.new"
tar -xJf "$BASE/engine.tar.xz" -C "$ENGINE.new"
rm -f "$BASE/engine.tar.xz"
- TAG=$(echo "$URL" | sed -n 's#.*/download/\([^/]*\)/.*#\1#p')
- printf '%s\n' "${TAG:-unknown}" > "$ENGINE.new/.soju-engine-release"
+ printf '%s\n' "$ENGINE_TAG" > "$ENGINE.new/.soju-engine-release"
if [ -d "$ENGINE" ]; then
# A broken engine from an earlier run; keep any GPTK payload in it.
carry_gptk "$ENGINE" "$ENGINE.new"
@@ -125,27 +195,6 @@ fi
fi # NEEDS_CX
-# ---------- Soju scripts ----------
-# The bottle scripts live in the repo; fetch a copy next to the engine so the
-# one-line installer can use them (a checkout running install.sh uses itself).
-SELF_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" 2>/dev/null && pwd || true)"
-if [ -n "$SELF_DIR" ] && [ -f "$SELF_DIR/scripts/play.sh" ]; then
- SOJU_DIR="$SELF_DIR"
- # Homebrew: the Cellar path carries the version and goes away on `brew
- # upgrade`, which would leave every app bundle pointing at nothing. Bake the
- # stable opt/ path into the bundles instead.
- case "$SOJU_DIR" in
- */Cellar/soju/*/libexec) SOJU_DIR="$(brew --prefix 2>/dev/null || echo /opt/homebrew)/opt/soju/libexec" ;;
- esac
-else
- SOJU_DIR="$BASE/soju"
- say "Fetching the Soju scripts into $SOJU_DIR"
- rm -rf "$SOJU_DIR.tmp"; mkdir -p "$SOJU_DIR.tmp"
- curl -fsSL "https://github.com/$REPO/archive/refs/heads/main.tar.gz" | tar -xz -C "$SOJU_DIR.tmp" --strip-components=1
- rm -rf "$SOJU_DIR"; mv "$SOJU_DIR.tmp" "$SOJU_DIR"
-fi
-chmod +x "$SOJU_DIR"/scripts/*.sh "$SOJU_DIR"/scripts/soju 2>/dev/null || true
-
# ---------- Apple GPTK (Battle.net / Epic / GOG only) ----------
if [ "$NEEDS_CX" = 1 ]; then
# scripts/get-gptk.sh finds the payload (mounted toolkit dmg, or CrossOver),
diff --git a/scripts/build-engine.sh b/scripts/build-engine.sh
index 5455da0187b..a373a017172 100755
--- a/scripts/build-engine.sh
+++ b/scripts/build-engine.sh
@@ -12,6 +12,9 @@ WORK="${WORK:-$HOME/.battlenet-macos/build}"
REPO="$(cd "$(dirname "$0")/.." && pwd)"
SRC_URL="https://media.codeweavers.com/pub/crossover/source/crossover-sources-26.3.0.tar.gz"
FT_URL="https://download.savannah.gnu.org/releases/freetype/freetype-2.13.3.tar.gz"
+# SHA-256 of the archives used for the verified 2026-08 build.
+SRC_SHA256="ac99c8ca4b3848f3e81784135f023df266b61c2345726ea55a50b3e030dd6872"
+FT_SHA256="5c3a8e78f7b24c20b25b54ee575d6daa40007a5f4eea2845861c3409b3021747"
DEPS="$WORK/deps"
ENGINE="${ENGINE:-$HOME/.battlenet-macos/cx26-engine}"
# get-components.sh pre-fetches the x86_64 dylibs into $DEPS/lib (frankea GPL release)
@@ -24,8 +27,23 @@ export PATH="/opt/homebrew/opt/bison/bin:/opt/homebrew/bin:$PATH"
mkdir -p "$WORK" "$DEPS"
+# Download $1 to $2 (kept between runs) and use it only when its SHA-256 is $3.
+fetch_checked(){ # url, dest, sha256
+ local got
+ if [ ! -f "$2" ]; then
+ curl -fL --retry 3 "$1" -o "$2.part" || { rm -f "$2.part"; echo "Download failed: $1" >&2; return 1; }
+ mv -f "$2.part" "$2"
+ fi
+ got=$(shasum -a 256 "$2" | awk '{print $1}')
+ if [ "$got" != "$3" ]; then
+ rm -f "$2"
+ printf 'Checksum mismatch for %s\n expected %s\n got %s\n' "$1" "$3" "$got" >&2
+ return 1
+ fi
+}
+
echo "==> Downloading CrossOver 26.3 sources + freetype"
-[ -f "$WORK/cx-src.tar.gz" ] || { curl -fL "$SRC_URL" -o "$WORK/cx-src.tar.gz.part" && mv -f "$WORK/cx-src.tar.gz.part" "$WORK/cx-src.tar.gz"; }
+fetch_checked "$SRC_URL" "$WORK/cx-src.tar.gz" "$SRC_SHA256"
tar -xzf "$WORK/cx-src.tar.gz" -C "$WORK" sources/wine
WINE="$WORK/sources/wine"
# Soju winemac patch: WINE_NO_DOCK_ICON (hide helper-process Dock icons) and
@@ -53,7 +71,7 @@ if ! grep -q "KEY_STORE_MAGIC" "$WINE/dlls/ncrypt/main.c"; then
fi
echo "==> Building x86_64 freetype (Rosetta)"
-[ -f "$WORK/ft.tar.gz" ] || { curl -fL "$FT_URL" -o "$WORK/ft.tar.gz.part" && mv -f "$WORK/ft.tar.gz.part" "$WORK/ft.tar.gz"; }
+fetch_checked "$FT_URL" "$WORK/ft.tar.gz" "$FT_SHA256"
tar -xzf "$WORK/ft.tar.gz" -C "$WORK"
( cd "$WORK/freetype-2.13.3" && arch -x86_64 ./configure --prefix="$DEPS" \
--without-harfbuzz --without-png --without-brotli --without-bzip2 \
diff --git a/scripts/build-steam-support.sh b/scripts/build-steam-support.sh
index 6b365acffa8..38867213294 100755
--- a/scripts/build-steam-support.sh
+++ b/scripts/build-steam-support.sh
@@ -7,6 +7,20 @@ export PATH="/opt/homebrew/opt/bison/bin:/opt/homebrew/opt/flex/bin:/opt/homebre
JOBS="${SOJU_BUILD_JOBS:-8}"
mkdir -p "$BUILD"
cd "$BUILD"
+# Download $1 to $2 (kept between runs) and use it only when its SHA-256 is $3.
+fetch_checked(){ # url, dest, sha256
+ local got
+ if [ ! -f "$2" ]; then
+ curl -fL --retry 3 "$1" -o "$2.part" || { rm -f "$2.part"; echo "Download failed: $1" >&2; return 1; }
+ mv -f "$2.part" "$2"
+ fi
+ got=$(shasum -a 256 "$2" | awk '{print $1}')
+ if [ "$got" != "$3" ]; then
+ rm -f "$2"
+ printf 'Checksum mismatch for %s\n expected %s\n got %s\n' "$1" "$3" "$got" >&2
+ return 1
+ fi
+}
clone(){
if [ "${SOJU_SOURCE_ARCHIVE:-0}" = 1 ]; then [ -d "$2" ] || { echo "Extract $2 from the source release first"; exit 1; }
else [ -d "$2/.git" ] || git clone --depth 1 --branch "$3" "$1" "$2"; fi
@@ -28,7 +42,9 @@ export MACOSX_DEPLOYMENT_TARGET=26.0
[ -x venv/bin/meson ] || { python3 -m venv venv; venv/bin/pip install 'meson==1.10.2'; }
mkdir -p dxmt/toolchains/wine
if [ ! -x dxmt/toolchains/wine/bin/winebuild ]; then
- curl -fL --retry 3 https://github.com/3Shain/wine/releases/download/v8.16-3shain/wine.tar.gz -o wine-toolchain.tar.gz
+ # GitHub records no digest for this asset; the SHA-256 is the archive used for steam-support-v2.
+ fetch_checked https://github.com/3Shain/wine/releases/download/v8.16-3shain/wine.tar.gz wine-toolchain.tar.gz \
+ 289c7f19e270a3d3d0a6fdb07691b176c70a0795f6811e5255cba82425de4f10
tar -xzf wine-toolchain.tar.gz -C dxmt/toolchains/wine
fi
if [ ! -f dxmt/toolchains/llvm/lib/libLLVMCore.a ]; then
diff --git a/scripts/doctor.sh b/scripts/doctor.sh
index 2e35d5b2f6e..43f13768de4 100755
--- a/scripts/doctor.sh
+++ b/scripts/doctor.sh
@@ -60,14 +60,12 @@ if [ -x "$ENGINE/bin/wine" ]; then
if [ -n "$v" ]; then pass "wine runs: $v"; else fail "engine present but wine does not start (DYLD problem? reinstall: soju update)"; fi
tag=$(cat "$ENGINE/.soju-engine-release" 2>/dev/null || echo "")
[ -n "$tag" ] && info "installed engine release: $tag" || info "engine release tag not recorded (installed before v1.2 of the installer)"
- latest=$(curl -fsSL --max-time 5 "https://api.github.com/repos/$REPO/releases?per_page=30" 2>/dev/null \
- | grep -o '"tag_name": *"engine-[^"]*"' | head -1 | cut -d'"' -f4 || true)
- if [ -n "$latest" ]; then
- if [ "$latest" = "$tag" ]; then pass "engine is the latest release ($latest)"
- else warn "latest engine release is $latest (run: soju update)"; fi
- else
- info "could not reach GitHub to compare engine versions (offline?)"
- fi
+ # soju update installs only the engine these scripts pin.
+ pinned=$(sed -n 's/^ENGINE_TAG="\(.*\)"$/\1/p' "$ROOT/scripts/update.sh" | head -1)
+ if [ -z "$pinned" ]; then
+ info "engine pin not found in $ROOT/scripts/update.sh"
+ elif [ "$pinned" = "$tag" ]; then pass "engine is the release these scripts use ($pinned)"
+ else warn "these scripts use engine $pinned, installed is ${tag:-unknown} (run: soju update)"; fi
else
fail "engine not installed (run: soju install)"
fi
diff --git a/scripts/get-components.sh b/scripts/get-components.sh
index 95edd9a2bbc..80ad98e8fdb 100755
--- a/scripts/get-components.sh
+++ b/scripts/get-components.sh
@@ -8,9 +8,25 @@ set -euo pipefail
WORK="${WORK:-$HOME/.battlenet-macos/build}"
DEPS="$WORK/deps"; mkdir -p "$DEPS/lib" "$WORK"
+# Download $1 to $2 (kept between runs) and use it only when its SHA-256 is $3.
+fetch_checked(){ # url, dest, sha256
+ local got
+ if [ ! -f "$2" ]; then
+ curl -fL --retry 3 "$1" -o "$2.part" || { rm -f "$2.part"; echo "Download failed: $1" >&2; return 1; }
+ mv -f "$2.part" "$2"
+ fi
+ got=$(shasum -a 256 "$2" | awk '{print $1}')
+ if [ "$got" != "$3" ]; then
+ rm -f "$2"
+ printf 'Checksum mismatch for %s\n expected %s\n got %s\n' "$1" "$3" "$got" >&2
+ return 1
+ fi
+}
+
echo "==> Downloading the x86_64 dylib stack (frankea/Whisky Libraries, GPL)"
LIBS_URL="https://github.com/frankea/Whisky/releases/download/v3.1.1/Libraries.tar.gz"
-[ -f "$WORK/whisky-libs.tar.gz" ] || { curl -fL "$LIBS_URL" -o "$WORK/whisky-libs.tar.gz.part" && mv -f "$WORK/whisky-libs.tar.gz.part" "$WORK/whisky-libs.tar.gz"; }
+LIBS_SHA256="01f3a1b43b98065fe20c529c1023b61dd79a6d2ad93bba6040865f646481ccf3"
+fetch_checked "$LIBS_URL" "$WORK/whisky-libs.tar.gz" "$LIBS_SHA256"
mkdir -p "$WORK/whisky-libs"
tar -xzf "$WORK/whisky-libs.tar.gz" -C "$WORK/whisky-libs"
cp -f "$WORK/whisky-libs/Libraries/Wine/lib/"*.dylib "$DEPS/lib/" 2>/dev/null
@@ -18,7 +34,8 @@ echo " Got $(ls "$DEPS/lib"/*.dylib | wc -l | tr -d ' ') dylibs"
echo "==> Downloading wine-mono 10.4.1 (official release)"
MONO_URL="https://github.com/wine-mono/wine-mono/releases/download/wine-mono-10.4.1/wine-mono-10.4.1-x86.tar.xz"
-[ -f "$WORK/wine-mono.tar.xz" ] || { curl -fL "$MONO_URL" -o "$WORK/wine-mono.tar.xz.part" && mv -f "$WORK/wine-mono.tar.xz.part" "$WORK/wine-mono.tar.xz"; }
+MONO_SHA256="a16606ef0724202e6a6848ece6e0cbba64d11e2f11aefe744af1d93c6d9f99bb"
+fetch_checked "$MONO_URL" "$WORK/wine-mono.tar.xz" "$MONO_SHA256"
mkdir -p "$WORK/mono"
tar -xJf "$WORK/wine-mono.tar.xz" -C "$WORK/mono"
echo " Got mono: $(ls "$WORK/mono" | head -1)"
diff --git a/scripts/update.sh b/scripts/update.sh
index 87f794498b6..9cb1db6726a 100755
--- a/scripts/update.sh
+++ b/scripts/update.sh
@@ -11,6 +11,47 @@ TTY=/dev/tty
say(){ printf '\n\033[1m%s\033[0m\n' "$*"; }
+# Same pin and helpers as install.sh (tests/test_installation.py keeps them equal).
+ENGINE_TAG="engine-v1.5"
+ENGINE_SHA256="7b96a4407308493ae92bebe96039bbc8d0bf3b86c22cb99c782f73cf7be3738e"
+ENGINE_URL="https://github.com/$REPO/releases/download/$ENGINE_TAG/wine-engine-x86_64.tar.xz"
+
+fetch_verified(){ # url, dest, sha256
+ local got
+ rm -f "$2.part"
+ curl -fL "$1" -o "$2.part" || { rm -f "$2.part"; return 1; }
+ got=$(shasum -a 256 "$2.part" | awk '{print $1}')
+ if [ "$got" != "$3" ]; then
+ rm -f "$2.part"
+ printf 'Checksum mismatch for %s\n expected %s\n got %s\n' "$1" "$3" "$got"
+ return 1
+ fi
+ mv -f "$2.part" "$2"
+}
+
+latest_release(){
+ local json i j tag name n digest
+ json=$(mktemp) || return 1
+ if ! curl -fsSL "https://api.github.com/repos/$REPO/releases?per_page=30" -o "$json"; then
+ rm -f "$json"; return 1
+ fi
+ for i in $(seq 0 29); do
+ tag=$(plutil -extract "$i.tag_name" raw -o - "$json" 2>/dev/null) || break
+ [[ "$tag" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]] || continue
+ [ "$(plutil -extract "$i.prerelease" raw -o - "$json" 2>/dev/null)" = false ] || continue
+ name="Soju-${tag#v}-macos-arm64.zip"
+ for j in $(seq 0 19); do
+ n=$(plutil -extract "$i.assets.$j.name" raw -o - "$json" 2>/dev/null) || break
+ [ "$n" = "$name" ] || continue
+ digest=$(plutil -extract "$i.assets.$j.digest" raw -o - "$json" 2>/dev/null) || break
+ [[ "$digest" =~ ^sha256:[0-9a-f]{64}$ ]] || break
+ echo "$tag https://github.com/$REPO/releases/download/$tag/$name ${digest#sha256:}"
+ rm -f "$json"; return 0
+ done
+ done
+ rm -f "$json"; return 1
+}
+
# ---------- 1. Scripts ----------
# Once the scripts are refreshed, the rest of this run must use the new ones
# (the engine carry-over in particular changes between versions), so step 1
@@ -30,20 +71,31 @@ elif [ "$ROOT" != "$BASE/soju" ]; then
# other checkout may carry local edits.
echo " $ROOT is not the installer's copy ($BASE/soju); update it yourself (git pull, or re-download)"
else
- echo " refreshing the tarball copy at $ROOT"
- tmp="$ROOT.tmp.$$"
- mkdir -p "$tmp"
- if curl -fsSL "https://github.com/$REPO/archive/refs/heads/main.tar.gz" | tar -xz -C "$tmp" --strip-components=1; then
- # Swap directories instead of copying over the running script.
- chmod +x "$tmp"/scripts/*.sh "$tmp"/scripts/soju 2>/dev/null || true
- rm -rf "$ROOT.old"; mv "$ROOT" "$ROOT.old"; mv "$tmp" "$ROOT"; rm -rf "$ROOT.old"
- tmp=""
- echo " scripts updated"
- exec bash "$ROOT/scripts/update.sh" --scripts-updated "$@"
+ # The installer's copy follows releases, never main: take the newest release
+ # zip, check its SHA-256 and swap in the scripts it carries.
+ cur="v$(cat "$ROOT/VERSION" 2>/dev/null || echo unknown)"
+ if ! rel=$(latest_release); then
+ echo " could not find a release with a recorded checksum (offline?); skipping the scripts update"
+ elif [ "${rel%% *}" = "$cur" ]; then
+ echo " scripts are up to date ($cur)"
else
- echo " download failed; skipping the scripts update"
+ read -r tag url sum <<<"$rel"
+ echo " $cur -> $tag"
+ tmp="$ROOT.tmp.$$"
+ rm -rf "$tmp"; mkdir -p "$tmp"
+ if fetch_verified "$url" "$tmp/soju.zip" "$sum" \
+ && ditto -x -k "$tmp/soju.zip" "$tmp/app" \
+ && [ -f "$tmp/app/Soju.app/Contents/Resources/soju/scripts/update.sh" ]; then
+ new="$tmp/app/Soju.app/Contents/Resources/soju"
+ chmod +x "$new"/install.sh "$new"/scripts/*.sh "$new"/scripts/soju 2>/dev/null || true
+ # Swap directories instead of copying over the running script.
+ rm -rf "$ROOT.old"; mv "$ROOT" "$ROOT.old"; mv "$new" "$ROOT"; rm -rf "$ROOT.old" "$tmp"
+ echo " scripts updated"
+ exec bash "$ROOT/scripts/update.sh" --scripts-updated "$@"
+ fi
+ echo " download or check failed; skipping the scripts update"
+ rm -rf "$tmp"
fi
- [ -n "$tmp" ] && rm -rf "$tmp"
fi
fi
@@ -57,16 +109,9 @@ if [ ! -x "$ENGINE/bin/wine" ]; then
echo " no launchers installed (run: soju install)"; exit 0
fi
-# The asset is named wine-engine-*.tar.xz from engine-v1.4 on. Older
-# updaters looked for soju-engine-* and, after refreshing the scripts, went on
-# to swap the engine with their own carry-over code, which dropped Apple's D3D
-# shims. The rename makes that updater stop at "could not find the engine
-# release asset" instead; the next run uses this script and carries the
-# shims over.
-URL=$(curl -fsSL "https://api.github.com/repos/$REPO/releases?per_page=30" \
- | grep -o '"browser_download_url": *"[^"]*wine-engine[^"]*"' | head -1 | grep -o 'https[^"]*') || true
-[ -n "${URL:-}" ] || { echo " could not find the engine release asset (offline? If the scripts were just updated, run soju update once more)"; exit 1; }
-TAG=$(echo "$URL" | sed -n 's#.*/download/\([^/]*\)/.*#\1#p')
+# The engine is pinned (ENGINE_TAG/ENGINE_SHA256 above): moving users to a new
+# engine release takes a script release that names it.
+TAG="$ENGINE_TAG"
CUR=$(cat "$ENGINE/.soju-engine-release" 2>/dev/null || echo "")
if [ -n "$CUR" ] && [ "$CUR" = "$TAG" ]; then
@@ -91,8 +136,7 @@ if pgrep -x wineserver >/dev/null 2>&1; then
fi
echo " downloading $TAG"
-curl -fL "$URL" -o "$BASE/engine.tar.xz.part"
-mv -f "$BASE/engine.tar.xz.part" "$BASE/engine.tar.xz"
+fetch_verified "$ENGINE_URL" "$BASE/engine.tar.xz" "$ENGINE_SHA256" || { echo " keeping the current engine"; exit 1; }
NEW="$ENGINE.new"
rm -rf "$NEW"; mkdir -p "$NEW"
tar -xJf "$BASE/engine.tar.xz" -C "$NEW"
diff --git a/tests/test_installation.py b/tests/test_installation.py
index 14a8a049273..f4fc0e8da07 100644
--- a/tests/test_installation.py
+++ b/tests/test_installation.py
@@ -256,5 +256,87 @@ class SupportManifestTests(unittest.TestCase):
self.assertIn('apply_once dxmt "$ROOT/patches/' + patch + '"', script)
self.assertIn("d3d11.maxTessFactor", (ROOT/"patches/dxmt-max-tess-factor.patch").read_text())
+class DownloadCheckTests(unittest.TestCase):
+ """install.sh and update.sh run only checked downloads, never main."""
+ SCRIPTS = ("install.sh", "scripts/update.sh")
+
+ def shell_function(self, script, name):
+ text = (ROOT/script).read_text()
+ start = text.index(name + "(){")
+ return text[start:text.index("\n}\n", start) + 3]
+
+ def run_bash(self, code, env=None):
+ return subprocess.run(["/bin/bash", "-c", code], capture_output=True, text=True,
+ env={**os.environ, **(env or {})})
+
+ def test_engine_pin_is_the_same_everywhere(self):
+ import re
+ pins = set()
+ for script in self.SCRIPTS:
+ text = (ROOT/script).read_text()
+ tag = re.search(r'^ENGINE_TAG="([^"]+)"$', text, re.M).group(1)
+ sha = re.search(r'^ENGINE_SHA256="([0-9a-f]{64})"$', text, re.M).group(1)
+ pins.add((tag, sha))
+ self.assertEqual(len(pins), 1, pins)
+
+ def test_no_unchecked_downloads_of_code(self):
+ for script in self.SCRIPTS + ("scripts/get-components.sh", "scripts/build-engine.sh"):
+ text = (ROOT/script).read_text()
+ self.assertNotIn("refs/heads/main", text, script)
+ self.assertNotIn("browser_download_url", text, script)
+ self.assertNotRegex(text, r"curl [^\n]*\| *tar", script)
+
+ def test_helpers_are_identical_in_both_scripts(self):
+ for name in ("fetch_verified", "latest_release"):
+ a, b = (self.shell_function(s, name) for s in self.SCRIPTS)
+ self.assertEqual(a, b, name)
+
+ def test_fetch_verified_keeps_only_matching_files(self):
+ fn = self.shell_function("install.sh", "fetch_verified")
+ with tempfile.TemporaryDirectory() as t:
+ src = Path(t)/"src.bin"; src.write_bytes(b"soju")
+ good = hashlib.sha256(b"soju").hexdigest()
+ ok = self.run_bash(fn + f'fetch_verified "file://{src}" "{t}/ok" {good}')
+ self.assertEqual(ok.returncode, 0, ok.stdout + ok.stderr)
+ self.assertEqual((Path(t)/"ok").read_bytes(), b"soju")
+ bad = self.run_bash(fn + f'fetch_verified "file://{src}" "{t}/bad" {"0" * 64}')
+ self.assertNotEqual(bad.returncode, 0)
+ self.assertIn("Checksum mismatch", bad.stdout)
+ self.assertFalse((Path(t)/"bad").exists())
+ self.assertFalse((Path(t)/"bad.part").exists())
+
+ def latest(self, releases):
+ fn = self.shell_function("install.sh", "latest_release")
+ with tempfile.TemporaryDirectory() as t:
+ fixture = Path(t)/"releases.json"; fixture.write_text(json.dumps(releases))
+ fake_curl = f'curl(){{ cp "{fixture}" "${{@: -1}}"; }}\n'
+ return self.run_bash('REPO=BCD1210/soju\n' + fake_curl + fn + "latest_release")
+
+ def test_latest_release_picks_newest_stable_app_zip_with_digest(self):
+ d = "a" * 64
+ result = self.latest([
+ {"tag_name": "engine-v9", "prerelease": False, "assets": [{"name": "wine-engine-x86_64.tar.xz", "digest": "sha256:" + d}]},
+ {"tag_name": "v2.0.0", "prerelease": True, "assets": [{"name": "Soju-2.0.0-macos-arm64.zip", "digest": "sha256:" + d}]},
+ {"tag_name": "v1.9.0", "prerelease": False, "assets": [{"name": "Soju-1.9.0-macos-arm64.zip", "digest": None}]},
+ {"tag_name": "v1.8.0", "prerelease": False, "assets": [
+ {"name": "Soju-1.8.0-macos-arm64.zip.sha256", "digest": "sha256:" + "b" * 64},
+ {"name": "Soju-1.8.0-macos-arm64.zip", "digest": "sha256:" + d}]},
+ ])
+ self.assertEqual(result.returncode, 0, result.stderr)
+ self.assertEqual(result.stdout.split(), ["v1.8.0",
+ "https://github.com/BCD1210/soju/releases/download/v1.8.0/Soju-1.8.0-macos-arm64.zip", d])
+
+ def test_latest_release_fails_without_a_checked_zip(self):
+ result = self.latest([{"tag_name": "v1.0.0", "prerelease": False, "assets": []}])
+ self.assertNotEqual(result.returncode, 0)
+ self.assertEqual(result.stdout, "")
+
+ def test_build_downloads_are_pinned(self):
+ for script, count in (("scripts/get-components.sh", 2), ("scripts/build-engine.sh", 2),
+ ("scripts/build-steam-support.sh", 1)):
+ text = (ROOT/script).read_text()
+ self.assertEqual(text.count("fetch_checked \"$") + text.count("fetch_checked https"), count, script)
+ self.assertNotIn(".part\" && mv", text, script)
+
if __name__ == "__main__":
unittest.main()