Run Steam and games easily, even under a secondary user
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. #!/bin/bash
  2. ## Copyright © 2018 Bret Human
  3. ## https://cynicaloptimist.me/
  4. ##
  5. ## Documentation at:
  6. ## https://mage.cynicaloptimist.me/en/st34m
  7. ## https://psi.cynicaloptimist.me/Caffarius/st34m/
  8. ##
  9. ## For questions or comments write:
  10. ## info@cynicaloptimist.me
  11. #####################################################################
  12. # st34m-run
  13. script_ver="1.0.1"
  14. # https://mage.cynicaloptimist.me/en/st34m
  15. # author: Bret Human
  16. # date: Dec 10, 2018
  17. #
  18. #####################################################################
  19. #
  20. # A wrapper for wrappers, used to manage/own a Steam installation in
  21. # a Linux environment.
  22. #
  23. # This is the second script in the line, fired off by st34m. This
  24. # script handles conditionals for safely running Steam or
  25. # most of its apps. The syntax makes it easily modular.
  26. #
  27. # If you want to add a game, search for "function game_on".
  28. #
  29. #####################################################################
  30. #
  31. # This is free software; you are free to change and redistribute it.
  32. # There is NO WARRANTY of any kind.
  33. #
  34. #####################################################################
  35. runas_user="`whoami`"
  36. app_name="Steam"
  37. app_dir="/usr/bin/"
  38. app_cmd="steam-native"
  39. console="bash"
  40. usage="st34m-run, version ${script_ver}
  41. Usage: ./`basename ${0}` -g (game) -dvptch
  42. -g | Launches the game of your choice
  43. -d | Debug messages on (turns verbose on)
  44. -v | Verbose messages on
  45. -p | Runs protontricks
  46. -t | Attempts to launch to the system tray
  47. -c | Launch a console session as specified user (can launch Xapps)
  48. -r | Use steam-runtime instead of steam-native
  49. -h | Help (this message)"
  50. # Catch CTRL+C and cleanup
  51. trap "echo '' && inform '---------------------------------' && inform 'Caught CTRL+C' && warp 2" 2
  52. ## Set default environment
  53. cd /home/"${runas_user}"
  54. export HOME="/home/${runas_user}"
  55. export USER="${runas_user}"
  56. export USERNAME="${runas_user}"
  57. export LOGNAME="${runas_user}"
  58. export WINEDEBUG=-all
  59. export XAUTHORITY="/home/${runas_user}/.Xauthority"
  60. export PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/sbin"
  61. unset OLDPWD
  62. unset SUDO_GID
  63. unset SUDO_COMMAND
  64. unset SUDO_USER
  65. unset SUDO_UID
  66. STEAM_FRAME_FORCE_CLOSE=1
  67. ## Define our functions
  68. function debug () {
  69. if [ ! "${WINEDEBUG}" ]; then
  70. echo "-d- ${1}"
  71. fi
  72. }
  73. function inform () {
  74. if [ "${app_verbose}" ]; then
  75. echo "--- ${1}"
  76. fi
  77. }
  78. function clean {
  79. debug "clean"
  80. # Var
  81. unset script_ver
  82. unset runas_user
  83. unset app_name
  84. unset app_dir
  85. unset app_cmd
  86. unset app_verbose
  87. unset app_proton
  88. unset console
  89. unset usage
  90. unset WINEDEBUG
  91. unset STEAM_FRAME_FORCE_CLOSE
  92. unset game_launch
  93. unset game_name
  94. unset game_id
  95. unset nobs_mode
  96. unset to_tray
  97. # Func
  98. unset debug
  99. unset inform
  100. unset game_on
  101. }
  102. function warp () {
  103. debug "warp" # exit the dungeon
  104. inform "Cleaning up ${runas_user}-side..."
  105. clean
  106. unset clean
  107. if [ "$1" ]; then
  108. unset warp && exit $1
  109. else
  110. echo "...what...?"
  111. unset warp && exit 5
  112. fi
  113. }
  114. function game_on {
  115. debug "game_on"
  116. case "${game_launch}" in
  117. test)
  118. echo "glxgears!"
  119. if [ "`which glxgears`" ]; then
  120. glxgears
  121. warp 0
  122. else
  123. echo "glxgears is not installed, or I can't find it in PATH"
  124. warp 1
  125. fi
  126. ;;
  127. 507490|ashes)
  128. game_name="Ashes of the Singularity: Escalation"
  129. game_id="507490"
  130. ;;
  131. 289070|civ6)
  132. game_name="Civilization VI"
  133. game_id="289070"
  134. ;;
  135. 65980|civbe)
  136. game_name="Civilization: Beyond Earth"
  137. game_id="65980"
  138. ;;
  139. 278080|dw8)
  140. game_name="Dynasty Warriors 8"
  141. game_id="278080"
  142. ;;
  143. 359320|elite)
  144. game_name="Elite Dangerous"
  145. game_id="359320"
  146. ;;
  147. 377160|fo4)
  148. game_name="Fallout 4"
  149. game_id="377160"
  150. ;;
  151. 244160|hw)
  152. game_name="Homeworld Remastered"
  153. game_id="244160"
  154. ;;
  155. 342200|mwo)
  156. game_name="MechWarrior Online"
  157. game_id="342200"
  158. ;;
  159. 204880|sins)
  160. game_name="Sins of a Solar Empire"
  161. game_id="204880"
  162. ;;
  163. *) echo "Unrecognized game: ${game_launch} - trying anyways..."
  164. game_id="${game_launch}"
  165. ;;
  166. esac
  167. if [ "${game_id}" ]; then
  168. if [ "${app_proton}" ]; then
  169. if [ "${WINEDEBUG}" ]; then
  170. protontricks "${game_id}" --gui > /dev/null 2>&1
  171. else
  172. protontricks "${game_id}" --gui
  173. fi
  174. else
  175. if [ ! "${game_name}" ]; then
  176. game_name="${game_id}"
  177. fi
  178. echo "Attempting to run ${game_name}..."
  179. ${app_dir}${app_cmd} steam://rungameid/${game_id}
  180. fi
  181. fi
  182. }
  183. ## Pick up any arguments provided
  184. while getopts ":g:G:dDvVpPtTnNcCrRhH" option; do
  185. case "${option}" in
  186. "g"|"G") game_launch="${OPTARG}";;
  187. "d"|"D")
  188. if [ "${WINEDEBUG}" ]; then
  189. unset WINEDEBUG
  190. debug "Run debug enabled"
  191. debug "`realpath "${0}"` version ${script_ver} running as ${runas_user}"
  192. app_verbose="y"
  193. fi
  194. ;;
  195. "p"|"P")
  196. echo "Running protontricks..."
  197. app_proton="y"
  198. ;;
  199. "n"|"N")
  200. inform "...with No BS..."
  201. nobs_mode="y"
  202. ;;
  203. "c"|"C")
  204. echo "Running console..."
  205. nobs_mode="y"
  206. ${console}
  207. ;;
  208. "v"|"V")
  209. if [ "${WINEDEBUG}" ]; then
  210. if [ ! "${app_verbose}" ]; then
  211. app_verbose="y"
  212. #inform "Run verbose enabled"
  213. inform "`realpath "${0}"` version ${script_ver} running as ${runas_user}"
  214. fi
  215. fi
  216. ;;
  217. "t"|"T")
  218. to_tray="-silent"
  219. inform "Attempting hide to system tray"
  220. ;;
  221. "r"|"R")
  222. echo "Switching to steam-runtime..."
  223. app_cmd="steam-runtime"
  224. ;;
  225. "h"|"H")
  226. echo "${usage}"
  227. warp 0
  228. ;;
  229. *) echo "Unknown option: -${OPTARG}"
  230. echo "${usage}"
  231. warp 1
  232. ;;
  233. esac
  234. done
  235. ## If a game was set for launch, give it a shot. Otherwise launcher.
  236. if [ "${nobs_mode}" ]; then
  237. debug "Skipping app launches"
  238. else
  239. debug "launch_select"
  240. if [ "${game_launch}" ]; then
  241. inform "game_launch argument: ${game_launch}"
  242. game_on
  243. else
  244. echo "Running ${app_name}"
  245. if [ "${WINEDEBUG}" ]; then
  246. ${app_dir}${app_cmd} "${to_tray}" > /dev/null 2>&1
  247. else
  248. ${app_dir}${app_cmd} "${to_tray}"
  249. fi
  250. fi
  251. fi
  252. ## If we still exist, clean up.
  253. debug "final notice"
  254. warp 0