Advertisement
EvilSupahFly

Game Installer Script v5.6

Jul 31st, 2024 (edited)
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 22.10 KB | Gaming | 0 0
  1. #!/bin/bash
  2. #
  3. # This is nearing the final evolution of my Game Installer Script. Command-line parameters are now optional,
  4. # I've added colour to the output, the logic has been tweaked out a bit so now the script will check for WINE,
  5. # and attempt to install it, should it not be found, and I've also added commentary to each section to explain
  6. # what it all does and added extensive error handling. As far as features go, I was thinking of making both the
  7. # MSVC redist and Vulkan functions which could be called independently of actually performing an install with
  8. # a command-line parameter, but I don't really see the need at this point. For now, it only works on Ubuntu and
  9. # Ubuntu-based distributions but eventually I plan to expand this.
  10.  
  11. IFS=$'\n'
  12.  
  13. # Define some fancy colourful text with BASH's built-in escape codes. Example:
  14. # echo -e "${BOLD}${YELLOW}This text will be displayed in BOLD YELLOW. ${RESET}While this text is normal."
  15. BOLD="\033[1m"
  16. RESET="\e[0m" #Normal
  17. BGND="\e[40m"
  18. ULINE="\033[4m"
  19. YELLOW="${BOLD}${BGND}\e[1;33m"
  20. RED="${BOLD}${BGND}\e[1;91m"
  21. GREEN="${BOLD}${BGND}\e[1;92m"
  22. WHITE="${BOLD}${BGND}\e[1;97m"
  23. SKIP=false
  24. LAUNCHER=""
  25.  
  26. echo -e "${WHITE}" # Make the text bold and white by default because it's easier to read.
  27. # User ID, working directory and parameter checks - NO ROOT!!!
  28. cd "$(dirname "$(readlink -f "$0")")" || exit; [ "$EUID" = "0" ] && echo -e "${RED}Gotta quit here because I can't run as root. ${WHITE}I'll prompt you if I need root access.${RESET}" && exit 255
  29.  
  30. # Check if a foler was supplied on the command line and deal with any trailing slashes, should they exist
  31. if [[ ! "$1" =~ ^[Ss][Kk][Ii][Pp]$ && -n "$1" ]]; then
  32.    if [[ "$1" == */ ]]; then
  33.        ONE="${1%/}"
  34.    else
  35.        ONE="$1"
  36.    fi
  37.    NOSPACE="${ONE// /_}"
  38.    echo
  39.    echo "This script will attempt to install WINE for you if it isn't already installed."
  40.    echo -e "As such, it would be ${ULINE}${YELLOW}REALLY HELPFUL${RESET}${WHITE} if you have Internet access."
  41.    echo "It's also largely failproof, so if it encounters something it can't fix, or something"
  42.    echo "which can't be fixed later by tweaking the runner script, it will exit with a fatal"
  43.    echo "error. Everything is mostly automated, only requiring you to answer a few prompts."
  44.    echo
  45.    echo -e "To continue, press ${YELLOW}<ENTER>${WHITE}. To cancel, press ${YELLOW}<CTRL-C>${WHITE}."; read donext
  46. fi
  47.  
  48. if [[ "${1,,}" == "skip" ]]; then
  49.    SKIP=true
  50. fi
  51.  
  52. if [[ -z "$1" ]] || [[ "${1,,}" == *"skip"* ]]; then
  53.    echo
  54.    # Load all subfolders into an array and make it a numbered list
  55.    #GDIRS=($(find . -maxdepth 1 -type d -exec basename {} \; | grep -vE '^\.$|^\..$|\.redist$'))
  56.    #shopt -s nullglob nocaseglob
  57.    GDIRS=()
  58.    echo -e "${RED}Commandline was blank. ${WHITE}Listing potential game folders. We'll see if they're empty later:"
  59.    echo
  60.    for dir in */; do
  61.        if [[ $dir =~ ^\.[^.]|^\.redist ]]; then
  62.            continue
  63.        fi
  64.        GDIRS+=("$dir")
  65.    done
  66.    for ((i=0; i<"${#GDIRS[@]}"; i++)); do
  67.        # Write the list to the screen, removing the trailing slashes, and determine the color based on the index
  68.        if ((i % 2 == 0)); then
  69.            echo -e "${ULINE}${WHITE}$i: ${GDIRS[$i]%/}${RESET}${WHITE}"
  70.        else
  71.            echo -e "${ULINE}${GREEN}$i: ${GDIRS[$i]%/}${RESET}${WHITE}"
  72.        fi
  73.        #dir="${GDIRS[$i]%/}"
  74.        #echo "$i: $dir"
  75.    done
  76.    # Ask for input based on the list, looping until a valid response is given
  77.    while true; do
  78.        echo -e "${WHITE}"
  79.        read -p "Choose a number from the list above. " dirsel
  80.        echo
  81.        if [[ $dirsel =~ ^[0-9]+$ && $dirsel -ge 0 && $dirsel -le ${#GDIRS[@]} ]]; then
  82.            echo
  83.            break
  84.        else
  85.            echo -e "${YELLOW}\"$dirsel\" was ${RED}NOT ${YELLOW}an option - let's try again."
  86.            echo
  87.        fi
  88.    done
  89.  
  90.    LAUNCHER="${GDIRS[dirsel]%/}"
  91.    echo -e "${YELLOW}Launching install script for \"${ULINE}${WHITE}$LAUNCHER${RESET}${YELLOW}\":"
  92.    echo
  93.    # By calling '. $0 "${GDIRS[dirsel]}"' we can relaunch this script using the chosen directory as the commandline
  94.    # option and avoid writing extra code to tell the script that each instance of "$1" should be "$1" unless the
  95.    # array for $GDIRS has been set, in which case, use "${GDIRS[dirsel]}". It's much simpler this way because even
  96.     # the first version of the install script has always taken a folder-name as a commandline.
  97.     . "$0" "$LAUNCHER"
  98.     exit 0
  99. fi
  100.  
  101. # Assuming the script was run with an option by the user, and not called from the loop above,
  102. # check to make sure the provided directory name actually exists. If not, exit with an error.
  103. if [ ! -d "$1" ]; then
  104.     echo
  105.     echo -e "${RED}I can't find \"${WHITE}${ULINE}$1${RESET}${RED}\". Maybe try checking your spelling?${RESET}"
  106.     echo
  107.     exit 255
  108. fi
  109.  
  110. # This checks to make sure the script is being run on some variation of Ubuntu, and quits with an error if it's not.
  111. if [ -f /etc/os-release ]; then
  112.     # If we're running Ubunto, Kubuntu, Mint, or anything else like it, run /etc/os-release and load the environment variables from it
  113.     . /etc/os-release
  114. else
  115.     echo
  116.     echo -e "${RED}What are you even running this on? This won't work.${RESET}"
  117.     echo
  118.     exit 255
  119. fi
  120.  
  121. # First, check to see if WINE is installed, if not, proceed accordingly.
  122. if ! command -v wine &> /dev/null; then
  123.     echo
  124.     echo -e "${YELLOW}WINE isn't installed. ${WHITE}Checking for WINEHQ official repositories."
  125.     echo
  126.     # Now, check if WineHQ repositories for WINE and WINETRICKS are configured.
  127.     # If "dl.winehq.org" isn't present in any .source files, add it and update.
  128.     if grep -q -r "dl.winehq.org" /etc/apt/; then
  129.         echo -e "${YELLOW}WINEHQ repository exists. ${WHITE}Proceeding to WINE install."
  130.     else
  131.         # The information for $UBUNTU_CODENAME is provided by /etc/os-release above
  132.         DISTRO=${UBUNTU_CODENAME,,}
  133.         echo -e "${RED}WINEHQ repository not found. ${WHITE}Proceeding to add WINEHQ repository information."
  134.         sudo mkdir -pm755 /etc/apt/keyrings
  135.         sudo wget -O /etc/apt/keyrings/winehq-archive.key https://dl.winehq.org/wine-builds/winehq.key
  136.         #sudo add-apt-repository "deb https://dl.winehq.org/wine-builds/ubuntu/ $UBUNTU_CODENAME main"
  137.         sudo wget -NP /etc/apt/sources.list.d/ https://dl.winehq.org/wine-builds/ubuntu/dists/$DISTRO/winehq-$DISTRO.sources
  138.         sudo apt update -y
  139.     fi
  140.  
  141.     # If the WINE install fails, save the error to $ERRNUM and exit - we can't do this without WINE.
  142.     if ! sudo apt install -y --install-recommends winehq-stable winetricks; then
  143.         ERRNUM=$?
  144.         echo
  145.         echo -e "${RED}Fatal error ${WHITE}$ERRNUM ${RED}occurred installing WINE. ٩(๏̯๏)۶ "
  146.         echo
  147.         echo -e "${YELLOW}Hey. Don't look at me. ${WHITE}I don't know what it means."
  148.         echo -e "${YELLOW}Try Googling error ${ULINE}$ERRNUM ${RESET}${YELLOW}and see if that helps?${RESET}"
  149.         echo
  150.         exit $ERRNUM
  151.     fi
  152.     echo
  153. fi
  154.  
  155. # Variable Declarations
  156. # Using the short-circuit trick, check if $WINE is empty (if we didn't have to install WINE, it will be)
  157. # and if so, assign it through command substitution
  158. WINE="$(command -v wine)"
  159. WINEVER="$(wine --version)" # Get the version number of the WINE package we just installed.
  160. WINE_LARGE_ADDRESS_AWARE=1; WINEDLLOVERRIDES="winemenubuilder.exe=d;mshtml=d;nvapi,nvapi64=n" # Set environment variables for WINE
  161. WINEPREFIX="/home/$(whoami)/Game_Storage" # Create Wineprefix if it doesn't exist
  162. GAMESRC="$PWD/$1" # Game Source Folder (where the setup is)
  163. GAMEDEST="$WINEPREFIX/drive_c/Games/$1" # Game Destination Folder (where it's going to be)
  164. GSS="$WINEPREFIX/drive_c/$NOSPACE.sh" # Game Starter Script - written automatically by this script
  165. RSRC="$PWD/.redist" # Location of the MSVC Redistributables
  166. #WINEDBG="$(command -v winedbg)" # <-- WINE Debugger
  167. #WINEBOOT="$(command -v wineboot)" # <-- WINEBOOT
  168. export WINE
  169. export WINEVER
  170. export WINE_LARGE_ADDRESS_AWARE
  171. export WINEDLLOVERRIDES
  172. export WINEPREFIX
  173. export GAMESRC
  174. export GAMEDEST
  175. export GSS
  176. export RSRC
  177. #export WINEDBG
  178. #export WINEBOOT
  179.  
  180. echo -e "${GREEN}WINE version ${YELLOW}$WINEVER${GREEN} is installed and verified functional."
  181. echo
  182.  
  183. # Check to see if $GAMESRC actually exists. If not, exit with an error (useful check if user gives $1)
  184. if [ ! -d "$GAMESRC" ]; then
  185.     echo -e "${RED}Error: \"${WHITE}$GAMESRC${RED}\" doesn't exist."
  186.     echo
  187.     echo " ლ(ಠ益ಠ)ლ "
  188.     echo -e "${RESET}"
  189.     exit 255
  190. fi
  191.  
  192. # Check to see if $GAMESRC contains files. If not, exit with an error (also useful check if user gives $1)
  193. if [ -z "$GAMESRC" ]; then
  194.     echo -e "${RED}Error: \"$GAMESRC\" is an empty directory.${WHITE}"
  195.     echo " ಠ_ಠ "
  196.     echo -e "${RESET}"
  197.     exit 255
  198. fi
  199.  
  200. # MSVC redistributables - if "skip" was given, don't ask about installing the runtimes.
  201. # Otherwise, ask and act accordingly.
  202. if [ "$SKIP" = false ]; then
  203.     echo -e "${WHITE}If you have already installed MSVC redistributables, you can answer 'y' below,"
  204.     echo "Or you can skip this prompt next time you install something by passing 'skip' on the command line:"
  205.     echo
  206.     echo -e "  ${YELLOW}$0 \"GAME FOLDER\" skip${WHITE}"
  207.     echo
  208.     echo -e "or just like this"
  209.     echo
  210.     echo -e "  ${GREEN}$0 skip${WHITE}"
  211.     echo
  212.     echo "Just remember that folder names containing spaces (' '), need to be enclosed in double quotes (\"Some Folder\")"
  213.     echo "or this entire process breaks down, even though I've done my best to minimize the odds of something breaking."
  214.     echo
  215.     echo -e "${RED}HOWEVER:${WHITE} If this is your first time running this script, you should ${GREEN}definitely${WHITE} install them."
  216.     echo
  217.     read -p "Go ahead and skip the install for MSVC redistributables? (y/n) " YN
  218.     echo
  219. else
  220.     YN="y"
  221. fi
  222. echo -e "${WHITE}"
  223. case $YN in
  224.     [nN] ) echo "Proceeding with MSVC runtime installs.";
  225.       cd "$RSRC";
  226.       for i in *.exe;
  227.         do
  228.             echo -e "${WHITE}Installing \"${YELLOW}$i${WHITE}\" into $WINEPREFIX";
  229.             "$WINE" "$i" >/dev/null 2>&1;
  230.         done;;
  231.     * ) echo -e "${YELLOW}OK, I'm skipping the redistributables. ${RED}Just don't blame me if something breaks.${WHITE}";;
  232. esac
  233.  
  234. # Create an array containing all the .exe files.
  235. # If there aren't any .exe files in the directory, exit with an error
  236. SETUPEXE=($(find "$GAMESRC" -type f -iname "*.exe"))
  237.  
  238. if [ "${#SETUPEXE[@]}" -eq 0 ]; then
  239.     echo -e "${WHITE}\"$GAMESRC\" ${RED}doesn't contain any .exe files."
  240.     echo
  241.     echo -e "${WHITE} ლ(ಠ益ಠ)ლ ${RESET}"
  242.     echo
  243.     exit 255
  244. fi
  245. # Print the contents of the array and ask for input, looping until a valid response is recieved, choose color based on even or odd index
  246. echo -e "${YELLOW}Installer options:${WHITE}"
  247.  
  248. echo
  249. for ((i=0; i<"${#SETUPEXE[@]}"; i++)); do
  250.     if ((i % 2 == 0)); then
  251.         echo -e "${ULINE}${WHITE}$i: ${SETUPEXE[$i]}${RESET}${WHITE}"
  252.     else
  253.         echo -e "${ULINE}${GREEN}$i: ${SETUPEXE[$i]}${RESET}${WHITE}"
  254.     fi
  255. done
  256.  
  257. echo -e "${WHITE}"
  258. while true; do
  259.     read -p "Select an installer: " instsel
  260.     if [[ "$instsel" =~ ^[0-9]+$ && "$instsel" -le "${#SETUPEXE[@]}" ]]; then
  261.         EXE=$(basename "${SETUPEXE[$instsel]}")
  262.         echo
  263.         break
  264.     else
  265.         echo
  266.         echo -e "${RED}That wasn't an option. ${WHITE}Please choose a valid number."
  267.         echo
  268.     fi
  269. done
  270.  
  271. # If $GAMEDEST doesn't exist, create it
  272. [ ! -d "$GAMEDEST" ] && mkdir -p "$GAMEDEST"
  273. # Print variables, their contents, and an explanatory note for verification.
  274. echo
  275. echo -e "${WHITE}Technical details, if you care:"
  276. echo
  277. echo -e "${YELLOW}    \$GSS=\"$GSS\""
  278. echo "    \$GAMESRC=\"$GAMESRC\""
  279. echo "    \$WINEPREFIX=\"$WINEPREFIX\""
  280. echo "    \$GAMEDEST=\"$GAMEDEST\""
  281. echo "    \$WINEDLLOVERRIDES=\"winemenubuilder.exe=d;mshtml=d;nvapi,nvapi64=n\""
  282. echo "    \$WINE_LARGE_ADDRESS_AWARE=1"
  283. echo
  284. echo -e "        Installer=\"$EXE\"${WHITE}"
  285. echo
  286. echo -e "  I ${YELLOW}${ULINE}***STRONGLY***${RESET}${WHITE} recommend picking the folder \"${ULINE}${YELLOW}$GAMEDEST${RESET}${WHITE}\""
  287. echo -e "  when the installer launches. For the sake of automation, this installer script creates the directory using"
  288. echo -e "  the placeholder \"${YELLOW}\$GAMEDEST${WHITE}\", and that's where the launcher script will expect it to be."
  289. echo
  290. echo -e "  If the installer doesn't default to C:\Games\\$1 you can change it using the advanced options."
  291. echo
  292. echo "  Also, you don't need to install DirectX or the MSVC Redistributables from the installer menu."
  293. echo "  Vulkan replaces DirectX, and the MSVC Redistributables can be (re)installed any time by running this script again."
  294. echo "  This install scripthandles all that, as you have no doubt already noticed."
  295. echo
  296. echo -e "  If you let the game's installer use a different folder, you will have to manually change the path and possibly the"
  297. echo -e "  filename for the game's primary ${YELLOW}.exe ${WHITE}in the ${YELLOW}$GSS ${WHITE}script to match."
  298. echo
  299. echo -e "  If you do modify the launcher script, remember that paths and files are ${RED}Case Sensitive${WHITE} on Linux."
  300. echo
  301. echo -e "To continue, press ${YELLOW}<ENTER>${WHITE}. To cancel, press ${YELLOW}<CTRL-C>${WHITE}."; read donext
  302. echo
  303.  
  304. # Install or update Vulkan. Ping GIT HUB to verify network connectivity, then get the latest version of VULKAN,
  305. # compare to what's installed (if any), and download and install the latest version if there's either none already
  306. # installed or the installed version is older than the current release. Downloads are deleted after install.
  307. ping -c 1 github.com >/dev/null || { echo -e "${RED}Possibly no network. Booting might fail.${WHITE}" ; }
  308. VLKLOG="$WINEPREFIX/vulkan.log"; VULKAN="$PWD/vulkan"; VLKVER="$(curl -s -m 5 https://api.github.com/repos/jc141x/vulkan/releases/latest | awk -F '["/]' '/"browser_download_url":/ {print $11}' | cut -c 1-)"
  309. status-vulkan() { [[ ! -f "$VLKLOG" || -z "$(awk "/^${FUNCNAME[1]}\$/ {print \$1}" "$VLKLOG" 2>/dev/null)" ]] || { echo "${FUNCNAME[1]} present" && return 1; }; }
  310. vulkan() { DL_URL="$(curl -s https://api.github.com/repos/jc141x/vulkan/releases/latest | awk -F '["]' '/"browser_download_url":/ {print $4}')"
  311. VLK="$(basename "$DL_URL")"; [ ! -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; }
  312. rm -rf "vulkan.tar.xz" && bash "$PWD/vulkan/setup-vulkan.sh" && rm -Rf "$VULKAN"; }
  313. vulkan-dl() { echo "Using external vulkan translation (dxvk,vkd3d,dxvk-nvapi)." && vulkan && echo "$VLKVER" >"$VLKLOG"; }
  314. [[ ! -f "$VLKLOG" && -z "$(status-vulkan)" ]] && vulkan-dl
  315. [[ -f "$VLKLOG" && -n "$VLKVER" && "$VLKVER" != "$(awk '{print $1}' "$VLKLOG")" ]] && { rm -f vulkan.tar.xz || true; } && vulkan-dl;
  316.  
  317. # Enables some nVidia-specific functionality, offering entry points for supporting the following features in applications:
  318. # - NVIDIA DLSS for Vulkan, by supporting the relevant adapter information by querying from Vulkan.
  319. # - NVIDIA DLSS for D3D11 and D3D12, by querying from Vulkan and forwarding the relevant calls into DXVK / VKD3D-Proton.
  320. # - NVIDIA Reflex, by forwarding the relevant calls into either DXVK / VKD3D-Proton or LatencyFleX.
  321. # - Several NVAPI D3D11 extensions, among others SetDepthBoundsTest and UAVOverlap, by forwarding the relevant calls into DXVK.
  322. # - NVIDIA PhysX, by supporting entry points for querying PhysX capabilities.
  323. # - Several GPU topology related methods for adapter and display information, by querying from DXVK and Vulkan.
  324. # Note that DXVK-NVAPI does not implement DLSS, Reflex or PhysX. It mostly forwards the relevant calls.
  325. export DXVK_ENABLE_NVAPI=1
  326. echo
  327.  
  328.  
  329. # Start WINE and pass the primary installer .EXE to it.
  330. echo -e "${WHITE}Starting \"${YELLOW}$1${WHITE}\" installer..."
  331. echo
  332.  
  333. cd "$GAMESRC" # This is the source folder for the .exe
  334. #Run WINE with an "If It Fails" assumption block.
  335. if ! "$WINE" "$EXE" "$@" >/dev/null 2>&1; then
  336.     # If it did fail, save the error number and exit with a message.
  337.     ERRNUM=$?
  338.     echo
  339.     echo -e "${RED}Error code ${YELLOW}$ERRNUM ${RED} detected on exit."
  340.     echo -e "${WHITE}Looks like something went wrong."
  341.     echo "Unfortunately, since ${RED}$ERRNUM${WHITE} is a Windows-related error, I can't help you."
  342.     echo
  343.     exit 255
  344. fi
  345.  
  346. # We used this once already so we're blanking it so we can reuse it
  347. EXE=""
  348.  
  349. # This is the destination folder, originally set at the start: GAMEDEST="$WINEPREFIX/drive_c/Games/$1"
  350. cd "$GAMEDEST"
  351.  
  352. # Create an array of .EXE files just like the initial setup, ignoring filename case
  353. GAME_EXE=($(find "$GAMEDEST" -type f -iname "*.exe"))
  354.  
  355. if [ ${#GAME_EXE[@]} -ne 0 ]; then
  356.     # As long as the array isn't empty we can proceed normally so we'll set DO_GSS and check it later
  357.     DO_GSS="y"
  358. elif [ ${#GAME_EXE[@]} -eq 0 ]; then
  359.     # If the array is empty, no .EXE files could be found, but it's not always fatal so we'll ask to try and continue
  360.     echo
  361.     echo -e "${WHITE}\"${RED}$GAMESRC${WHITE}\" doesn't contain any .exe files."
  362.     echo
  363.     echo -e "${YELLOW} ლ(ಠ益ಠ)ლ ${WHITE}"
  364.     echo
  365.     read -p "Continue anyway? You'll have to manually edit the launcher scxript. (y/n) " DO_GSS
  366.     case $DO_GSS in
  367.         [yY] ) echo;
  368.             # If DO_GSS="y" we'll continue with the script, but use a place holder for the runner script since no .EXE was found
  369.             echo -e "${WHITE}Continuing as per your request.";
  370.             EXE="\"Just A Place Holder - Replace Me With Actual Game .EXE\"";
  371.             echo;;
  372.         * ) echo;
  373.             # If anything other than "y" was selected, treat it as a fatal error and abandon the install without creating the runner script
  374.             echo -e "${RED}OK, I'm Stopping this process. You'll have to start over if you want to proceed.${RESET}";
  375.             echo;
  376.             exit 255;;
  377.     esac
  378. fi
  379.  
  380. # If DO_GSS is "y" and the array wasn't empty, present a list of .exe files, looping until we get a valid response
  381. if [[ "${DO_GSS,,}" == "y" ]] && [ ${#GAME_EXE[@]} -ne 0 ]; then
  382.     echo
  383.     echo -e "${WHITE}Game runner options:"
  384.     echo
  385.     for ((i=0; i<"${#GAME_EXE[@]}"; i++)); do
  386.         if ((i % 2 == 0)); then
  387.             echo -e "${ULINE}${WHITE}$i: ${GAME_EXE[$i]}${RESET}${WHITE}"
  388.         else
  389.             echo -e "${ULINE}${GREEN}$i: ${GAME_EXE[$i]}${RESET}${WHITE}"
  390.         fi
  391.     done
  392.     echo
  393.     while true; do
  394.         read -p "Select game .EXE: " gamesel
  395.         if [[ $gamesel =~ ^[0-9]+$ && $gamesel -le ${#GAME_EXE[@]} ]]; then
  396.             GAMEDEST=$(dirname "${GAME_EXE[$((gamesel))]}")
  397.             EXE=$(basename "${GAME_EXE[$gamesel]}")
  398.             echo
  399.             break
  400.         else
  401.             echo
  402.             echo -e "${YELLOW}$gamesel ${RED}wasn't an option. ${WHITE}Please choose a ${RED}valid ${WHITE}number."
  403.         fi
  404.     done
  405. fi
  406. echo
  407. echo -e "${WHITE}Game Destination: \"${YELLOW}$GAMEDEST${WHITE}\" (C:\Games\\$1)"
  408. echo
  409. echo -e "Writing Game Starter Script (GSS) for ${YELLOW}$1 ${WHITE}to ${YELLOW}$GSS ${WHITE}..."
  410. echo
  411.  
  412. # Create game starter script by writing everything up to "EOL" in the file defined in $GSS
  413. cat << EOL > "$GSS"
  414. #!/bin/bash
  415.  
  416. ###############
  417. ## Script Name:
  418. ## $GSS
  419. ###############
  420.  
  421. # Change the current working directory to the one the scipt was run from
  422. cd "\$(dirname "\$(readlink -f "\$0")")" || exit; [ "\$EUID" = "0" ] && echo "Please don't run as root!" && exit
  423.  
  424. # Make sure WINE is configured (although, I'm assuming it was done by the original installer script)
  425. export WINE="\$(command -v wine)"
  426. export WINEPREFIX="/home/\$(whoami)/Game_Storage"
  427. export WINEDLLOVERRIDES="winemenubuilder.exe=d;mshtml=d;nvapi,nvapi64=n"
  428. export WINE_LARGE_ADDRESS_AWARE=1
  429. export RESTORE_RESOLUTION=1
  430. export WINE_D3D_CONFIG="renderer=vulkan"
  431. export GAMEDEST="\$WINEPREFIX/drive_c/Games/$1"
  432.  
  433. # Check Vulkan version and download and install if there's a newer version available online
  434.  
  435. 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"
  436. VLKVER="\$(curl -s -m 5 https://api.github.com/repos/jc141x/vulkan/releases/latest | awk -F '["/]' '/"browser_download_url":/ {print \$11}' | cut -c 1-)"
  437. status-vulkan() { [[ ! -f "\$VLKLOG" || -z "\$(awk "/^\${FUNCNAME[1]}\$/ {print \$1}" "\$VLKLOG" 2>/dev/null)" ]] || { echo "\${FUNCNAME[1]} present" && return 1; }; }
  438. 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")"
  439. [ ! -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; }
  440. rm -rf "vulkan.tar.xz" && bash "\$PWD/vulkan/setup-vulkan.sh" && rm -Rf "\$VULKAN"; }
  441. vulkan-dl() { echo "Using external vulkan translation (dxvk,vkd3d,dxvk-nvapi)." && vulkan && echo "\$VLKVER" >"\$VLKLOG"; }
  442. [[ ! -f "\$VLKLOG" && -z "\$(status-vulkan)" ]] && vulkan-dl;
  443. [[ -f "\$VLKLOG" && -n "\$VLKVER" && "\$VLKVER" != "\$(awk '{print \$1}' "\$VLKLOG")" ]] && { rm -f vulkan.tar.xz || true; } && vulkan-dl
  444.  
  445. # Start process in WINE
  446. export DXVK_ENABLE_NVAPI=1
  447. cd "\$GAMEDEST"
  448. "\$WINE" "$EXE" "\$@"
  449. EOL
  450.  
  451. # Make the script executable and present a recap
  452. chmod a+x "$GSS"
  453. echo
  454. cat "$GSS"
  455. echo
  456. echo -e "${WHITE}\"${YELLOW}$GSS${WHITE}\" has been written and made executable."
  457. echo
  458. echo "If you aren't running an nVidia GPU, you should change this:"
  459. echo
  460. echo -e "        ${YELLOW}export WINEDLLOVERRIDES=\"winemenubuilder.exe=d;mshtml=d;nvapi,nvapi64=n\""
  461. echo
  462. echo -e "${WHITE}to this:"
  463. echo
  464. echo -e "        ${YELLOW}export WINEDLLOVERRIDES=\"winemenubuilder.exe=d;mshtml=d\"${WHITE}"
  465. echo
  466. echo "It probably won't cause any problems for non-nVidia GPUs, but it's best just to be safe."
  467. echo
  468. echo -e "The full path of your ${YELLOW}$1 ${WHITE}wineprefix is: \"${YELLOW}$WINEPREFIX${WHITE}\""
  469. echo
  470. echo -e "Be sure to verify that the game executable written to \"${YELLOW}$GSS${WHITE}\" is actually \"${YELLOW}$EXE${WHITE}\" and modify if necessary.${RESET}"
  471. echo
  472.  
  473. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement