chamesle-exe (3197B)
1 #!/bin/sh 2 # double-clicked a windows program: run it with wine, installing and setting things up the first time 3 f=$1 4 # python looks it up: the gettext program isn't on every system, python is 5 _() { python3 -c 'import gettext, sys; gettext.textdomain("chamesle"); sys.stdout.write(gettext.gettext(sys.argv[1]))' "$1" 2>/dev/null || printf %s "$1"; } 6 title=$(_ "Windows program") 7 [ -n "$f" ] || { echo "usage: chamesle-exe FILE.exe" >&2; exit 1; } 8 9 # free space in MB where it all goes; the live session keeps everything in memory and runs out fast 10 room() { df -Pm "$1" | awk 'NR == 2 { print $4 }'; } 11 no_room() { 12 if [ "$(id -un)" = live ]; then 13 zenity --error --title="$title" --text="$(_ "Windows programs need about 3 GB of space, and this live session doesn't have that much memory to spare.\n\nInstall Chamesle first, then open the program again.")" 14 else 15 zenity --error --title="$title" --text="$(printf "$(_ "Windows programs need about %s GB of free space. Make some room and try again.")" "$1")" 16 fi 17 exit 1 18 } 19 20 if ! command -v wine >/dev/null; then 21 [ "$(room /usr)" -ge 3200 ] || no_room 3 22 zenity --question --title="$title" --icon=application-x-ms-dos-executable --ok-label="$(_ "Install")" --cancel-label="$(_ "Cancel")" \ 23 --text="$(printf "$(_ "To open %s, Chamesle needs Windows support (Wine).\n\nIt's a 650 MB download and takes about 3 GB on disk.\n\nInstall it now?")" "<b>$(basename "$f" | sed 's/&/\&/g; s/</\</g')</b>")" || exit 0 24 # the subshell keeps the pipe open, so the progress window stays up until apk is done 25 (pkexec /usr/libexec/chamesle-store-helper add wine wine-mono wine-gecko dxvk >/dev/null 2>&1; echo 100) | 26 zenity --progress --pulsate --auto-close --no-cancel --title="$title" --text="$(_ "Installing Windows support...")" 27 if ! command -v wine >/dev/null; then 28 zenity --error --title="$title" --text="$(_ "Windows support couldn't be installed. Check that you're online and try again.")" 29 exit 1 30 fi 31 fi 32 33 export WINEPREFIX="${WINEPREFIX:-$HOME/.wine}" WINEDEBUG=-all 34 35 # dxvk needs a vulkan driver: intel, newer amd cards, or nvidia's own 36 vulkan() { 37 for d in /sys/class/drm/card*/device/driver; do 38 case $(basename "$(readlink "$d")") in i915|xe|amdgpu|nvidia) return 0 ;; esac 39 done 40 return 1 41 } 42 43 setup() { 44 wineboot --init 45 wineserver --wait 46 if [ -d /usr/share/dxvk ] && vulkan; then 47 sys="$WINEPREFIX/drive_c/windows" 48 for dll in /usr/share/dxvk/x64/*.dll; do cp -f "$dll" "$sys/system32/"; done 49 for dll in /usr/share/dxvk/x32/*.dll; do cp -f "$dll" "$sys/syswow64/"; done 50 for name in d3d8 d3d9 d3d10core d3d11 dxgi; do 51 wine reg add 'HKCU\Software\Wine\DllOverrides' /v "$name" /d native,builtin /f 52 done 53 wineserver --wait 54 fi 55 } 56 57 if [ ! -f "$WINEPREFIX/system.reg" ]; then 58 [ "$(room "$HOME")" -ge 1200 ] || no_room 1 59 (setup >/dev/null 2>&1; echo 100) | 60 zenity --progress --pulsate --auto-close --no-cancel --title="$title" \ 61 --text="$(_ "Setting up Windows support. This only happens once...")" 62 fi 63 64 cd "$(dirname "$f")" || exit 1 65 exec wine start /unix "$f"