2019-05-21 08:44:34 -04:00
|
|
|
#!/bin/bash
|
|
|
|
## Copyright © 2018 Bret Human
|
|
|
|
## https://cynicaloptimist.me/
|
|
|
|
##
|
|
|
|
## Documentation at:
|
|
|
|
## https://mage.cynicaloptimist.me/en/bn3t
|
|
|
|
## https://psi.cynicaloptimist.me/Caffarius/bn3t/
|
|
|
|
##
|
|
|
|
## For questions or comments write:
|
|
|
|
## info@cynicaloptimist.me
|
|
|
|
#####################################################################
|
|
|
|
# bn3t-run
|
2019-05-21 08:52:53 -04:00
|
|
|
script_ver="0.2"
|
2019-05-21 08:44:34 -04:00
|
|
|
page="https://mage.cynicaloptimist.me/en/bn3t"
|
|
|
|
# author: Bret Human
|
|
|
|
# date: Dec 6, 2018
|
|
|
|
#
|
|
|
|
#####################################################################
|
|
|
|
#
|
|
|
|
# A wrapper for wrappers, used to install/manage/own a Battle.net
|
|
|
|
# installation within Wine in a Linux environment.
|
|
|
|
#
|
|
|
|
# This script is intended to be run by bn3t, Hence the name.
|
|
|
|
#
|
|
|
|
# This is the second script in the line, fired off by bn3t. This
|
|
|
|
# script handles conditionals for safely running Battle.net or
|
|
|
|
# most of its apps. The syntax makes it easily modular.
|
|
|
|
#
|
|
|
|
# If you want to add a game, search for "function game_on".
|
|
|
|
#
|
|
|
|
#####################################################################
|
|
|
|
#
|
|
|
|
# This is free software; you are free to change and redistribute it.
|
|
|
|
# There is NO WARRANTY of any kind.
|
|
|
|
#
|
|
|
|
#####################################################################
|
|
|
|
|
|
|
|
runas_user="`whoami`"
|
|
|
|
app_name="Battle.net"
|
|
|
|
dl_addr="https://www.battle.net/download/getInstallerForGame?os=win&locale=enUS&version=LIVE&gameProgram=BATTLENET_APP"
|
2019-05-21 08:52:53 -04:00
|
|
|
tc_addr="https://desktop.twitchsvc.net/installer/windows/TwitchSetup.exe"
|
2019-05-21 08:44:34 -04:00
|
|
|
install_dir="/drive_c/Program Files (x86)"
|
|
|
|
app_loc="/Battle.net/Battle.net.exe"
|
|
|
|
console="bash"
|
|
|
|
usage="bn3t-run, version ${script_ver}
|
|
|
|
Usage: ./`basename ${0}` -g (game) -p (prefix) -a (arch) -dvsbwtnchx
|
|
|
|
-g | Launches the game of your choice
|
|
|
|
-p | Selects the location of the Wine prefix
|
|
|
|
-a | Selects the architecture to run as (32 | 64)
|
|
|
|
-d | Debug messages on (turns verbose on)
|
|
|
|
-v | Verbose messages on
|
|
|
|
-s | Runs ${app_name} setup
|
|
|
|
-b | Runs wineboot
|
|
|
|
-w | Runs winetricks
|
2019-05-21 08:52:53 -04:00
|
|
|
-m | Runs Twitch client
|
2019-05-21 08:44:34 -04:00
|
|
|
-t | Attempts to launch to the system tray
|
|
|
|
-n | No BS mode - doesn't launch an app (for boot/tricks/console safety)
|
|
|
|
-c | Launch a console session as specified user (can launch Xapps)
|
|
|
|
-h | Help (this message)
|
|
|
|
-x | Force upgrade DXVK
|
|
|
|
See more documentation at: ${page}"
|
|
|
|
|
|
|
|
# Catch CTRL+C and cleanup
|
|
|
|
trap "echo '' && inform '---------------------------------' && inform 'Caught CTRL+C' && warp 2" 2
|
|
|
|
|
|
|
|
## Set default environment
|
|
|
|
cd /home/"${runas_user}"
|
|
|
|
export WINEPREFIX="/home/${runas_user}/.bnet"
|
|
|
|
export HOME="/home/${runas_user}"
|
|
|
|
export USER="${runas_user}"
|
|
|
|
export USERNAME="${runas_user}"
|
|
|
|
export LOGNAME="${runas_user}"
|
|
|
|
export WINEDEBUG=-all
|
|
|
|
export XAUTHORITY="/home/${runas_user}/.Xauthority"
|
|
|
|
export PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/sbin"
|
|
|
|
unset OLDPWD
|
|
|
|
unset SUDO_GID
|
|
|
|
unset SUDO_COMMAND
|
|
|
|
unset SUDO_USER
|
|
|
|
unset SUDO_UID
|
|
|
|
|
|
|
|
## Define our functions
|
|
|
|
function debug () {
|
|
|
|
if [ ! "${WINEDEBUG}" ]; then
|
|
|
|
echo "-d- ${1}"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function inform () {
|
|
|
|
if [ "${app_verbose}" ]; then
|
|
|
|
echo "--- ${1}"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function clean {
|
|
|
|
debug "clean"
|
|
|
|
|
|
|
|
# Var
|
|
|
|
unset script_ver
|
|
|
|
unset runas_user
|
|
|
|
unset app_name
|
|
|
|
unset dl_addr
|
|
|
|
unset install_dir
|
|
|
|
unset app_loc
|
|
|
|
unset console
|
|
|
|
unset usage
|
|
|
|
unset WINEPREFIX
|
|
|
|
unset WINEDEBUG
|
|
|
|
unset WINEARCH
|
|
|
|
unset game_launch
|
|
|
|
unset game_name
|
|
|
|
unset game_start
|
|
|
|
unset to_tray
|
|
|
|
|
|
|
|
# Func
|
|
|
|
unset debug
|
|
|
|
unset inform
|
|
|
|
unset game_on
|
|
|
|
unset run_wine
|
|
|
|
}
|
|
|
|
|
|
|
|
function warp () {
|
|
|
|
debug "warp" # exit the dungeon
|
|
|
|
inform "Cleaning up ${runas_user}-side..."
|
|
|
|
clean
|
|
|
|
unset clean
|
|
|
|
|
|
|
|
if [ "$1" ]; then
|
|
|
|
unset warp && exit $1
|
|
|
|
else
|
|
|
|
echo "...what...?"
|
|
|
|
unset warp && exit 5
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function game_on {
|
|
|
|
debug "game_on"
|
|
|
|
case "${game_launch}" in
|
|
|
|
test)
|
|
|
|
echo "glxgears!"
|
|
|
|
if [ "`which glxgears`" ]; then
|
|
|
|
glxgears
|
|
|
|
else
|
|
|
|
echo "glxgears is not installed, or I can't find it in PATH"
|
|
|
|
warp 1
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
wtcg|Wtcg|WTCG|hearth|hearthstone|HEARTH|HEARTHSTONE|hs|HS)
|
|
|
|
game_name="Hearthstone"
|
|
|
|
game_start="/Hearthstone/Hearthstone Beta Launcher.exe"
|
|
|
|
;;
|
|
|
|
d3|D3|diablo3|Diablo3|DIABLO3)
|
|
|
|
game_name="Diablo 3"
|
|
|
|
game_start="/Diablo III/Diablo III Launcher.exe"
|
|
|
|
;;
|
|
|
|
sc2|SC2|starcraft2|Starcraft2|StarCraft2|STARCRAFT2)
|
|
|
|
game_name="StarCraft II"
|
|
|
|
game_start="/StarCraft II/StarCraft II.exe"
|
|
|
|
;;
|
|
|
|
sc|SC|starcraft|Starcraft|StarCraft|STARCRAFT)
|
|
|
|
game_name="StarCraft"
|
|
|
|
game_start="/StarCraft/StarCraft Launcher.exe"
|
|
|
|
;;
|
|
|
|
wow|Wow|woW|WoW|WOW|worldofwarcraft|WorldofWarcraft|WorldOfWarcraft|WorldofWarCraft|WorldOfWarCraft|WORLDOFWARCRAFT)
|
|
|
|
game_name="World of WarCraft"
|
|
|
|
game_start="/World of Warcraft/World of Warcraft Launcher.exe"
|
|
|
|
;;
|
|
|
|
hero|Hero|HERO|heros|Heros|HEROS|hots|HotS|HOTS)
|
|
|
|
game_name="Heroes of the Storm"
|
|
|
|
game_start="/Heroes of the Storm/Heroes of the Storm.exe"
|
|
|
|
;;
|
|
|
|
pro|Pro|PRO|ow|OW|overwatch|Overwatch|OverWatch|OVERWATCH)
|
|
|
|
game_name="Overwatch"
|
|
|
|
game_start="/Overwatch/Overwatch Launcher.exe"
|
|
|
|
;;
|
|
|
|
dst2|Dst2|DST2|destiny2|Destiny2|DESTINY2)
|
|
|
|
echo "Destiny 2 cannot currently run on Linux without being banned."
|
|
|
|
warp 1
|
|
|
|
;;
|
|
|
|
*) echo "Unrecognized game: ${game_launch} - Can't launch!"
|
|
|
|
echo "${usage}"
|
|
|
|
warp 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
if [ "${game_launch}" != "test" ]; then
|
|
|
|
echo "Attempting to run ${game_name}..."
|
|
|
|
if [ -f "${WINEPREFIX}${install_dir}${game_start}" ]; then
|
|
|
|
run_wine "${WINEPREFIX}${install_dir}${game_start}"
|
|
|
|
else
|
|
|
|
echo "${game_name} is not currently installed."
|
|
|
|
warp 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function run_wine () {
|
|
|
|
debug "run_wine ${1}"
|
|
|
|
if [ "${WINEARCH}" == "win64" ]; then
|
|
|
|
debug "arch: win64"
|
|
|
|
if [ "${WINEDEBUG}" ]; then
|
|
|
|
wine64 "${1}" "${to_tray}" > /dev/null 2>&1
|
|
|
|
else
|
|
|
|
wine64 "${1}" "${to_tray}"
|
|
|
|
fi
|
|
|
|
wine64 "${1}" "${to_tray}"
|
|
|
|
elif [ "${WINEARCH}" == "win32" ]; then
|
|
|
|
debug "arch: win32"
|
|
|
|
if [ "${WINEDEBUG}" ]; then
|
|
|
|
wine "${1}" "${to_tray}" > /dev/null 2>&1
|
|
|
|
else
|
|
|
|
wine "${1}" "${to_tray}"
|
|
|
|
fi
|
|
|
|
else # Default to AMD64
|
|
|
|
debug "arch: default (AMD64)"
|
|
|
|
export WINEARCH=win64
|
|
|
|
if [ "${WINEDEBUG}" ]; then
|
|
|
|
wine64 "${1}" "${to_tray}" > /dev/null 2>&1
|
|
|
|
else
|
|
|
|
wine64 "${1}" "${to_tray}"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Pick up any arguments provided
|
2019-05-21 08:52:53 -04:00
|
|
|
while getopts ":g:G:p:P:a:A:dDvVsSbBwWtTnNcChHxXmM" option; do
|
2019-05-21 08:44:34 -04:00
|
|
|
case "${option}" in
|
|
|
|
"g"|"G") game_launch="${OPTARG}";;
|
|
|
|
"d"|"D")
|
|
|
|
if [ "${WINEDEBUG}" ]; then
|
|
|
|
unset WINEDEBUG
|
|
|
|
debug "Run debug enabled"
|
|
|
|
debug "`realpath "${0}"` version ${script_ver} running as ${runas_user}"
|
|
|
|
app_verbose="y"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
"p"|"P") export WINEPREFIX="${OPTARG}";;
|
|
|
|
"a"|"A")
|
|
|
|
case "${OPTARG}" in
|
|
|
|
32) export WINEARCH=win32;;
|
|
|
|
64) export WINEARCH=win64;;
|
|
|
|
*) inform "Weird architecture: ${OPTARG}, ignoring";;
|
|
|
|
esac
|
|
|
|
;;
|
2019-05-21 08:52:53 -04:00
|
|
|
"m"|"M")
|
|
|
|
echo "Running Twitch Client..."
|
|
|
|
nobs_mode="y"
|
|
|
|
|
|
|
|
if [ -d ${WINEPREFIX}/drive_c/users/${runas_user}/Application\ Data/Twitch ]; then
|
|
|
|
wine C:\\users\\${runas_user}\\Application\ Data\\Twitch\\Bin\\Twitch.exe
|
|
|
|
else
|
|
|
|
inform "...but it helps to install it first..."
|
|
|
|
if [ ! -f "/tmp/TwitchSetup.exe" ]; then
|
|
|
|
inform "/tmp/TwitchSetup.exe was not found. Retreiving."
|
|
|
|
wget -O "/tmp/TwitchSetup.exe" "${tc_addr}" ||
|
|
|
|
(echo "Failed to download installer from ${tc_addr}"; warp 1)
|
|
|
|
fi
|
|
|
|
wine "/tmp/TwitchSetup.exe"
|
|
|
|
fi
|
|
|
|
;;
|
2019-05-21 08:44:34 -04:00
|
|
|
"w"|"W")
|
|
|
|
echo "Running winetricks..."
|
|
|
|
nobs_mode="y"
|
|
|
|
if [ ! "${app_verbose}" ]; then
|
|
|
|
winetricks > /dev/null 2>&1
|
|
|
|
else
|
|
|
|
winetricks
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
"s"|"S")
|
|
|
|
nobs_mode="y"
|
|
|
|
if [ -f "${WINEPREFIX}${install_dir}${app_loc}" ]; then
|
|
|
|
echo "${app_name} looks like it's already installed. Aborting setup."
|
|
|
|
warp 1
|
|
|
|
else
|
|
|
|
echo "Running setup..."
|
|
|
|
if [ ! -f "/tmp/${app_name}-Setup.exe" ]; then
|
|
|
|
inform "/tmp/${app_name}-Setup.exe was not found. Retreiving."
|
|
|
|
wget -O "/tmp/${app_name}-Setup.exe" "${dl_addr}" ||
|
|
|
|
(echo "Failed to download installer from ${dl_addr}" && warp 1)
|
|
|
|
else
|
|
|
|
inform "Looks like the installer is in place. Executing."
|
|
|
|
fi
|
|
|
|
run_wine "/tmp/${app_name}-Setup.exe"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
"x"|"X")
|
|
|
|
echo "Upgrading dxvk..."
|
|
|
|
nobs_mode="y"
|
|
|
|
if [ ! "${app_verbose}" ]; then
|
|
|
|
winetricks --force dxvk > /dev/null 2>&1
|
|
|
|
else
|
|
|
|
winetricks --force dxvk
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
"b"|"B")
|
|
|
|
echo "Running wineboot..."
|
|
|
|
nobs_mode="y"
|
|
|
|
if [ -d "${WINEPREFIX}" ]; then
|
|
|
|
echo "${WINEPREFIX} already exists! Refusing to wineboot."
|
|
|
|
else
|
|
|
|
if [ "${WINEDEBUG}" ]; then
|
|
|
|
wineboot > /dev/null 2>&1
|
|
|
|
else
|
|
|
|
wineboot
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
"n"|"N")
|
|
|
|
inform "...with No BS..."
|
|
|
|
nobs_mode="y"
|
|
|
|
;;
|
|
|
|
"c"|"C")
|
|
|
|
echo "Running console..."
|
|
|
|
nobs_mode="y"
|
|
|
|
${console}
|
|
|
|
;;
|
|
|
|
"v"|"V")
|
|
|
|
if [ "${WINEDEBUG}" ]; then
|
|
|
|
if [ ! "${app_verbose}" ]; then
|
|
|
|
app_verbose="y"
|
|
|
|
#inform "Run verbose enabled"
|
|
|
|
inform "`realpath "${0}"` version ${script_ver} running as ${runas_user}"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
"t"|"T")
|
|
|
|
to_tray="--autostarted"
|
|
|
|
inform "Attempting hide to system tray"
|
|
|
|
;;
|
|
|
|
"h"|"H")
|
|
|
|
echo "${usage}"
|
|
|
|
warp 0
|
|
|
|
;;
|
|
|
|
*) echo "Unknown option: -${OPTARG}"
|
|
|
|
echo "${usage}"
|
|
|
|
warp 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## If a game was set for launch, give it a shot. Otherwise launcher.
|
|
|
|
if [ "${nobs_mode}" ]; then
|
|
|
|
debug "Skipping app launches"
|
|
|
|
else
|
|
|
|
debug "launch_select"
|
|
|
|
if [[ -d "${WINEPREFIX}" || "${game_launch}" == "test" ]]; then
|
|
|
|
if [ "${game_launch}" ]; then
|
|
|
|
inform "game_launch argument: ${game_launch}"
|
|
|
|
game_on
|
|
|
|
else
|
|
|
|
echo "Running ${app_name}"
|
|
|
|
run_wine "${WINEPREFIX}${install_dir}${app_loc}"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "Prefix ${WINEPREFIX} does not exist! Prep with -bs first"
|
|
|
|
warp 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## If we still exist, clean up.
|
|
|
|
debug "final notice"
|
|
|
|
warp 0
|