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.

383 lines
12KB

  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.3"
  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. -a | Selects the architecture to run as (32 | 64)
  47. -b | Runs wineboot
  48. -c | Launch a console session as specified user (can launch Xapps)
  49. -d | Debug messages on (turns verbose on)
  50. -g | Launches the game of your choice
  51. -h | Help (this message)
  52. -m | Runs Twitch client
  53. -n | No BS mode - doesn't launch an app (for boot/tricks/console safety)
  54. -p | Selects the location of the Wine prefix
  55. -s | Runs ${app_name} setup
  56. -t | Attempts to launch to the system tray
  57. -v | Verbose messages on
  58. -w | Runs winetricks
  59. -x | Force upgrade DXVK
  60. -z | Set the DISPLAY variable
  61. See more documentation at: ${page}"
  62. # Catch CTRL+C and cleanup
  63. trap "echo '' && inform '---------------------------------' && inform 'Caught CTRL+C' && warp 2" 2
  64. ## Set default environment
  65. cd /home/"${runas_user}"
  66. export RADV_PERFTEST=aco
  67. export WINEPREFIX="/home/${runas_user}/.bnet"
  68. export HOME="/home/${runas_user}"
  69. export USER="${runas_user}"
  70. export USERNAME="${runas_user}"
  71. export LOGNAME="${runas_user}"
  72. export WINEDEBUG=-all
  73. #export WINEDLLOVERRIDES="winemenubuilder.exe=d"
  74. export XAUTHORITY="/home/${runas_user}/.Xauthority"
  75. export PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/sbin"
  76. unset OLDPWD
  77. unset SUDO_GID
  78. unset SUDO_COMMAND
  79. unset SUDO_USER
  80. unset SUDO_UID
  81. ## Define our functions
  82. function debug () {
  83. if [ ! "${WINEDEBUG}" ]; then
  84. echo "-d- ${1}"
  85. fi
  86. }
  87. function inform () {
  88. if [ "${app_verbose}" ]; then
  89. echo "--- ${1}"
  90. fi
  91. }
  92. if [ -z "${DISPLAY}" ]; then
  93. inform "DISPLAY not set - using default (0.0)";
  94. export DISPLAY=:0.0
  95. else
  96. debug "Using DISPLAY variable: ${DISPLAY}";
  97. fi
  98. function clean {
  99. debug "clean"
  100. # Var
  101. unset script_ver
  102. unset runas_user
  103. unset app_name
  104. unset dl_addr
  105. unset install_dir
  106. unset app_loc
  107. unset console
  108. unset usage
  109. unset WINEPREFIX
  110. unset WINEDEBUG
  111. unset WINEARCH
  112. unset game_launch
  113. unset game_name
  114. unset game_start
  115. unset to_tray
  116. unset DISPLAY
  117. # Func
  118. unset debug
  119. unset inform
  120. unset game_on
  121. unset run_wine
  122. }
  123. function warp () {
  124. debug "warp" # exit the dungeon
  125. inform "Cleaning up ${runas_user}-side..."
  126. clean
  127. unset clean
  128. if [ "$1" ]; then
  129. unset warp && exit $1
  130. else
  131. echo "...what...?"
  132. unset warp && exit 5
  133. fi
  134. }
  135. function game_on {
  136. debug "game_on"
  137. case "${game_launch}" in
  138. test)
  139. echo "glxgears!"
  140. if [ "`which glxgears`" ]; then
  141. glxgears
  142. else
  143. echo "glxgears is not installed, or I can't find it in PATH"
  144. warp 1
  145. fi
  146. ;;
  147. wtcg|Wtcg|WTCG|hearth|hearthstone|HEARTH|HEARTHSTONE|hs|HS)
  148. game_name="Hearthstone"
  149. game_start="/Hearthstone/Hearthstone Beta Launcher.exe"
  150. ;;
  151. d3|D3|diablo3|Diablo3|DIABLO3)
  152. game_name="Diablo 3"
  153. game_start="/Diablo III/Diablo III Launcher.exe"
  154. ;;
  155. sc2|SC2|starcraft2|Starcraft2|StarCraft2|STARCRAFT2)
  156. game_name="StarCraft II"
  157. game_start="/StarCraft II/StarCraft II.exe"
  158. ;;
  159. sc|SC|starcraft|Starcraft|StarCraft|STARCRAFT)
  160. game_name="StarCraft"
  161. game_start="/StarCraft/StarCraft Launcher.exe"
  162. ;;
  163. wow|Wow|woW|WoW|WOW|worldofwarcraft|WorldofWarcraft|WorldOfWarcraft|WorldofWarCraft|WorldOfWarCraft|WORLDOFWARCRAFT)
  164. game_name="World of WarCraft"
  165. game_start="/World of Warcraft/World of Warcraft Launcher.exe"
  166. ;;
  167. hero|Hero|HERO|heros|Heros|HEROS|hots|HotS|HOTS)
  168. game_name="Heroes of the Storm"
  169. game_start="/Heroes of the Storm/Heroes of the Storm.exe"
  170. ;;
  171. pro|Pro|PRO|ow|OW|overwatch|Overwatch|OverWatch|OVERWATCH)
  172. game_name="Overwatch"
  173. game_start="/Overwatch/Overwatch Launcher.exe"
  174. ;;
  175. dst2|Dst2|DST2|destiny2|Destiny2|DESTINY2)
  176. echo "Destiny 2 cannot currently run on Linux without being banned."
  177. warp 1
  178. ;;
  179. *) echo "Unrecognized game: ${game_launch} - Can't launch!"
  180. echo "${usage}"
  181. warp 1
  182. ;;
  183. esac
  184. if [ "${game_launch}" != "test" ]; then
  185. echo "Attempting to run ${game_name}..."
  186. if [ -f "${WINEPREFIX}${install_dir}${game_start}" ]; then
  187. run_wine "${WINEPREFIX}${install_dir}${game_start}"
  188. else
  189. echo "${game_name} is not currently installed."
  190. warp 1
  191. fi
  192. fi
  193. }
  194. function run_wine () {
  195. debug "run_wine ${1}"
  196. if [ "${WINEARCH}" == "win64" ]; then
  197. debug "arch: win64"
  198. if [ "${WINEDEBUG}" ]; then
  199. wine64 "${1}" "${to_tray}" > /dev/null 2>&1
  200. else
  201. wine64 "${1}" "${to_tray}"
  202. fi
  203. wine64 "${1}" "${to_tray}"
  204. elif [ "${WINEARCH}" == "win32" ]; then
  205. debug "arch: win32"
  206. if [ "${WINEDEBUG}" ]; then
  207. wine "${1}" "${to_tray}" > /dev/null 2>&1
  208. else
  209. wine "${1}" "${to_tray}"
  210. fi
  211. else # Default to AMD64
  212. debug "arch: default (AMD64)"
  213. export WINEARCH=win64
  214. if [ "${WINEDEBUG}" ]; then
  215. wine64 "${1}" "${to_tray}" > /dev/null 2>&1
  216. else
  217. wine64 "${1}" "${to_tray}"
  218. fi
  219. fi
  220. }
  221. ## Pick up any arguments provided
  222. while getopts ":a:A:g:G:p:P:bBcCdDhHmMnNsStTvVwWxXzZ" option; do
  223. case "${option}" in
  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. "b"|"B")
  232. echo "Running wineboot..."
  233. nobs_mode="y"
  234. if [ "${WINEDEBUG}" ]; then
  235. wineboot > /dev/null 2>&1
  236. else
  237. wineboot
  238. fi
  239. ;;
  240. "c"|"C")
  241. echo "Running console..."
  242. nobs_mode="y"
  243. ${console}
  244. ;;
  245. "d"|"D")
  246. if [ "${WINEDEBUG}" ]; then
  247. unset WINEDEBUG
  248. debug "Run debug enabled"
  249. debug "`realpath "${0}"` version ${script_ver} running as ${runas_user}"
  250. app_verbose="y"
  251. fi
  252. ;;
  253. "g"|"G") game_launch="${OPTARG}";;
  254. "h"|"H")
  255. echo "${usage}"
  256. warp 0
  257. ;;
  258. "m"|"M")
  259. echo "Running Twitch Client..."
  260. nobs_mode="y"
  261. if [ -d ${WINEPREFIX}/drive_c/users/${runas_user}/Application\ Data/Twitch ]; then
  262. wine C:\\users\\${runas_user}\\Application\ Data\\Twitch\\Bin\\Twitch.exe
  263. else
  264. inform "...but it helps to install it first..."
  265. if [ ! -f "${WINEPREFIX}/drive_c/TwitchSetup.exe" ]; then
  266. inform "${WINEPREFIX}/drive_c/TwitchSetup.exe was not found. Retreiving."
  267. wget -O "${WINEPREFIX}/drive_c/TwitchSetup.exe" "${tc_addr}" ||
  268. (echo "Failed to download installer from ${tc_addr}"; warp 1)
  269. fi
  270. wine "${WINEPREFIX}/drive_c/TwitchSetup.exe"
  271. fi
  272. ;;
  273. "n"|"N")
  274. inform "...with No BS..."
  275. nobs_mode="y"
  276. ;;
  277. "p"|"P") export WINEPREFIX="${OPTARG}";;
  278. "s"|"S")
  279. nobs_mode="y"
  280. if [ -f "${WINEPREFIX}${install_dir}${app_loc}" ]; then
  281. echo "${app_name} looks like it's already installed. Aborting setup."
  282. warp 1
  283. else
  284. echo "Running setup..."
  285. if [ ! -f "${WINEPREFIX}/drive_c/${app_name}-Setup.exe" ]; then
  286. inform "${WINEPREFIX}/drive_c/${app_name}-Setup.exe was not found. Retreiving."
  287. wget -O "${WINEPREFIX}/drive_c/${app_name}-Setup.exe" "${dl_addr}" ||
  288. (echo "Failed to download installer from ${dl_addr}" && warp 1)
  289. else
  290. inform "Looks like the installer is in place. Executing."
  291. fi
  292. run_wine "${WINEPREFIX}/drive_c/${app_name}-Setup.exe"
  293. fi
  294. ;;
  295. "t"|"T")
  296. to_tray="--autostarted"
  297. inform "Attempting hide to system tray"
  298. ;;
  299. "v"|"V")
  300. if [ "${WINEDEBUG}" ]; then
  301. if [ ! "${app_verbose}" ]; then
  302. app_verbose="y"
  303. #inform "Run verbose enabled"
  304. inform "`realpath "${0}"` version ${script_ver} running as ${runas_user}"
  305. fi
  306. fi
  307. ;;
  308. "w"|"W")
  309. echo "Running winetricks..."
  310. nobs_mode="y"
  311. if [ ! "${app_verbose}" ]; then
  312. winetricks > /dev/null 2>&1
  313. else
  314. winetricks
  315. fi
  316. ;;
  317. "x"|"X")
  318. echo "Upgrading dxvk..."
  319. nobs_mode="y"
  320. if [ ! "${app_verbose}" ]; then
  321. winetricks --force dxvk > /dev/null 2>&1
  322. else
  323. winetricks --force dxvk
  324. fi
  325. ;;
  326. "z"|"Z")
  327. inform "DISPLAY set to ${OPTARG}"
  328. DISPLAY=${OPTARG}
  329. ;;
  330. *) echo "Unknown option: -${OPTARG}"
  331. echo "${usage}"
  332. warp 1
  333. ;;
  334. esac
  335. done
  336. ## If a game was set for launch, give it a shot. Otherwise launcher.
  337. if [ "${nobs_mode}" ]; then
  338. debug "Skipping app launches"
  339. else
  340. debug "launch_select"
  341. if [[ -d "${WINEPREFIX}" || "${game_launch}" == "test" ]]; then
  342. if [ "${game_launch}" ]; then
  343. inform "game_launch argument: ${game_launch}"
  344. game_on
  345. else
  346. echo "Running ${app_name}"
  347. run_wine "${WINEPREFIX}${install_dir}${app_loc}"
  348. fi
  349. else
  350. echo "Prefix ${WINEPREFIX} does not exist! Prep with -bs first"
  351. warp 1
  352. fi
  353. fi
  354. ## If we still exist, clean up.
  355. debug "final notice"
  356. warp 0