arfbtwn

wine wrapper

Oct 31st, 2020
2,139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.71 KB | None | 0 0
  1. ## wine wrapper, install on your path somewhere
  2.  
  3. #!/usr/bin/env bash
  4.  
  5. WINE_DDRAW_OVERRIDE=WINEDLLOVERRIDES="ddraw=n"
  6. NVIDIA_PRIME_GLX=__NV_PRIME_RENDER_OFFLOAD=1\ __GLX_VENDOR_LIBRARY_NAME=nvidia
  7.  
  8. config=${CONFIG:-~/.config/wine-wrapper.conf}
  9.  
  10. function name() {
  11.     echo ${0##*/}
  12. }
  13.  
  14. function wine() {
  15.     local wine=($(which -a "$(name)"))
  16.     wine=(${wine[@]/$(realpath -s "$0")})
  17.     echo $wine;
  18. }
  19.  
  20. function usage() {
  21.     cat << EOF >&2
  22. usage: $(name) [-c|--config <file>] [-d|--debug] [--print] [--glx] [--ddraw] [--clean] PROGRAM [ARGUMENTS]
  23.  
  24. --help              display this help and exit
  25. --help-wine         execute $(wine) --help
  26.  
  27. -c,--config <file>  use <file> instead of ${config}
  28. --print             print complete environment and exit
  29.  
  30. -d,--debug          echo commands to console
  31. --glx               set ${NVIDIA_PRIME_GLX}
  32. --ddraw             set ${WINE_DDRAW_OVERRIDE}
  33. --clean             unset environment
  34. EOF
  35.     exit
  36. }
  37.  
  38. TEMP=$(getopt -n "$(name)" -o "?hdc:" -l "help,help-wine,debug,print,glx,ddraw,clean,config:" -- "$@")
  39.  
  40. [[ $? -ne 0 ]] && usage
  41.  
  42. eval set -- "$TEMP"
  43. unset TEMP
  44.  
  45. auto=true
  46. clean=false
  47. debug=
  48. print=false
  49.  
  50. while true
  51. do
  52.     case "$1" in
  53.         -\?|-h|--help)
  54.             usage
  55.             ;;
  56.         --help-wine)
  57.             exec $(wine) --help
  58.             ;;
  59.         -c|--config)
  60.             config=$2
  61.             shift 2
  62.             ;;
  63.         -d|--debug)
  64.             debug=echo
  65.             shift
  66.             ;;
  67.         --print)
  68.             print=true
  69.             shift
  70.             ;;
  71.         --glx)
  72.             env+=(${NVIDIA_PRIME_GLX})
  73.             auto=false
  74.             shift
  75.             ;;
  76.         --ddraw)
  77.             env+=(${WINE_DDRAW_OVERRIDE})
  78.             auto=false
  79.             shift
  80.             ;;
  81.         --clean)
  82.             clean=true
  83.             auto=false
  84.             shift
  85.             ;;
  86.         --)
  87.             shift
  88.             break
  89.             ;;
  90.         *)
  91.             usage
  92.             ;;
  93.     esac
  94. done
  95.  
  96. declare -A environment
  97.  
  98. [[ -r ${config} ]] && . ${config}
  99.  
  100. $print && {
  101.     for key in "${!environment[@]}"
  102.     do
  103.         printf "%s: %s\n" "${key}" "${environment[$key]}"
  104.     done
  105.     exit
  106. }
  107.  
  108. [[ $# -eq 0 ]] && usage
  109.  
  110. $clean && unset env
  111.  
  112. shopt -s nocasematch
  113.  
  114. $auto && for arg
  115. do
  116.     case "${arg,,}" in
  117.         *.lnk|*.exe)
  118.             path=$(realpath -qe "$arg")
  119.             ;;
  120.         *)
  121.             continue
  122.             ;;
  123.     esac
  124.  
  125.     for key in "${!environment[@]}"
  126.     do
  127.         [[ $arg =~ $key ]] || [[ $path =~ $key ]] && env=${environment[$key]}
  128.     done
  129.  
  130.     unset path
  131. done
  132.  
  133. ## FIXME: since debug here is a simple echo, argument quoting is swallowed
  134. if [ -v env ]; then
  135.     $debug env ${env[@]} $(wine) "$@"
  136. else
  137.     $debug $(wine) "$@"
  138. fi
  139.  
  140. $debug xrandr -s 0
  141.  
  142. ## Example configuration file
  143.  
  144. #!/usr/bin/env bash
  145.  
  146. declare -A environment=(
  147.  
  148.     [Stardock/Impulse.lnk]=
  149.     [Stardock/Open Impulse Dock.lnk]=
  150.     [Galactic Civilizations II - Ultimate Edition/Galactic Civilizations II - Ultimate Edition.lnk]=
  151.  
  152.     [Doom 3/Documentation.lnk]=
  153.     [Doom 3/1.3 Patch Readme.lnk]=
  154.     [Doom 3/Doom 3.lnk]=${NVIDIA_PRIME_GLX}
  155.     [Doom 3/Uninstall Doom 3.lnk]=
  156.  
  157.     [Tiberian Sun/Tiberian Sun Game.lnk]=${WINE_DDRAW_OVERRIDE}
  158.     [Tiberian Sun/Tiberian Sun Launcher.lnk]=${WINE_DDRAW_OVERRIDE}
  159.     [Tiberian Sun/Uninstall Command & Conquer Tiberian Sun.lnk]=
  160.  
  161.     [Total War - Rome II/Uninstall.lnk]=
  162.     [Total War - Rome II/Total War - Rome II.lnk]=${NVIDIA_PRIME_GLX}
  163.  
  164.     [Command & Conquer 95/Command & Conquer Gold Configuration.lnk]=
  165.     [Command & Conquer 95/Uninstall C&C95.lnk]=
  166.     [Command & Conquer 95/Command & Conquer Windows 95 Edition.lnk]=${WINE_DDRAW_OVERRIDE}
  167.  
  168.     [DOOM 3 Resurrection of Evil/Documentation.lnk]=
  169.     [DOOM 3 Resurrection of Evil/Uninstall DOOM 3 Resurrection of Evil.lnk]=
  170.     [DOOM 3 Resurrection of Evil/DOOM 3 Resurrection of Evil.lnk]=${NVIDIA_PRIME_GLX}
  171.  
  172.     [Red Alert/Red Alert.lnk]=${WINE_DDRAW_OVERRIDE}
  173.  
  174.     [Full Control Studios/Space Hulk/Space Hulk.lnk]=${NVIDIA_PRIME_GLX}
  175.     [Full Control Studios/Space Hulk/Uninstall Space Hulk.lnk]=
  176.     [Space Hulk - Ascension/Space Hulk - Ascension.lnk]=${NVIDIA_PRIME_GLX}
  177.     [Space Hulk - Ascension/Uninstall Space Hulk - Ascension.lnk]=
  178.     [Space Hulk - Deathwing EE/Space Hulk - Deathwing EE.lnk]=${NVIDIA_PRIME_GLX}
  179.     [Space Hulk - Deathwing EE/Uninstall Space Hulk - Deathwing EE.lnk]=
  180.  
  181.     [GalCiv2.exe]=
  182.     [Rome2.exe]=${NVIDIA_PRIME_GLX}
  183.     [DOOM3.exe]=${NVIDIA_PRIME_GLX}
  184.     [C&C95.exe]=${WINE_DDRAW_OVERRIDE}
  185.     [ra95.exe]=${WINE_DDRAW_OVERRIDE}
  186.     [Tiberian Sun/Game.exe]=${WINE_DDRAW_OVERRIDE}
  187.     [Tiberian Sun/Launcher.exe]=${WINE_DDRAW_OVERRIDE}
  188.  
  189. )
Advertisement
Add Comment
Please, Sign In to add comment