proton.sh 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #!/bin/bash
  2. # Proton builds for live WE, next to the system Wine rig (README "Proton")
  3. # proton.sh available [ge|cachyos|valve] releases that can be installed
  4. # proton.sh install <name> GE-Proton11-9, cachyos-11.0-20261005-slr, proton-experimental (Valve)
  5. # proton.sh list installed builds
  6. # proton.sh env <name> WE_WINE_DIR/WE_PREFIX for the we_*.sh scripts (also WE_PROTON=<name>)
  7. # proton.sh remove <name>
  8. # proton.sh i686 private i686 glibc for images without /lib/ld-linux.so.2 (see below)
  9. # Each build gets a shim dir ($PROTON_DIR/<name>/shim/bin/wine, wineserver): wine goes through Proton's `run`
  10. # (proton_run.py), so WE sees the environment and prefix setup (DXVK, vkd3d-proton, fonts, wine-mono) Steam would
  11. # give it, minus the Steam Linux Runtime container (no user namespaces here, host libraries are used).
  12. # The prefix is $WE_LIVE_DIR/proton/<name>/pfx, created on the first wine call. Setup output and Proton's own
  13. # messages go to the caller's stderr like Wine's.
  14. # Proton's wine always starts through the i386 preloader (also for 64-bit programs), which needs the 32-bit
  15. # /lib/ld-linux.so.2. The image has glibc.i686 for that; without it the shim runs Proton under proot with a private
  16. # copy bound there (`proton.sh i686` fetches it, ptrace overhead, so timings are off).
  17. S=${WE_LIVE_DIR:-$HOME/.local/share/we_live}
  18. HERE=$(cd "$(dirname "$0")" && pwd)
  19. P=${PROTON_DIR:-$HOME/.local/share/proton}
  20. mkdir -p "$P/dl"
  21. gh_releases() {
  22. curl -fsSL "https://api.github.com/repos/$1/releases?per_page=${2:-15}"
  23. }
  24. shim() {
  25. local name=$1 root=$P/$1
  26. mkdir -p "$root/shim/bin" "$P/steam"
  27. cat > "$root/shim/bin/wine" <<SH
  28. #!/bin/bash
  29. # WINEPREFIX=<compat dir>/pfx as the we_*.sh scripts set it from WE_PREFIX
  30. export STEAM_COMPAT_DATA_PATH=\${WINEPREFIX%/pfx} STEAM_COMPAT_CLIENT_INSTALL_PATH=$P/steam
  31. export SteamAppId=\${SteamAppId:-431960} SteamGameId=\${SteamGameId:-431960}
  32. mkdir -p "\$STEAM_COMPAT_DATA_PATH"
  33. # the image's global d3d overrides would hide Proton's own; WE_WINED3D=1 sets dxgi=b, Proton's wined3d switch
  34. case "\$WINEDLLOVERRIDES" in *dxgi=b*) export PROTON_USE_WINED3D=1 ;; esac
  35. unset WINEDLLOVERRIDES
  36. # xalia (gamepad UI navigation, a mono process per prefix) has nothing to do with rendering
  37. export PROTON_USE_XALIA=\${PROTON_USE_XALIA:-0}
  38. run=()
  39. if [ ! -e /lib/ld-linux.so.2 ]; then
  40. [ -e "$P/i686/root/usr/lib/ld-linux.so.2" ] || { echo "no /lib/ld-linux.so.2, run proton.sh i686" >&2; exit 1; }
  41. export LD_LIBRARY_PATH=\${LD_LIBRARY_PATH:+\$LD_LIBRARY_PATH:}$P/i686/root/usr/lib
  42. run=(proot -b "$P/i686/root/usr/lib/ld-linux.so.2:/lib/ld-linux.so.2")
  43. fi
  44. # Proton's "run" path (prefix setup, DXVK overrides) with the program started directly, see proton_run.py
  45. exec "\${run[@]}" python3 "$HERE/proton_run.py" "$root/proton" "\$@"
  46. SH
  47. cat > "$root/shim/bin/wineserver" <<SH
  48. #!/bin/bash
  49. exec "$root/files/bin/wineserver" "\$@"
  50. SH
  51. chmod +x "$root/shim/bin/wine" "$root/shim/bin/wineserver"
  52. }
  53. case $1 in
  54. available)
  55. case ${2:-all} in ge|all)
  56. echo "# GE-Proton (GloriousEggroll/proton-ge-custom)"
  57. gh_releases GloriousEggroll/proton-ge-custom | python3 -c '
  58. import json, sys
  59. for r in json.load(sys.stdin):
  60. if any(a["name"].endswith("x86_64.tar.gz") for a in r["assets"]): print(r["tag_name"], r["published_at"][:10])'
  61. esac
  62. case ${2:-all} in cachyos|all)
  63. echo "# proton-cachyos (CachyOS/proton-cachyos)"
  64. gh_releases CachyOS/proton-cachyos | python3 -c '
  65. import json, sys
  66. for r in json.load(sys.stdin):
  67. if any(a["name"].endswith("-x86_64.tar.xz") for a in r["assets"]): print(r["tag_name"], r["published_at"][:10])'
  68. esac
  69. case ${2:-all} in valve|all)
  70. echo "# Valve Proton (current build of each branch, all but experimental need STEAM_USER)"
  71. printf '%s\n' proton-experimental proton-11 proton-10 proton-9 proton-8 proton-7 proton-hotfix
  72. esac
  73. ;;
  74. install)
  75. name=$2; [ -n "$name" ] || { echo "usage: proton.sh install <name>"; exit 1; }
  76. [ -x "$P/$name/proton" ] && { shim "$name"; echo "$name already installed"; exit 0; }
  77. case $name in
  78. GE-Proton*)
  79. base=https://github.com/GloriousEggroll/proton-ge-custom/releases/download/$name
  80. file=$name-x86_64.tar.gz; sum=$name-x86_64.sha512sum
  81. ;;
  82. cachyos-*)
  83. base=https://github.com/CachyOS/proton-cachyos/releases/download/$name
  84. file=proton-$name-x86_64.tar.xz; sum=proton-$name-x86_64.sha512sum
  85. ;;
  86. proton-*)
  87. exec bash "$(dirname "$0")/proton_valve.sh" "$name"
  88. ;;
  89. *) echo "unknown build $name (see proton.sh available)"; exit 1 ;;
  90. esac
  91. cd "$P/dl" || exit 1
  92. curl -fL --progress-bar -o "$file" "$base/$file" && curl -fsSL -o "$sum" "$base/$sum" || exit 1
  93. sha512sum -c "$sum" || exit 1
  94. tmp=$(mktemp -d "$P/dl/x.XXXX")
  95. tar -xf "$file" -C "$tmp" || exit 1
  96. top=$(ls "$tmp"); [ "$(echo "$top" | wc -l)" = 1 ] || { echo "unexpected archive layout"; exit 1; }
  97. mv "$tmp/$top" "$P/$name" && rmdir "$tmp" && rm -f "$file"
  98. shim "$name"
  99. echo "installed $P/$name ($(cat "$P/$name/version"))"
  100. ;;
  101. list)
  102. for d in "$P"/*/; do
  103. [ -x "$d/proton" ] || continue
  104. n=$(basename "$d"); printf '%-36s %s' "$n" "$(cut -d' ' -f2- "$d/version" 2>/dev/null)"
  105. [ -d "$S/proton/$n/pfx" ] && printf ' (prefix)'
  106. echo
  107. done
  108. ;;
  109. env)
  110. name=$2; [ -x "$P/$name/proton" ] || { echo "echo 'proton.sh: $name is not installed' >&2; exit 1"; exit 1; }
  111. [ -x "$P/$name/shim/bin/wine" ] || shim "$name"
  112. echo "export WE_WINE_DIR=$P/$name/shim WE_PREFIX=$S/proton/$name/pfx"
  113. ;;
  114. i686)
  115. mkdir -p "$P/i686/rpms" "$P/i686/root" && cd "$P/i686/rpms" || exit 1
  116. dnf download --setopt=cachedir="$P/i686/dnfcache" --arch=i686 glibc libgcc libstdc++ || exit 1
  117. cd "$P/i686/root" && for r in "$P"/i686/rpms/*.rpm; do rpm2cpio "$r" | cpio -idm --quiet; done
  118. rm -rf "$P/i686/dnfcache"
  119. ;;
  120. remove)
  121. name=$2; [ -n "$name" ] && [ -d "$P/$name" ] || { echo "not installed"; exit 1; }
  122. rm -rf "${P:?}/$name" "${S:?}/proton/$name"
  123. ;;
  124. *)
  125. sed -n '2,16p' "$0" | sed 's/^# \{0,1\}//'
  126. exit 1
  127. ;;
  128. esac