Advertisement
EvilSupahFly

Game Installer Script (v2.8) Based on JC141 Script

Mar 1st, 2024 (edited)
921
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 8.13 KB | Source Code | 0 0
  1. #!/bin/bash
  2. #
  3. # My Game Installer Script Based on the JC141 Script from BG3. v2.8
  4. #
  5. # Takes a folder name on the command line, searches for applicable .EXE files in it, displays the list asking
  6. # for input, creates all the applicable directories and a WINE prefix if the prefix doesn't already exist,
  7. # calls WINE to run the user-selected setup, downloads and installs the newest version of VULKAN, checks the
  8. # install folder for another .EXE, asking you to pick one from the list, and writes a Game Starter Script out
  9. # containing everything required to run the game in a WINE prefix, a secondary check for Vulkan updates, and
  10. # ultimately run the chosen .EXE in WINE.
  11. #
  12. # Changes from v2.75:
  13. # - Fixed the broken ".exe" finder loop that looks for the installer and moved variable declarations up top.
  14. # - Cleaned up EXE finder result string by stripping the path out, leaving just the filename.
  15. #
  16. # Changes from v2.5:
  17. # - Changed game installer from "setup.exe" to a user-selectable one using the same loop idea I added in 2.0 to
  18. #   search for the game .EXE after install since not all games use "setup.exe" explicitly, and some GoG games
  19. #   will fail if you rename the installer to "setup.exe" to accommodate the script - which I learned the hard
  20. #   way. I plan to consolidate this into a single function in the next version but BASH functions are a little
  21. #   persnickety sometimes, so this will do for now.
  22. #
  23. # Changes from v2.0:
  24. # - Added a loop to locate any ".exe" files in $GAMEDEST and store them in an array, print array as numbered list,
  25. #   ask user to select a listed ".exe" and write it to $GSS, verified with error-checking.
  26. # - Modified MSVC loop
  27.  
  28. IFS=$'\n'
  29. # Basic checks
  30. cd "$(dirname "$(readlink -f "$0")")" || exit; [ "$EUID" = "0" ] && echo "Please don't run as root!" && exit; [ "$1" = "" ] && echo "Command line can't be blank - please choose a game folder." && exit
  31.  
  32. if [ ! -d "$1" ]; then
  33.    echo "I can't find \"$1\" and suggest checking your spelling."
  34.    exit 255
  35. fi
  36.  
  37. # Declarations
  38. export G="${1// /_}"
  39. export GAMESRC="$PWD/$1"
  40. export WINEPREFIX="/home/$(whoami)/Games/jc141" #Create Wineprefix
  41. export GAMEDIR="$WINEPREFIX/drive_c/Games/$1"
  42. export GSS="$WINEPREFIX/drive_c/${G}.sh" #Convert spaces to underscores, if they exist, for the launcher script
  43. export RSRC="$PWD/redist"
  44. export WINE="$(command -v wine)"
  45. export WINEDLLOVERRIDES="winemenubuilder.exe=d;mshtml=d;nvapi,nvapi64=n"
  46. export WINE_LARGE_ADDRESS_AWARE=1
  47.  
  48. cd "$GAMESRC"
  49.  
  50. echo "Select game installer from the following list:"
  51. SETUPEXE=( $(find "$GAMESRC" -type f -name "*.exe") )
  52. echo ""
  53. PS3="#: "
  54.  
  55. select file in "${SETUPEXE[@]}"; do
  56.    if [[ -z $file ]]; then
  57.        echo "Uh... Excuse me? Let's try that again." >&2
  58.    else
  59.        EXE="${file##*/}"
  60.        echo ""
  61.        echo "You've selected \"$EXE\" - it's too late to change your mind now."
  62.        echo ""
  63.        break
  64.    fi    
  65. done
  66.  
  67. echo ""
  68. echo "Declarations:"
  69. echo ""
  70. echo "G=\"${1// /_}\""
  71. echo "GAMESRC=\"$PWD/$1\""
  72. echo "WINEPREFIX=\"/home/$(whoami)/Games/jc141\""
  73. echo "GAMEDIR=\"$WINEPREFIX/drive_c/Games"
  74. echo "GSS=\"$WINEPREFIX/drive_c/${G}.sh\""
  75. echo "RSRC=\"$PWD/redist\""
  76. echo "WINE=\"$(command -v wine)\""
  77. echo "WINEDLLOVERRIDES=\"winemenubuilder.exe=d;mshtml=d;nvapi,nvapi64=n\""
  78. echo "Game Instraller=$SETUPFILE"
  79. echo ""
  80. echo "Variables Declared. Starting Vulkan setup."
  81. echo ""
  82. echo ""
  83.  
  84. # external vulkan translation
  85. #export DXVK_ASYNC=1
  86.  
  87. [ ! -d "$GAMEDEST" ] && mkdir -p "$GAMEDEST" #If $GAMEDEST doesn't exist, create it
  88.  
  89. ping -c 1 github.com >/dev/null || { echo "Possibly no network. This may mean that booting will fail." ; }; VLKLOG="$WINEPREFIX/vulkan.log"; VULKAN="$PWD/vulkan"
  90. VLKVER="$(curl -s -m 5 https://api.github.com/repos/jc141x/vulkan/releases/latest | awk -F '["/]' '/"browser_download_url":/ {print $11}' | cut -c 1-)"
  91. status-vulkan() { [[ ! -f "$VLKLOG" || -z "$(awk "/^${FUNCNAME[1]}\$/ {print \$1}" "$VLKLOG" 2>/dev/null)" ]] || { echo "${FUNCNAME[1]} present" && return 1; }; }
  92. vulkan() { DL_URL="$(curl -s https://api.github.com/repos/jc141x/vulkan/releases/latest | awk -F '["]' '/"browser_download_url":/ {print $4}')"; VLK="$(basename "$DL_URL")"
  93. [ ! -f "$VLK" ] && command -v curl >/dev/null 2>&1 && curl -LO "$DL_URL" && tar -xvf "vulkan.tar.xz" || { rm "$VLK" && echo "ERROR: Failed to extract vulkan translation." && return 1; }
  94. rm -rf "vulkan.tar.xz" && bash "$PWD/vulkan/setup-vulkan.sh" && rm -Rf "$VULKAN"; }
  95. vulkan-dl() { echo "Using external vulkan translation (dxvk,vkd3d,dxvk-nvapi)." && vulkan && echo "$VLKVER" >"$VLKLOG"; }
  96. [[ ! -f "$VLKLOG" && -z "$(status-vulkan)" ]] && vulkan-dl;
  97. [[ -f "$VLKLOG" && -n "$VLKVER" && "$VLKVER" != "$(awk '{print $1}' "$VLKLOG")" ]] && { rm -f vulkan.tar.xz || true; } && vulkan-dl; export DXVK_ENABLE_NVAPI=1
  98.  
  99. echo ""
  100. if [ "$2" == "skip" ]
  101. then
  102.    YN="n"
  103. else
  104.    read -p "Install MSVC redistributables? (y/n) " YN
  105. fi
  106. echo ""
  107. case $YN in
  108.    [yY] ) echo "Proceeding with install.";
  109.      cd "$RSRC";
  110.      for i in *.exe;
  111.        do
  112.            echo "Installing $i into $WINEPREFIX";
  113.            "$WINE" "$i";
  114.        done;;
  115.    [nN] ) echo "Skipping redistributables. Don't blame me if something breaks.";;
  116.    * ) echo "Invalid response.";
  117.        break;;
  118. esac
  119.  
  120. # start installer
  121. echo ""
  122. echo "Starting \"$1\" installer..."
  123. echo ""
  124.  
  125. cd "$GAMESRC"
  126. "$WINE" "$EXE" "$@"
  127.  
  128. if [ $? -ne 0 ]; then
  129.    echo ""
  130.    echo "Looks like something went wrong. The error was \"$?\"."
  131.    echo ""
  132.    exit 1
  133. fi
  134.  
  135. EXE="" # Blanking it, just in case
  136.  
  137. cd "$GAMEDEST"
  138. echo "Select your executable from the following list:"
  139. echo ""
  140. EXELIST=( $(find $GAMEDEST -type f -name "*.exe") )
  141. PS3="#: "
  142.  
  143. select file in "${EXELIST[@]}"; do
  144.    if [[ -z $file ]]; then
  145.        echo "Uh... Excuse me? Let's try that again." >&2
  146.    else
  147.        EXE="${file##*/}"
  148.        echo ""
  149.        echo "You've selected: \"$EXE\""
  150.        echo "Not my fault if it doesn't work."
  151.        echo ""
  152.        break
  153.    fi
  154. done
  155.  
  156. echo ""
  157. echo "Writing Game Starter Script (GSS) for $1 to $GSS ..."
  158. echo ""
  159.  
  160. #create game starter script
  161. cat << EOL > "$GSS"
  162. #!/bin/bash
  163.  
  164. # $GSS #
  165.  
  166. cd "\$(dirname "\$(readlink -f "\$0")")" || exit; [ "\$EUID" = "0" ] && echo "Please don't run as root!" && exit
  167.  
  168. # wine
  169. export WINE="\$(command -v wine)"
  170. export WINEPREFIX="/home/\$(whoami)/Games/jc141"
  171. export WINEDLLOVERRIDES="winemenubuilder.exe=d;mshtml=d;nvapi,nvapi64=n"
  172. export WINE_LARGE_ADDRESS_AWARE=1
  173. export GAMEDIR="\$WINEPREFIX/drive_c/Games/$1"
  174.  
  175. # external vulkan translation
  176. #export DXVK_ASYNC=1
  177.  
  178. ping -c 1 github.com >/dev/null || { echo "Possibly no network. This may mean that booting will fail." ; }; VLKLOG="\$WINEPREFIX/vulkan.log"; VULKAN="\$PWD/vulkan"
  179. VLKVER="\$(curl -s -m 5 https://api.github.com/repos/jc141x/vulkan/releases/latest | awk -F '["/]' '/"browser_download_url":/ {print \$11}' | cut -c 1-)"
  180. status-vulkan() { [[ ! -f "\$VLKLOG" || -z "\$(awk "/^\${FUNCNAME[1]}\$/ {print \$1}" "\$VLKLOG" 2>/dev/null)" ]] || { echo "\${FUNCNAME[1]} present" && return 1; }; }
  181. vulkan() { DL_URL="\$(curl -s https://api.github.com/repos/jc141x/vulkan/releases/latest | awk -F '["]' '/"browser_download_url":/ {print \$4}')"; VLK="\$(basename "\$DL_URL")"
  182. [ ! -f "\$VLK" ] && command -v curl >/dev/null 2>&1 && curl -LO "\$DL_URL" && tar -xvf "vulkan.tar.xz" || { rm "\$VLK" && echo "ERROR: Failed to extract vulkan translation." && return 1; }
  183. rm -rf "vulkan.tar.xz" && bash "\$PWD/vulkan/setup-vulkan.sh" && rm -Rf "\$VULKAN"; }
  184. vulkan-dl() { echo "Using external vulkan translation (dxvk,vkd3d,dxvk-nvapi)." && vulkan && echo "\$VLKVER" >"\$VLKLOG"; }
  185. [[ ! -f "\$VLKLOG" && -z "\$(status-vulkan)" ]] && vulkan-dl;
  186. [[ -f "\$VLKLOG" && -n "\$VLKVER" && "\$VLKVER" != "\$(awk '{print \$1}' "\$VLKLOG")" ]] && { rm -f vulkan.tar.xz || true; } && vulkan-dl
  187.  
  188. # start
  189. export DXVK_ENABLE_NVAPI=1
  190. cd "\$GAMEDEST"
  191. "\$WINE" "$EXE" "\$@"
  192. EOL
  193.  
  194. chmod a+x "$GSS"
  195. echo ""
  196. cat $GSS
  197. echo ""
  198. echo "\"$GSS\" written and made executable."
  199. echo ""
  200.  
  201. echo ""
  202. echo "Path of the $1 wineprefix is: $WINEPREFIX"
  203. echo ""
  204. echo "Be sure to verify that the game executable written to \"$GSS\" is actually \"$EXE\" and modify if necessary."
  205. echo ""
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement