Advertisement
EvilSupahFly

Game Installer Script (v2) Based on JC141 Script

Feb 6th, 2024 (edited)
1,394
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 6.86 KB | Source Code | 0 0
  1. #!/bin/bash
  2. #
  3. # V2 of my Game Installer Script Based on the original JC141 Script as it appeared in BG3.
  4. # Assumes multiple games are stored in conveniently-named subdirectories with a 'setup.exe' in them, and
  5. # takes a folder name on the command line, creates all the applicable directories and a WINE prefix for
  6. # it, downloads and installs, the newest version of VULKAN, starts the setup.exe located in the folder
  7. # provided on the command line, and writes a version of the installer script out as the game start script.
  8. #
  9. # Changes from v1:
  10. # - Rather than create individually named bottles each time it gets run as V1 did, this version installs
  11. #   the game to a named folder in a pre-set prefix to conserve disk space, which I plan to make optional in V3.
  12. # - Replaces whitespace in the command line with underscores to make a custom named starting script for the game
  13. #   which replaces the original version of starting script, reflecting changes made to this installer.
  14. # - Copies and runs all MSVCPP redistributables from the folder REDIST, located in the script's starting directory.
  15. # - Removed WAN blocking
  16. # - Removed dwarfs checking
  17. # - Added some extra directory and CLI parameter verification checks
  18. # - Added some notes
  19. # - Added a loop to copy and install MSVC 2022 redistributables
  20. # - Made installer script partially interactive
  21. # TO DO in v3:
  22. # - Add colour to prompts and output (probably)
  23.  
  24. # Basic checks
  25. cd "$(dirname "$(readlink -f "$0")")" || exit; [ "$EUID" = "0" ] && echo "For the love of God! Please don't run this as root!" && exit; [ "$1" = "" ] && echo "Command line can't be blank - please choose a game." && exit
  26.  
  27. if [ ! -d "$1" ]; then
  28.    echo "Sorry... I can't find \"$1\" in this folder."
  29.    exit 255
  30. elif [ ! -f "$1/setup.exe" ]; then
  31.    echo "Sorry... \"$1\" doesn't have a \"setup.exe\" installer."
  32.    exit 255
  33. fi
  34.  
  35. # Declarations
  36. export G="${1// /_}"
  37. export GAMESRC="$PWD/$1"
  38. export WINEPREFIX="/home/$(whoami)/Games/jc141" #Create Wineprefix
  39. export GAMEDIR="$WINEPREFIX/drive_c/Games/$1"; [ ! -d "$GAMEDIR" ] && mkdir -p "$GAMEDIR" #If $GAMEDIR doesn't exist, create it
  40. export GSS="$WINEPREFIX/drive_c/${G}.sh" #Convert spaces to underscores, if they exist, for the launcher script
  41. export RSRC="$PWD/redist"
  42. export WINE="$(command -v wine)"
  43. export WINEDLLOVERRIDES="winemenubuilder.exe=d;mshtml=d;nvapi,nvapi64=n"
  44. export WINE_LARGE_ADDRESS_AWARE=1
  45.  
  46. echo ""
  47. echo "Declarations:"
  48. echo ""
  49. echo "G=\"${1// /_}\""
  50. echo "GAMESRC=\"$PWD/$1\""
  51. echo "WINEPREFIX=\"/home/$(whoami)/Games/jc141\""
  52. echo "GAMEDIR=\"$WINEPREFIX/drive_c/Games"
  53. echo "GSS=\"$WINEPREFIX/drive_c/${G}.sh\""
  54. echo "RSRC=\"$PWD/redist\""
  55. echo "WINE=\"$(command -v wine)\""
  56. echo "WINEDLLOVERRIDES=\"winemenubuilder.exe=d;mshtml=d;nvapi,nvapi64=n\""
  57. echo ""
  58. echo "Variables Declared. Starting Vulkan setup."
  59. echo ""
  60. echo ""
  61.  
  62. # external vulkan translation
  63. #export DXVK_ASYNC=1
  64.  
  65. 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"
  66. VLKVER="$(curl -s -m 5 https://api.github.com/repos/jc141x/vulkan/releases/latest | awk -F '["/]' '/"browser_download_url":/ {print $11}' | cut -c 1-)"
  67. status-vulkan() { [[ ! -f "$VLKLOG" || -z "$(awk "/^${FUNCNAME[1]}\$/ {print \$1}" "$VLKLOG" 2>/dev/null)" ]] || { echo "${FUNCNAME[1]} present" && return 1; }; }
  68. 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")"
  69. [ ! -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; }
  70. rm -rf "vulkan.tar.xz" && bash "$PWD/vulkan/setup-vulkan.sh" && rm -Rf "$VULKAN"; }
  71. vulkan-dl() { echo "Using external vulkan translation (dxvk,vkd3d,dxvk-nvapi)." && vulkan && echo "$VLKVER" >"$VLKLOG"; }
  72. [[ ! -f "$VLKLOG" && -z "$(status-vulkan)" ]] && vulkan-dl;
  73. [[ -f "$VLKLOG" && -n "$VLKVER" && "$VLKVER" != "$(awk '{print $1}' "$VLKLOG")" ]] && { rm -f vulkan.tar.xz || true; } && vulkan-dl; export DXVK_ENABLE_NVAPI=1
  74.  
  75. echo ""
  76. if [ "$2" == "skip" ]; then
  77.    YN="y"
  78. else
  79.    read -p "Skip installing MSVC redistributables? (y/n) " YN
  80. fi
  81. echo ""
  82. case $YN in
  83.    [nN] ) echo "Proceeding with install.";
  84.      cd "$RSRC";
  85.      for i in *.exe;
  86.        do
  87.            echo "Installing $i into $WINEPREFIX";
  88.            "$WINE" "$i";
  89.        done;;
  90.    [yY] ) echo "Skipping redistributables. Don't blame me if something breaks.";;
  91.    * ) echo "Invalid response.";
  92.        break;;
  93. esac
  94.  
  95. echo ""
  96. echo "Writing Game Starter Script (GSS) for $1 to $GSS ..."
  97. echo ""
  98. #create game starter script
  99. cat << EOL > "$GSS"
  100. #!/bin/bash
  101.  
  102. # $GSS #
  103.  
  104. cd "\$(dirname "\$(readlink -f "\$0")")" || exit; [ "\$EUID" = "0" ] && echo "Please don't run as root!" && exit
  105.  
  106. # wine
  107. export WINE="\$(command -v wine)";
  108. export WINEPREFIX="/home/\$(whoami)/Games/jc141"; export WINEDLLOVERRIDES="winemenubuilder.exe=d;mshtml=d;nvapi,nvapi64=n"
  109. export WINE_LARGE_ADDRESS_AWARE=1;
  110. export GAMEDIR="\$WINEPREFIX/drive_c/Games/$1"
  111.  
  112. # external vulkan translation
  113. #export DXVK_ASYNC=1
  114.  
  115. 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"
  116. VLKVER="\$(curl -s -m 5 https://api.github.com/repos/jc141x/vulkan/releases/latest | awk -F '["/]' '/"browser_download_url":/ {print \$11}' | cut -c 1-)"
  117. status-vulkan() { [[ ! -f "\$VLKLOG" || -z "\$(awk "/^\${FUNCNAME[1]}\$/ {print \$1}" "\$VLKLOG" 2>/dev/null)" ]] || { echo "\${FUNCNAME[1]} present" && return 1; }; }
  118. 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")"
  119. [ ! -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; }
  120. rm -rf "vulkan.tar.xz" && bash "\$PWD/vulkan/setup-vulkan.sh" && rm -Rf "\$VULKAN"; }
  121. vulkan-dl() { echo "Using external vulkan translation (dxvk,vkd3d,dxvk-nvapi)." && vulkan && echo "\$VLKVER" >"\$VLKLOG"; }
  122. [[ ! -f "\$VLKLOG" && -z "\$(status-vulkan)" ]] && vulkan-dl;
  123. [[ -f "\$VLKLOG" && -n "\$VLKVER" && "\$VLKVER" != "\$(awk '{print \$1}' "\$VLKLOG")" ]] && { rm -f vulkan.tar.xz || true; } && vulkan-dl
  124.  
  125. # start
  126. export DXVK_ENABLE_NVAPI=1
  127. cd "\$GAMEDIR"
  128. "\$WINE" "setup.exe" "\$@"
  129. EOL
  130.  
  131. chmod a+x "$GSS"
  132. echo ""
  133. cat $GSS
  134. echo ""
  135. echo "\"$GSS\" written and made executable."
  136. echo ""
  137.  
  138. # start installer
  139. echo ""
  140. echo "Starting \"$1\" installer..."
  141. echo ""
  142.  
  143. cd "$GAMESRC"; "$WINE" "setup.exe" "$@"
  144.  
  145. echo ""
  146. echo "Path of the $1 wineprefix is: $WINEPREFIX"
  147. echo ""
  148. echo "Be sure to change the name of the game executable in \"$GSS\" from \"setup.exe\"."
  149.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement