Install Battle.net quickly and easily, even for a secondary user
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

bn3t-run.sh 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. #!/bin/bash
  2. ## Copyright © 2018 Bret Human
  3. ## https://cynicaloptimist.me/
  4. ##
  5. ## Documentation at:
  6. ## https://mage.cynicaloptimist.me/en/bn3t
  7. ## https://psi.cynicaloptimist.me/Caffarius/bn3t/
  8. ##
  9. ## For questions or comments write:
  10. ## info@cynicaloptimist.me
  11. #####################################################################
  12. # bn3t-run
  13. script_ver="0.2"
  14. page="https://mage.cynicaloptimist.me/en/bn3t"
  15. # author: Bret Human
  16. # date: Dec 6, 2018
  17. #
  18. #####################################################################
  19. #
  20. # A wrapper for wrappers, used to install/manage/own a Battle.net
  21. # installation within Wine in a Linux environment.
  22. #
  23. # This script is intended to be run by bn3t, Hence the name.
  24. #
  25. # This is the second script in the line, fired off by bn3t. This
  26. # script handles conditionals for safely running Battle.net or
  27. # most of its apps. The syntax makes it easily modular.
  28. #
  29. # If you want to add a game, search for "function game_on".
  30. #
  31. #####################################################################
  32. #
  33. # This is free software; you are free to change and redistribute it.
  34. # There is NO WARRANTY of any kind.
  35. #
  36. #####################################################################
  37. runas_user="`whoami`"
  38. app_name="Battle.net"
  39. dl_addr="https://www.battle.net/download/getInstallerForGame?os=win&locale=enUS&version=LIVE&gameProgram=BATTLENET_APP"
  40. tc_addr="https://desktop.twitchsvc.net/installer/windows/TwitchSetup.exe"
  41. install_dir="/drive_c/Program Files (x86)"
  42. app_loc="/Battle.net/Battle.net.exe"
  43. console="bash"
  44. usage="bn3t-run, version ${script_ver}
  45. Usage: ./`basename ${0}` -g (game) -p (prefix) -a (arch) -dvsbwtnchx
  46. -g | Launches the game of your choice
  47. -p | Selects the location of the Wine prefix
  48. -a | Selects the architecture to run as (32 | 64)
  49. -d | Debug messages on (turns verbose on)
  50. -v | Verbose messages on
  51. -s | Runs ${app_name} setup
  52. -b | Runs wineboot
  53. -w | Runs winetricks
  54. -m | Runs Twitch client
  55. -t | Attempts to launch to the system tray
  56. -n | No BS mode - doesn't launch an app (for boot/tricks/console safety)
  57. -c | Launch a console session as specified user (can launch Xapps)
  58. -h | Help (this message)
  59. -x | Force upgrade DXVK
  60. See more documentation at: ${page}"
  61. # Catch CTRL+C and cleanup
  62. trap "echo '' && inform '---------------------------------' && inform 'Caught CTRL+C' && warp 2" 2
  63. ## Set default environment
  64. cd /home/"${runas_user}"
  65. export WINEPREFIX="/home/${runas_user}/.bnet"
  66. export HOME="/home/${runas_user}"
  67. export USER="${runas_user}"
  68. export USERNAME="${runas_user}"
  69. export LOGNAME="${runas_user}"
  70. export WINEDEBUG=-all
  71. export XAUTHORITY="/home/${runas_user}/.Xauthority"
  72. export PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/sbin"
  73. unset OLDPWD
  74. unset SUDO_GID
  75. unset SUDO_COMMAND
  76. unset SUDO_USER
  77. unset SUDO_UID
  78. ## Define our functions
  79. function debug () {
  80. if [ ! "${WINEDEBUG}" ]; then
  81. echo "-d- ${1}"
  82. fi
  83. }
  84. function inform () {
  85. if [ "${app_verbose}" ]; then
  86. echo "--- ${1}"
  87. fi
  88. }
  89. function clean {
  90. debug "clean"
  91. # Var
  92. unset script_ver
  93. unset runas_user
  94. unset app_name
  95. unset dl_addr
  96. unset install_dir
  97. unset app_loc
  98. unset console
  99. unset usage
  100. unset WINEPREFIX
  101. unset WINEDEBUG
  102. unset WINEARCH
  103. unset game_launch
  104. unset game_name
  105. unset game_start
  106. unset to_tray
  107. # Func
  108. unset debug
  109. unset inform
  110. unset game_on
  111. unset run_wine
  112. }
  113. function warp () {
  114. debug "warp" # exit the dungeon
  115. inform "Cleaning up ${runas_user}-side..."
  116. clean
  117. unset clean
  118. if [ "$1" ]; then
  119. unset warp && exit $1
  120. else
  121. echo "...what...?"
  122. unset warp && exit 5
  123. fi
  124. }
  125. function game_on {
  126. debug "game_on"
  127. case "${game_launch}" in
  128. test)
  129. echo "glxgears!"
  130. if [ "`which glxgears`" ]; then
  131. glxgears
  132. else
  133. echo "glxgears is not installed, or I can't find it in PATH"
  134. warp 1
  135. fi
  136. ;;
  137. wtcg|Wtcg|WTCG|hearth|hearthstone|HEARTH|HEARTHSTONE|hs|HS)
  138. game_name="Hearthstone"
  139. game_start="/Hearthstone/Hearthstone Beta Launcher.exe"
  140. ;;
  141. d3|D3|diablo3|Diablo3|DIABLO3)
  142. game_name="Diablo 3"
  143. game_start="/Diablo III/Diablo III Launcher.exe"
  144. ;;
  145. sc2|SC2|starcraft2|Starcraft2|StarCraft2|STARCRAFT2)
  146. game_name="StarCraft II"
  147. game_start="/StarCraft II/StarCraft II.exe"
  148. ;;
  149. sc|SC|starcraft|Starcraft|StarCraft|STARCRAFT)
  150. game_name="StarCraft"
  151. game_start="/StarCraft/StarCraft Launcher.exe"
  152. ;;
  153. wow|Wow|woW|WoW|WOW|worldofwarcraft|WorldofWarcraft|WorldOfWarcraft|WorldofWarCraft|WorldOfWarCraft|WORLDOFWARCRAFT)
  154. game_name="World of WarCraft"
  155. game_start="/World of Warcraft/World of Warcraft Launcher.exe"
  156. ;;
  157. hero|Hero|HERO|heros|Heros|HEROS|hots|HotS|HOTS)
  158. game_name="Heroes of the Storm"
  159. game_start="/Heroes of the Storm/Heroes of the Storm.exe"
  160. ;;
  161. pro|Pro|PRO|ow|OW|overwatch|Overwatch|OverWatch|OVERWATCH)
  162. game_name="Overwatch"
  163. game_start="/Overwatch/Overwatch Launcher.exe"
  164. ;;
  165. dst2|Dst2|DST2|destiny2|Destiny2|DESTINY2)
  166. echo "Destiny 2 cannot currently run on Linux without being banned."
  167. warp 1
  168. ;;
  169. *) echo "Unrecognized game: ${game_launch} - Can't launch!"
  170. echo "${usage}"
  171. warp 1
  172. ;;
  173. esac
  174. if [ "${game_launch}" != "test" ]; then
  175. echo "Attempting to run ${game_name}..."
  176. if [ -f "${WINEPREFIX}${install_dir}${game_start}" ]; then
  177. run_wine "${WINEPREFIX}${install_dir}${game_start}"
  178. else
  179. echo "${game_name} is not currently installed."
  180. warp 1
  181. fi
  182. fi
  183. }
  184. function run_wine () {
  185. debug "run_wine ${1}"
  186. if [ "${WINEARCH}" == "win64" ]; then
  187. debug "arch: win64"
  188. if [ "${WINEDEBUG}" ]; then
  189. wine64 "${1}" "${to_tray}" > /dev/null 2>&1
  190. else
  191. wine64 "${1}" "${to_tray}"
  192. fi
  193. wine64 "${1}" "${to_tray}"
  194. elif [ "${WINEARCH}" == "win32" ]; then
  195. debug "arch: win32"
  196. if [ "${WINEDEBUG}" ]; then
  197. wine "${1}" "${to_tray}" > /dev/null 2>&1
  198. else
  199. wine "${1}" "${to_tray}"
  200. fi
  201. else # Default to AMD64
  202. debug "arch: default (AMD64)"
  203. export WINEARCH=win64
  204. if [ "${WINEDEBUG}" ]; then
  205. wine64 "${1}" "${to_tray}" > /dev/null 2>&1
  206. else
  207. wine64 "${1}" "${to_tray}"
  208. fi
  209. fi
  210. }
  211. ## Pick up any arguments provided
  212. while getopts ":g:G:p:P:a:A:dDvVsSbBwWtTnNcChHxXmM" option; do
  213. case "${option}" in
  214. "g"|"G") game_launch="${OPTARG}";;
  215. "d"|"D")
  216. if [ "${WINEDEBUG}" ]; then
  217. unset WINEDEBUG
  218. debug "Run debug enabled"
  219. debug "`realpath "${0}"` version ${script_ver} running as ${runas_user}"
  220. app_verbose="y"
  221. fi
  222. ;;
  223. "p"|"P") export WINEPREFIX="${OPTARG}";;
  224. "a"|"A")
  225. case "${OPTARG}" in
  226. 32) export WINEARCH=win32;;
  227. 64) export WINEARCH=win64;;
  228. *) inform "Weird architecture: ${OPTARG}, ignoring";;
  229. esac
  230. ;;
  231. "m"|"M")
  232. echo "Running Twitch Client..."
  233. nobs_mode="y"
  234. if [ -d ${WINEPREFIX}/drive_c/users/${runas_user}/Application\ Data/Twitch ]; then
  235. wine C:\\users\\${runas_user}\\Application\ Data\\Twitch\\Bin\\Twitch.exe
  236. else
  237. inform "...but it helps to install it first..."
  238. if [ ! -f "/tmp/TwitchSetup.exe" ]; then
  239. inform "/tmp/TwitchSetup.exe was not found. Retreiving."
  240. wget -O "/tmp/TwitchSetup.exe" "${tc_addr}" ||
  241. (echo "Failed to download installer from ${tc_addr}"; warp 1)
  242. fi
  243. wine "/tmp/TwitchSetup.exe"
  244. fi
  245. ;;
  246. "w"|"W")
  247. echo "Running winetricks..."
  248. nobs_mode="y"
  249. if [ ! "${app_verbose}" ]; then
  250. winetricks > /dev/null 2>&1
  251. else
  252. winetricks
  253. fi
  254. ;;
  255. "s"|"S")
  256. nobs_mode="y"
  257. if [ -f "${WINEPREFIX}${install_dir}${app_loc}" ]; then
  258. echo "${app_name} looks like it's already installed. Aborting setup."
  259. warp 1
  260. else
  261. echo "Running setup..."
  262. if [ ! -f "/tmp/${app_name}-Setup.exe" ]; then
  263. inform "/tmp/${app_name}-Setup.exe was not found. Retreiving."
  264. wget -O "/tmp/${app_name}-Setup.exe" "${dl_addr}" ||
  265. (echo "Failed to download installer from ${dl_addr}" && warp 1)
  266. else
  267. inform "Looks like the installer is in place. Executing."
  268. fi
  269. run_wine "/tmp/${app_name}-Setup.exe"
  270. fi
  271. ;;
  272. "x"|"X")
  273. echo "Upgrading dxvk..."
  274. nobs_mode="y"
  275. if [ ! "${app_verbose}" ]; then
  276. winetricks --force dxvk > /dev/null 2>&1
  277. else
  278. winetricks --force dxvk
  279. fi
  280. ;;
  281. "b"|"B")
  282. echo "Running wineboot..."
  283. nobs_mode="y"
  284. if [ -d "${WINEPREFIX}" ]; then
  285. echo "${WINEPREFIX} already exists! Refusing to wineboot."
  286. else
  287. if [ "${WINEDEBUG}" ]; then
  288. wineboot > /dev/null 2>&1
  289. else
  290. wineboot
  291. fi
  292. fi
  293. ;;
  294. "n"|"N")
  295. inform "...with No BS..."
  296. nobs_mode="y"
  297. ;;
  298. "c"|"C")
  299. echo "Running console..."
  300. nobs_mode="y"
  301. ${console}
  302. ;;
  303. "v"|"V")
  304. if [ "${WINEDEBUG}" ]; then
  305. if [ ! "${app_verbose}" ]; then
  306. app_verbose="y"
  307. #inform "Run verbose enabled"
  308. inform "`realpath "${0}"` version ${script_ver} running as ${runas_user}"
  309. fi
  310. fi
  311. ;;
  312. "t"|"T")
  313. to_tray="--autostarted"
  314. inform "Attempting hide to system tray"
  315. ;;
  316. "h"|"H")
  317. echo "${usage}"
  318. warp 0
  319. ;;
  320. *) echo "Unknown option: -${OPTARG}"
  321. echo "${usage}"
  322. warp 1
  323. ;;
  324. esac
  325. done
  326. ## If a game was set for launch, give it a shot. Otherwise launcher.
  327. if [ "${nobs_mode}" ]; then
  328. debug "Skipping app launches"
  329. else
  330. debug "launch_select"
  331. if [[ -d "${WINEPREFIX}" || "${game_launch}" == "test" ]]; then
  332. if [ "${game_launch}" ]; then
  333. inform "game_launch argument: ${game_launch}"
  334. game_on
  335. else
  336. echo "Running ${app_name}"
  337. run_wine "${WINEPREFIX}${install_dir}${app_loc}"
  338. fi
  339. else
  340. echo "Prefix ${WINEPREFIX} does not exist! Prep with -bs first"
  341. warp 1
  342. fi
  343. fi
  344. ## If we still exist, clean up.
  345. debug "final notice"
  346. warp 0