rinkplanner/tools/setup_windows_export.sh

94 lines
3.1 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
# Richtet rcedit für Windows-Exporte auf Linux ein.
#
# Godot bettet Icon, Versionsinfo und Produktdaten in die .exe ein, indem es
# rcedit aufruft. rcedit ist ein Windows-Programm; auf Linux läuft es über ein
# portables Wine (kein Root nötig).
#
# Aufruf:
# ./tools/setup_windows_export.sh
#
# Danach den Windows-Build neu erzeugen:
# ./tools/export_windows.sh
set -euo pipefail
TOOLCHAIN="${TOOLCHAIN:-$HOME/.local/share/rinkplanner-toolchain}"
WINE_VERSION="${WINE_VERSION:-11.20}"
RCEDIT_VERSION="${RCEDIT_VERSION:-2.0.0}"
WINE_URL="https://github.com/Kron4ek/Wine-Builds/releases/download/${WINE_VERSION}/wine-${WINE_VERSION}-amd64.tar.xz"
RCEDIT_URL="https://github.com/electron/rcedit/releases/download/v${RCEDIT_VERSION}/rcedit-x64.exe"
log() { printf '\n==> %s\n' "$*"; }
command -v curl >/dev/null || { echo "Fehlt: curl" >&2; exit 1; }
command -v tar >/dev/null || { echo "Fehlt: tar" >&2; exit 1; }
command -v python3 >/dev/null || { echo "Fehlt: python3" >&2; exit 1; }
mkdir -p "$TOOLCHAIN"
if compgen -G "$TOOLCHAIN/wine-*/bin/wine" >/dev/null; then
log "Wine vorhanden: $(ls -d "$TOOLCHAIN"/wine-*/bin/wine | head -1)"
else
log "Lade portables Wine $WINE_VERSION"
curl -fL --retry 3 -o "$TOOLCHAIN/wine.tar.xz" "$WINE_URL"
tar -xf "$TOOLCHAIN/wine.tar.xz" -C "$TOOLCHAIN"
rm -f "$TOOLCHAIN/wine.tar.xz"
fi
if [[ -f "$TOOLCHAIN/rcedit-x64.exe" ]]; then
log "rcedit vorhanden"
else
log "Lade rcedit $RCEDIT_VERSION"
curl -fL --retry 3 -o "$TOOLCHAIN/rcedit-x64.exe" "$RCEDIT_URL"
fi
log "Schreibe Wrapper $TOOLCHAIN/rcedit"
cat > "$TOOLCHAIN/rcedit" <<'WRAPPER'
#!/usr/bin/env bash
set -euo pipefail
TOOLCHAIN="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
WINE_BIN="$(ls -d "$TOOLCHAIN"/wine-*/bin/wine | head -1)"
export WINEPREFIX="${WINEPREFIX:-$TOOLCHAIN/wineprefix}"
export WINEDEBUG="${WINEDEBUG:--all}"
exec "$WINE_BIN" "$TOOLCHAIN/rcedit-x64.exe" "$@" \
2> >(grep -vE "libEGL|pci id|egl: failed" >&2)
WRAPPER
chmod +x "$TOOLCHAIN/rcedit"
log "Initialisiere Wine-Prefix (einmalig)"
WINEPREFIX="$TOOLCHAIN/wineprefix" WINEDEBUG=-all \
"$(ls -d "$TOOLCHAIN"/wine-*/bin/wine | head -1)" --version >/dev/null
log "Trage rcedit in die Godot-Editor-Settings ein"
python3 - "$TOOLCHAIN/rcedit" <<'PY'
import pathlib
import re
import shutil
import sys
wrapper = sys.argv[1]
patched = 0
for path in sorted((pathlib.Path.home() / ".config" / "godot").glob("editor_settings-4.*.tres")):
text = path.read_text()
shutil.copy2(path, path.with_suffix(path.suffix + ".bak"))
line = f'export/windows/rcedit = "{wrapper}"'
if re.search(r'^export/windows/rcedit = .*$', text, flags=re.M):
text = re.sub(r'^export/windows/rcedit = .*$', line, text, flags=re.M)
else:
text = text.rstrip() + "\n" + line + "\n"
path.write_text(text)
print(f" {path}")
patched += 1
if patched == 0:
print(" keine passende editor_settings-4.*.tres gefunden")
PY
log "Fertig"
cat <<EOF
rcedit-Wrapper: $TOOLCHAIN/rcedit
Windows-Build: ./tools/export_windows.sh
Die .exe enthält danach Icon, Produktname, Beschreibung und Version aus
rinkplanner/export_presets.cfg (application/*).
EOF