check_deps.sh 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. #!/bin/bash
  2. # LGSM check_deps.sh function
  3. # Author: Daniel Gibbs
  4. # Website: https://gameservermanagers.com
  5. # Description: Checks if required dependencies are installed for LGSM.
  6. local commandname="CHECK"
  7. fn_deps_detector(){
  8. # Checks if dependency is missing
  9. if [ "${tmuxcheck}" == "1" ]; then
  10. # Added for users compiling tmux from source to bypass check.
  11. depstatus=0
  12. deptocheck="tmux"
  13. unset tmuxcheck
  14. elif [ "${javacheck}" == "1" ]; then
  15. # Added for users using Oracle JRE to bypass check.
  16. depstatus=0
  17. deptocheck="${javaversion}"
  18. unset javacheck
  19. elif [ -n "$(command -v apt-get)" ]; then
  20. dpkg-query -W -f='${Status}' ${deptocheck} 2>/dev/null | grep -q -P '^install ok installed$'
  21. depstatus=$?
  22. elif [ -n "$(command -v yum)" ]; then
  23. yum -q list installed ${deptocheck} > /dev/null 2>&1
  24. depstatus=$?
  25. fi
  26. if [ "${depstatus}" == "0" ]; then
  27. # if dependency is found
  28. missingdep=0
  29. if [ "${function_selfname}" == "command_install.sh" ]; then
  30. echo -e "${green}${deptocheck}${default}"
  31. sleep 0.5
  32. fi
  33. else
  34. # if dependency is not found
  35. missingdep=1
  36. if [ "${function_selfname}" == "command_install.sh" ]; then
  37. echo -e "${red}${deptocheck}${default}"
  38. sleep 0.5
  39. fi
  40. fi
  41. # Missing dependencies are added to array_deps_missing
  42. if [ "${missingdep}" == "1" ]; then
  43. array_deps_missing+=("${deptocheck}")
  44. fi
  45. }
  46. fn_deps_email(){
  47. # Adds postfix to required dependencies if email alert is enabled
  48. if [ "${emailalert}" == "on" ]; then
  49. if [ -f /usr/bin/mailx ]; then
  50. if [ -d /etc/exim4 ]; then
  51. array_deps_required+=( exim4 )
  52. elif [ -d /etc/sendmail ]; then
  53. array_deps_required+=( sendmail )
  54. elif [ -n "$(command -v dpkg-query)" ]; then
  55. array_deps_required+=( mailutils postfix )
  56. elif [ -n "$(command -v yum)" ]; then
  57. array_deps_required+=( mailx postfix )
  58. fi
  59. else
  60. if [ -n "$(command -v dpkg-query)" ]; then
  61. array_deps_required+=( mailutils postfix )
  62. elif [ -n "$(command -v yum)" ]; then
  63. array_deps_required+=( mailx postfix )
  64. fi
  65. fi
  66. fi
  67. }
  68. fn_found_missing_deps(){
  69. if [ "${#array_deps_missing[@]}" != "0" ]; then
  70. fn_print_dots "Checking dependencies"
  71. sleep 0.5
  72. fn_print_error_nl "Checking dependencies: missing: ${red}${array_deps_missing[@]}${default}"
  73. fn_script_log_error "Checking dependencies: missing: ${array_deps_missing[@]}"
  74. sleep 1
  75. sudo -v > /dev/null 2>&1
  76. if [ $? -eq 0 ]; then
  77. fn_print_information_nl "Automatically installing missing dependencies."
  78. fn_script_log_info "Automatically installing missing dependencies."
  79. echo -en ".\r"
  80. sleep 1
  81. echo -en "..\r"
  82. sleep 1
  83. echo -en "...\r"
  84. sleep 1
  85. echo -en " \r"
  86. if [ -n "$(command -v dpkg-query)" ]; then
  87. cmd="sudo dpkg --add-architecture i386; sudo apt-get update; sudo apt-get -y install ${array_deps_missing[@]}"
  88. eval ${cmd}
  89. elif [ -n "$(command -v yum)" ]; then
  90. cmd="sudo yum -y install ${array_deps_missing[@]}"
  91. eval ${cmd}
  92. fi
  93. if [ $? != 0 ]; then
  94. fn_print_failure_nl "Unable to install dependencies"
  95. fn_script_log_fatal "Unable to install dependencies"
  96. else
  97. fn_print_complete_nl "Install dependencies completed"
  98. fn_script_log_pass "Install dependencies completed"
  99. fi
  100. else
  101. echo ""
  102. fn_print_warning_nl "$(whoami) does not have sudo access. Manually install dependencies."
  103. fn_script_log_warn "$(whoami) does not have sudo access. Manually install dependencies."
  104. if [ -n "$(command -v dpkg-query)" ]; then
  105. echo " sudo dpkg --add-architecture i386; sudo apt-get update; sudo apt-get install ${array_deps_missing[@]}"
  106. elif [ -n "$(command -v yum)" ]; then
  107. echo " sudo yum install ${array_deps_missing[@]}"
  108. fi
  109. echo ""
  110. fi
  111. if [ "${function_selfname}" == "command_install.sh" ]; then
  112. sleep 5
  113. fi
  114. fi
  115. }
  116. fn_check_loop(){
  117. # Loop though required depenencies
  118. for deptocheck in "${array_deps_required[@]}"
  119. do
  120. fn_deps_detector
  121. done
  122. # user to be informed of any missing dependencies
  123. fn_found_missing_deps
  124. }
  125. info_distro.sh
  126. if [ "${function_selfname}" == "command_install.sh" ]; then
  127. echo ""
  128. echo "Checking Dependencies"
  129. echo "================================="
  130. fi
  131. # Check will only run if using apt-get or yum
  132. if [ -n "$(command -v dpkg-query)" ]; then
  133. # Generate array of missing deps
  134. array_deps_missing=()
  135. # LGSM requirements
  136. array_deps_required=( curl wget ca-certificates file bsdmainutils util-linux python bzip2 gzip unzip )
  137. # All servers except ts3 require tmux
  138. if [ "${gamename}" != "TeamSpeak 3" ]; then
  139. if [ "$(command -v tmux)" ]||[ "$(which tmux 2>/dev/null)" ]||[ -f "/usr/bin/tmux" ]||[ -f "/bin/tmux" ]; then
  140. tmuxcheck=1 # Added for users compiling tmux from source to bypass check.
  141. else
  142. array_deps_required+=( tmux )
  143. fi
  144. fi
  145. # All servers except ts3,mumble and minecraft servers require libstdc++6 and lib32gcc1
  146. if [ "${gamename}" != "TeamSpeak 3" ]&&[ "${gamename}" != "Mumble" ]&&[ "${engine}" != "lwjgl2" ]; then
  147. if [ "${arch}" == "x86_64" ]; then
  148. array_deps_required+=( lib32gcc1 libstdc++6:i386 )
  149. else
  150. array_deps_required+=( libstdc++6:i386 )
  151. fi
  152. fi
  153. # Game Specific requirements
  154. # Spark
  155. if [ "${engine}" == "spark" ]; then
  156. array_deps_required+=( speex:i386 libtbb2 )
  157. # 7 Days to Die
  158. elif [ "${gamename}" == "7 Days To Die" ]; then
  159. array_deps_required+=( telnet expect )
  160. # No More Room in Hell, Counter-Strike: Source and Garry's Mod
  161. elif [ "${gamename}" == "No More Room in Hell" ]||[ "${gamename}" == "Counter-Strike: Source" ]||[ "${gamename}" == "Garry's Mod" ]; then
  162. if [ "${arch}" == "x86_64" ]; then
  163. array_deps_required+=( lib32tinfo5 )
  164. else
  165. array_deps_required+=( libtinfo5 )
  166. fi
  167. # Brainbread 2 and Don't Starve Together
  168. elif [ "${gamename}" == "Brainbread 2" ]||[ "${gamename}" == "Don't Starve Together" ]; then
  169. array_deps_required+=( libcurl4-gnutls-dev:i386 )
  170. # Battlefield: 1942
  171. elif [ "${gamename}" == "Battlefield: 1942" ]; then
  172. array_deps_required+=( libncurses5:i386 )
  173. # Call of Duty
  174. elif [ "${gamename}" == "Call of Duty" ]||[ "${gamename}" == "Call of Duty 2" ]; then
  175. array_deps_required+=( libstdc++5:i386 )
  176. # Project Zomboid and Minecraft
  177. elif [ "${engine}" == "projectzomboid" ]||[ "${engine}" == "lwjgl2" ]; then
  178. javaversion=$(java -version 2>&1 | grep "version")
  179. if [ -n "${javaversion}" ]; then
  180. javacheck=1 # Added for users using Oracle JRE to bypass the check.
  181. else
  182. array_deps_required+=( default-jre )
  183. fi
  184. # GoldenEye: Source
  185. elif [ "${gamename}" == "GoldenEye: Source" ]; then
  186. array_deps_required+=( zlib1g:i386 libldap-2.4-2:i386 )
  187. # Serious Sam 3: BFE
  188. elif [ "${gamename}" == "Serious Sam 3: BFE" ]; then
  189. array_deps_required+=( libxrandr2:i386 libglu1-mesa:i386 libxtst6:i386 libusb-1.0-0-dev:i386 libxxf86vm1:i386 libopenal1:i386 libssl1.0.0:i386 libgtk2.0-0:i386 libdbus-glib-1-2:i386 libnm-glib-dev:i386 )
  190. # Unreal Engine
  191. elif [ "${executable}" == "./ucc-bin" ]; then
  192. #UT2K4
  193. if [ -f "${executabledir}/ut2004-bin" ]; then
  194. array_deps_required+=( libsdl1.2debian libstdc++5:i386 bzip2 )
  195. #UT99
  196. else
  197. array_deps_required+=( libsdl1.2debian bzip2 )
  198. fi
  199. # Unreal Tournament
  200. elif [ "${gamename}" == "Unreal Tournament" ]; then
  201. array_deps_required+=( unzip )
  202. fi
  203. fn_deps_email
  204. fn_check_loop
  205. elif [ -n "$(command -v yum)" ]; then
  206. # Generate array of missing deps
  207. array_deps_missing=()
  208. # LGSM requirements
  209. if [ "${distroversion}" == "6" ]; then
  210. array_deps_required=( curl wget util-linux-ng python file gzip bzip2 unzip )
  211. else
  212. array_deps_required=( curl wget util-linux python file gzip bzip2 unzip )
  213. fi
  214. # All servers except ts3 require tmux
  215. if [ "${gamename}" != "TeamSpeak 3" ]; then
  216. if [ "$(command -v tmux)" ]||[ "$(which tmux 2>/dev/null)" ]||[ -f "/usr/bin/tmux" ]||[ -f "/bin/tmux" ]; then
  217. tmuxcheck=1 # Added for users compiling tmux from source to bypass check.
  218. else
  219. array_deps_required+=( tmux )
  220. fi
  221. fi
  222. # All servers except ts3,mumble and minecraft servers require glibc.i686 and libstdc++.i686
  223. if [ "${gamename}" != "TeamSpeak 3" ]&&[ "${gamename}" != "Mumble" ]&&[ "${engine}" != "lwjgl2" ]; then
  224. array_deps_required+=( glibc.i686 libstdc++.i686 )
  225. fi
  226. # Game Specific requirements
  227. # Spark
  228. if [ "${engine}" == "spark" ]; then
  229. array_deps_required+=( speex.i686 tbb.i686 )
  230. # 7 Days to Die
  231. elif [ "${gamename}" == "7 Days To Die" ]; then
  232. array_deps_required+=( telnet expect )
  233. # No More Room in Hell, Counter-Strike: Source and Garry's Mod
  234. elif [ "${gamename}" == "No More Room in Hell" ]||[ "${gamename}" == "Counter-Strike: Source" ]||[ "${gamename}" == "Garry's Mod" ]; then
  235. array_deps_required+=( ncurses-libs.i686 )
  236. # Brainbread 2 and Don't Starve Together
  237. elif [ "${gamename}" == "Brainbread 2" ]||[ "${gamename}" == "Don't Starve Together" ]; then
  238. array_deps_required+=( libcurl.i686 )
  239. # Battlefield: 1942
  240. elif [ "${gamename}" == "Battlefield: 1942" ]; then
  241. array_deps_required+=( ncurses-libs.i686 )
  242. # Call of Duty
  243. elif [ "${gamename}" == "Call of Duty" ]||[ "${gamename}" == "Call of Duty 2" ]; then
  244. array_deps_required+=( compat-libstdc++-33.i686 )
  245. # Project Zomboid and Minecraft
  246. elif [ "${engine}" == "projectzomboid" ]||[ "${engine}" == "lwjgl2" ]; then
  247. javaversion=$(java -version 2>&1 | grep "version")
  248. if [ -n "${javaversion}" ]; then
  249. javacheck=1 # Added for users using Oracle JRE to bypass the check.
  250. else
  251. array_deps_required+=( java-1.8.0-openjdk )
  252. fi
  253. # GoldenEye: Source
  254. elif [ "${gamename}" == "GoldenEye: Source" ]; then
  255. array_deps_required+=( zlib.i686 openldap.i686 )
  256. # Unreal Engine
  257. elif [ "${executable}" == "./ucc-bin" ]; then
  258. #UT2K4
  259. if [ -f "${executabledir}/ut2004-bin" ]; then
  260. array_deps_required+=( compat-libstdc++-33.i686 SDL.i686 bzip2 )
  261. #UT99
  262. else
  263. array_deps_required+=( SDL.i686 bzip2 )
  264. fi
  265. # Unreal Tournament
  266. elif [ "${gamename}" == "Unreal Tournament" ]; then
  267. array_deps_required+=( unzip )
  268. fi
  269. fn_deps_email
  270. fn_check_loop
  271. fi