Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #
- # My Game Installer Script Based on the JC141 Script from BG3. v2.8
- #
- # Takes a folder name on the command line, searches for applicable .EXE files in it, displays the list asking
- # for input, creates all the applicable directories and a WINE prefix if the prefix doesn't already exist,
- # calls WINE to run the user-selected setup, downloads and installs the newest version of VULKAN, checks the
- # install folder for another .EXE, asking you to pick one from the list, and writes a Game Starter Script out
- # containing everything required to run the game in a WINE prefix, a secondary check for Vulkan updates, and
- # ultimately run the chosen .EXE in WINE.
- #
- # Changes from v2.75:
- # - Fixed the broken ".exe" finder loop that looks for the installer and moved variable declarations up top.
- # - Cleaned up EXE finder result string by stripping the path out, leaving just the filename.
- #
- # Changes from v2.5:
- # - Changed game installer from "setup.exe" to a user-selectable one using the same loop idea I added in 2.0 to
- # search for the game .EXE after install since not all games use "setup.exe" explicitly, and some GoG games
- # will fail if you rename the installer to "setup.exe" to accommodate the script - which I learned the hard
- # way. I plan to consolidate this into a single function in the next version but BASH functions are a little
- # persnickety sometimes, so this will do for now.
- #
- # Changes from v2.0:
- # - Added a loop to locate any ".exe" files in $GAMEDEST and store them in an array, print array as numbered list,
- # ask user to select a listed ".exe" and write it to $GSS, verified with error-checking.
- # - Modified MSVC loop
- IFS=$'\n'
- # Basic checks
- 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
- if [ ! -d "$1" ]; then
- echo "I can't find \"$1\" and suggest checking your spelling."
- exit 255
- fi
- # Declarations
- export G="${1// /_}"
- export GAMESRC="$PWD/$1"
- export WINEPREFIX="/home/$(whoami)/Games/jc141" #Create Wineprefix
- export GAMEDIR="$WINEPREFIX/drive_c/Games/$1"
- export GSS="$WINEPREFIX/drive_c/${G}.sh" #Convert spaces to underscores, if they exist, for the launcher script
- export RSRC="$PWD/redist"
- export WINE="$(command -v wine)"
- export WINEDLLOVERRIDES="winemenubuilder.exe=d;mshtml=d;nvapi,nvapi64=n"
- export WINE_LARGE_ADDRESS_AWARE=1
- cd "$GAMESRC"
- echo "Select game installer from the following list:"
- SETUPEXE=( $(find "$GAMESRC" -type f -name "*.exe") )
- echo ""
- PS3="#: "
- select file in "${SETUPEXE[@]}"; do
- if [[ -z $file ]]; then
- echo "Uh... Excuse me? Let's try that again." >&2
- else
- EXE="${file##*/}"
- echo ""
- echo "You've selected \"$EXE\" - it's too late to change your mind now."
- echo ""
- break
- fi
- done
- echo ""
- echo "Declarations:"
- echo ""
- echo "G=\"${1// /_}\""
- echo "GAMESRC=\"$PWD/$1\""
- echo "WINEPREFIX=\"/home/$(whoami)/Games/jc141\""
- echo "GAMEDIR=\"$WINEPREFIX/drive_c/Games"
- echo "GSS=\"$WINEPREFIX/drive_c/${G}.sh\""
- echo "RSRC=\"$PWD/redist\""
- echo "WINE=\"$(command -v wine)\""
- echo "WINEDLLOVERRIDES=\"winemenubuilder.exe=d;mshtml=d;nvapi,nvapi64=n\""
- echo "Game Instraller=$SETUPFILE"
- echo ""
- echo "Variables Declared. Starting Vulkan setup."
- echo ""
- echo ""
- # external vulkan translation
- #export DXVK_ASYNC=1
- [ ! -d "$GAMEDEST" ] && mkdir -p "$GAMEDEST" #If $GAMEDEST doesn't exist, create it
- 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"
- VLKVER="$(curl -s -m 5 https://api.github.com/repos/jc141x/vulkan/releases/latest | awk -F '["/]' '/"browser_download_url":/ {print $11}' | cut -c 1-)"
- status-vulkan() { [[ ! -f "$VLKLOG" || -z "$(awk "/^${FUNCNAME[1]}\$/ {print \$1}" "$VLKLOG" 2>/dev/null)" ]] || { echo "${FUNCNAME[1]} present" && return 1; }; }
- 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")"
- [ ! -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; }
- rm -rf "vulkan.tar.xz" && bash "$PWD/vulkan/setup-vulkan.sh" && rm -Rf "$VULKAN"; }
- vulkan-dl() { echo "Using external vulkan translation (dxvk,vkd3d,dxvk-nvapi)." && vulkan && echo "$VLKVER" >"$VLKLOG"; }
- [[ ! -f "$VLKLOG" && -z "$(status-vulkan)" ]] && vulkan-dl;
- [[ -f "$VLKLOG" && -n "$VLKVER" && "$VLKVER" != "$(awk '{print $1}' "$VLKLOG")" ]] && { rm -f vulkan.tar.xz || true; } && vulkan-dl; export DXVK_ENABLE_NVAPI=1
- echo ""
- if [ "$2" == "skip" ]
- then
- YN="n"
- else
- read -p "Install MSVC redistributables? (y/n) " YN
- fi
- echo ""
- case $YN in
- [yY] ) echo "Proceeding with install.";
- cd "$RSRC";
- for i in *.exe;
- do
- echo "Installing $i into $WINEPREFIX";
- "$WINE" "$i";
- done;;
- [nN] ) echo "Skipping redistributables. Don't blame me if something breaks.";;
- * ) echo "Invalid response.";
- break;;
- esac
- # start installer
- echo ""
- echo "Starting \"$1\" installer..."
- echo ""
- cd "$GAMESRC"
- "$WINE" "$EXE" "$@"
- if [ $? -ne 0 ]; then
- echo ""
- echo "Looks like something went wrong. The error was \"$?\"."
- echo ""
- exit 1
- fi
- EXE="" # Blanking it, just in case
- cd "$GAMEDEST"
- echo "Select your executable from the following list:"
- echo ""
- EXELIST=( $(find $GAMEDEST -type f -name "*.exe") )
- PS3="#: "
- select file in "${EXELIST[@]}"; do
- if [[ -z $file ]]; then
- echo "Uh... Excuse me? Let's try that again." >&2
- else
- EXE="${file##*/}"
- echo ""
- echo "You've selected: \"$EXE\""
- echo "Not my fault if it doesn't work."
- echo ""
- break
- fi
- done
- echo ""
- echo "Writing Game Starter Script (GSS) for $1 to $GSS ..."
- echo ""
- #create game starter script
- cat << EOL > "$GSS"
- #!/bin/bash
- # $GSS #
- cd "\$(dirname "\$(readlink -f "\$0")")" || exit; [ "\$EUID" = "0" ] && echo "Please don't run as root!" && exit
- # wine
- export WINE="\$(command -v wine)"
- export WINEPREFIX="/home/\$(whoami)/Games/jc141"
- export WINEDLLOVERRIDES="winemenubuilder.exe=d;mshtml=d;nvapi,nvapi64=n"
- export WINE_LARGE_ADDRESS_AWARE=1
- export GAMEDIR="\$WINEPREFIX/drive_c/Games/$1"
- # external vulkan translation
- #export DXVK_ASYNC=1
- 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"
- VLKVER="\$(curl -s -m 5 https://api.github.com/repos/jc141x/vulkan/releases/latest | awk -F '["/]' '/"browser_download_url":/ {print \$11}' | cut -c 1-)"
- status-vulkan() { [[ ! -f "\$VLKLOG" || -z "\$(awk "/^\${FUNCNAME[1]}\$/ {print \$1}" "\$VLKLOG" 2>/dev/null)" ]] || { echo "\${FUNCNAME[1]} present" && return 1; }; }
- 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")"
- [ ! -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; }
- rm -rf "vulkan.tar.xz" && bash "\$PWD/vulkan/setup-vulkan.sh" && rm -Rf "\$VULKAN"; }
- vulkan-dl() { echo "Using external vulkan translation (dxvk,vkd3d,dxvk-nvapi)." && vulkan && echo "\$VLKVER" >"\$VLKLOG"; }
- [[ ! -f "\$VLKLOG" && -z "\$(status-vulkan)" ]] && vulkan-dl;
- [[ -f "\$VLKLOG" && -n "\$VLKVER" && "\$VLKVER" != "\$(awk '{print \$1}' "\$VLKLOG")" ]] && { rm -f vulkan.tar.xz || true; } && vulkan-dl
- # start
- export DXVK_ENABLE_NVAPI=1
- cd "\$GAMEDEST"
- "\$WINE" "$EXE" "\$@"
- EOL
- chmod a+x "$GSS"
- echo ""
- cat $GSS
- echo ""
- echo "\"$GSS\" written and made executable."
- echo ""
- echo ""
- echo "Path of the $1 wineprefix is: $WINEPREFIX"
- echo ""
- echo "Be sure to verify that the game executable written to \"$GSS\" is actually \"$EXE\" and modify if necessary."
- echo ""
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement