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/update: survive interrupted downloads and extracts, refuse to swap a running engine

mikey92f4cb0ab7d998
diff --git a/install.sh b/install.sh
index 684cebc45ab..d4500594ed8 100644
--- a/install.sh
+++ b/install.sh
@@ -25,7 +25,9 @@ say(){ printf '\n\033[1m%s\033[0m\n' "$*"; }
mkdir -p "$BASE"
# ---------- 1. Engine ----------
-if [ -x "$ENGINE/bin/wine" ]; then
+# bin/wine alone can be left behind by an interrupted extract; only an engine
+# that actually starts counts as present.
+if [ -x "$ENGINE/bin/wine" ] && DYLD_FALLBACK_LIBRARY_PATH="$ENGINE/lib:/usr/lib" "$ENGINE/bin/wine" --version >/dev/null 2>&1; then
say "[1/4] Engine already present - skipping"
else
say "[1/4] Downloading prebuilt engine (~350MB, GPL - built from CodeWeavers' published Wine sources)"
@@ -34,12 +36,21 @@ else
URL=$(curl -fsSL "https://api.github.com/repos/$REPO/releases?per_page=30" \
| grep -o '"browser_download_url": *"[^"]*soju-engine[^"]*"' | head -1 | grep -o 'https[^"]*')
[ -n "$URL" ] || { echo "Could not find the engine release asset."; exit 1; }
- curl -fL "$URL" -o "$BASE/engine.tar.xz"
- mkdir -p "$ENGINE"
- tar -xJf "$BASE/engine.tar.xz" -C "$ENGINE"
+ # 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"
+ 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')
- [ -n "$TAG" ] && printf '%s\n' "$TAG" > "$ENGINE/.soju-engine-release"
+ printf '%s\n' "${TAG:-unknown}" > "$ENGINE.new/.soju-engine-release"
+ if [ -d "$ENGINE" ]; then
+ # A half-extracted engine from an earlier run; keep any GPTK payload in it.
+ [ -d "$ENGINE/lib/external" ] && cp -Rf "$ENGINE/lib/external" "$ENGINE.new/lib/" 2>/dev/null || true
+ rm -rf "$ENGINE"
+ fi
+ mv "$ENGINE.new" "$ENGINE"
v=$(DYLD_FALLBACK_LIBRARY_PATH="$ENGINE/lib:/usr/lib" "$ENGINE/bin/wine" --version 2>&1) \
|| { echo "The engine does not start on this Mac:"; echo "$v"; echo "Please report this with the output of: sw_vers; uname -m"; exit 1; }
echo "Engine OK: $v"
diff --git a/scripts/build-engine.sh b/scripts/build-engine.sh
index 5e9acd29631..9cc96890713 100755
--- a/scripts/build-engine.sh
+++ b/scripts/build-engine.sh
@@ -25,7 +25,7 @@ export PATH="/opt/homebrew/opt/bison/bin:/opt/homebrew/bin:$PATH"
mkdir -p "$WORK" "$DEPS"
echo "==> Downloading CrossOver 26.3 sources + freetype"
-[ -f "$WORK/cx-src.tar.gz" ] || curl -fL "$SRC_URL" -o "$WORK/cx-src.tar.gz"
+[ -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"; }
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
@@ -49,7 +49,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"
+[ -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"; }
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/create-bottle.sh b/scripts/create-bottle.sh
index 986d71d637c..8d4139bf9d9 100755
--- a/scripts/create-bottle.sh
+++ b/scripts/create-bottle.sh
@@ -35,7 +35,7 @@ done
echo "==> Downloading the Battle.net installer (official Blizzard)"
SETUP="$WORK/Battle.net-Setup.exe"
-[ -f "$SETUP" ] || curl -fL "https://downloader.battle.net/download/getInstaller?os=win&installer=Battle.net-Setup.exe" -o "$SETUP"
+[ -f "$SETUP" ] || { curl -fL "https://downloader.battle.net/download/getInstaller?os=win&installer=Battle.net-Setup.exe" -o "$SETUP.part" && mv -f "$SETUP.part" "$SETUP"; }
echo "==> Running the installer (a few minutes, fully automatic)"
"$ENGINE/bin/wine" "$SETUP" --lang=enUS >/dev/null 2>&1 || true
diff --git a/scripts/create-epic-bottle.sh b/scripts/create-epic-bottle.sh
index 47a839f2e31..146458a93ec 100755
--- a/scripts/create-epic-bottle.sh
+++ b/scripts/create-epic-bottle.sh
@@ -28,7 +28,7 @@ echo "==> Initializing the prefix: $WINEPREFIX"
echo "==> Downloading the Epic Games Launcher installer (official Epic MSI)"
MSI="$WORK/EpicGamesLauncherInstaller.msi"
-[ -f "$MSI" ] || curl -fL "https://launcher-public-service-prod06.ol.epicgames.com/launcher/api/installer/download/EpicGamesLauncherInstaller.msi" -o "$MSI"
+[ -f "$MSI" ] || { curl -fL "https://launcher-public-service-prod06.ol.epicgames.com/launcher/api/installer/download/EpicGamesLauncherInstaller.msi" -o "$MSI.part" && mv -f "$MSI.part" "$MSI"; }
echo "==> Running the installer (unattended, about half a minute)"
"$W" msiexec /i "$MSI" /qn >/dev/null 2>&1 || true
diff --git a/scripts/create-gog-bottle.sh b/scripts/create-gog-bottle.sh
index d9f64f65637..7ed7851c044 100755
--- a/scripts/create-gog-bottle.sh
+++ b/scripts/create-gog-bottle.sh
@@ -31,7 +31,7 @@ echo "==> Initializing the prefix: $WINEPREFIX"
echo "==> Downloading the GOG GALAXY installer"
EXE="$WORK/setup_galaxy.exe"
-[ -f "$EXE" ] || curl -fL "https://webinstallers.gog-statics.com/download/GOG_Galaxy_2.0.exe" -o "$EXE"
+[ -f "$EXE" ] || { curl -fL "https://webinstallers.gog-statics.com/download/GOG_Galaxy_2.0.exe" -o "$EXE.part" && mv -f "$EXE.part" "$EXE"; }
echo "==> Running the installer (silent; it downloads the client, a few minutes)"
"$W" "$EXE" /VERYSILENT /NORESTART /SUPPRESSMSGBOXES >/dev/null 2>&1 || true
diff --git a/scripts/create-steam-bottle.sh b/scripts/create-steam-bottle.sh
index 1e1407309f3..071e12dbc41 100755
--- a/scripts/create-steam-bottle.sh
+++ b/scripts/create-steam-bottle.sh
@@ -44,7 +44,7 @@ echo "==> Initializing the prefix: $WINEPREFIX"
"$WINESTABLE_APP/Contents/Resources/wine/bin/wineserver" -w 2>/dev/null || true
SETUP="$WORK/SteamSetup.exe"
-[ -f "$SETUP" ] || curl -fL "https://cdn.cloudflare.steamstatic.com/client/installer/SteamSetup.exe" -o "$SETUP"
+[ -f "$SETUP" ] || { curl -fL "https://cdn.cloudflare.steamstatic.com/client/installer/SteamSetup.exe" -o "$SETUP.part" && mv -f "$SETUP.part" "$SETUP"; }
echo "==> Installing Steam silently"
"$WINE" "$SETUP" /S >/dev/null 2>&1 || true
"$WINESTABLE_APP/Contents/Resources/wine/bin/wineserver" -w 2>/dev/null || true
diff --git a/scripts/get-components.sh b/scripts/get-components.sh
index 84fdeab684c..95edd9a2bbc 100755
--- a/scripts/get-components.sh
+++ b/scripts/get-components.sh
@@ -10,7 +10,7 @@ DEPS="$WORK/deps"; mkdir -p "$DEPS/lib" "$WORK"
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"
+[ -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"; }
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 +18,7 @@ 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"
+[ -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"; }
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/uninstall.sh b/scripts/uninstall.sh
index ec76a2f80a2..7d24e61891c 100755
--- a/scripts/uninstall.sh
+++ b/scripts/uninstall.sh
@@ -52,7 +52,20 @@ if [ -d "$ENGINE" ]; then
fi
fi
-# 5. The scripts copy made by the one-line installer.
+# 5. Caches and support files: downloaded installers and sources (build/),
+# compiled helpers (*-support/), logs, and leftovers of an interrupted update.
+extras=()
+for d in build steam-support epic-support gog-support logs cx26-engine.old cx26-engine.new soju.old; do
+ [ -e "$BASE/$d" ] && extras+=("$BASE/$d")
+done
+if [ "${#extras[@]}" -gt 0 ]; then
+ sz=$(du -shc "${extras[@]}" 2>/dev/null | tail -1 | cut -f1)
+ printf 'Caches and support files (%s):\n' "$sz"; printf ' %s\n' "${extras[@]}"
+ if ask "Remove these?"; then rm -rf "${extras[@]}"; echo " removed"; fi
+fi
+rm -f "$BASE"/reaper-*.log "$BASE"/*.tar.xz "$BASE"/*.part 2>/dev/null || true
+
+# 6. The scripts copy made by the one-line installer.
if [ -d "$BASE/soju" ]; then
if ask "Remove the scripts copy at $BASE/soju?"; then rm -rf "$BASE/soju"; echo " removed"; fi
fi
diff --git a/scripts/update.sh b/scripts/update.sh
index 0bc2462319e..d406b371779 100755
--- a/scripts/update.sh
+++ b/scripts/update.sh
@@ -13,23 +13,29 @@ say(){ printf '\n\033[1m%s\033[0m\n' "$*"; }
# ---------- 1. Scripts ----------
say "[1/2] Updating the Soju scripts"
-if [ -d "$ROOT/.git" ]; then
+if [ -e "$ROOT/.git" ]; then # a directory, or a file for worktrees/submodules
echo " git checkout at $ROOT"
git -C "$ROOT" pull --ff-only || echo " git pull failed (local changes?); skipping the scripts update"
-elif [[ "$ROOT" == */Cellar/* ]]; then
+elif [[ "$ROOT" == */Cellar/* || "$ROOT" == */opt/soju/* ]]; then
echo " installed with Homebrew; update with: brew update && brew upgrade $REPO/soju"
+elif [ "$ROOT" != "$BASE/soju" ]; then
+ # Only the copy install.sh made is ours to overwrite; a zip download or any
+ # 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
- rsync -a --delete --exclude '.git' "$tmp/" "$ROOT/" 2>/dev/null || { cp -Rf "$tmp/". "$ROOT/"; }
- chmod +x "$ROOT"/scripts/*.sh "$ROOT"/scripts/soju 2>/dev/null || true
+ # 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"
else
echo " download failed; skipping the scripts update"
fi
- rm -rf "$tmp"
+ [ -n "$tmp" ] && rm -rf "$tmp"
fi
# ---------- 2. Engine ----------
@@ -57,8 +63,17 @@ else
echo " $CUR -> $TAG"
fi
+# Processes already running keep the old engine mapped while new ones (a game
+# started from the launcher, Agent) would load the new one against the old
+# wineserver. Refuse rather than mix them.
+if pgrep -x wineserver >/dev/null 2>&1; then
+ echo " a launcher or game is still running; close it first (soju kill / epic-kill / gog-kill / steam-kill) and run soju update again"
+ exit 1
+fi
+
echo " downloading $TAG"
-curl -fL "$URL" -o "$BASE/engine.tar.xz"
+curl -fL "$URL" -o "$BASE/engine.tar.xz.part"
+mv -f "$BASE/engine.tar.xz.part" "$BASE/engine.tar.xz"
NEW="$ENGINE.new"
rm -rf "$NEW"; mkdir -p "$NEW"
tar -xJf "$BASE/engine.tar.xz" -C "$NEW"