check_deps.sh 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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: ${red}${array_deps_missing[@]}${default}"
  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 -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 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 )
  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 requies ncurses
  171. elif [ "${gamename}" == "Battlefield: 1942" ]; then
  172. array_deps_required+=( libncurses5:i386 )
  173. # Project Zomboid and Minecraft
  174. elif [ "${engine}" == "projectzomboid" ]||[ "${engine}" == "lwjgl2" ]; then
  175. javaversion=$(java -version 2>&1 | grep "version")
  176. if [ -n "${javaversion}" ]; then
  177. javacheck=1 # Added for users using Oracle JRE to bypass the check.
  178. else
  179. array_deps_required+=( default-jre )
  180. fi
  181. # GoldenEye: Source
  182. elif [ "${gamename}" == "GoldenEye: Source" ]; then
  183. array_deps_required+=( zlib1g:i386 )
  184. # Unreal Engine
  185. elif [ "${executable}" == "./ucc-bin" ]; then
  186. #UT2K4
  187. if [ -f "${executabledir}/ut2004-bin" ]; then
  188. array_deps_required+=( libsdl1.2debian libstdc++5:i386 bzip2 )
  189. #UT99
  190. else
  191. array_deps_required+=( libsdl1.2debian bzip2 )
  192. fi
  193. # Unreal Tournament
  194. elif [ "${gamename}" == "Unreal Tournament" ]; then
  195. array_deps_required+=( unzip )
  196. fi
  197. fn_deps_email
  198. fn_check_loop
  199. elif [ -n "$(command -v yum)" ]; then
  200. # Generate array of missing deps
  201. array_deps_missing=()
  202. # LGSM requirements
  203. if [ "${distroversion}" == "6" ]; then
  204. array_deps_required=( curl wget util-linux-ng python file gzip bzip2 )
  205. else
  206. array_deps_required=( curl wget util-linux python file gzip bzip2 )
  207. fi
  208. # All servers except ts3 require tmux
  209. if [ "${gamename}" != "TeamSpeak 3" ]; then
  210. if [ "$(command -v tmux)" ]||[ "$(which tmux 2>/dev/null)" ]||[ -f "/usr/bin/tmux" ]||[ -f "/bin/tmux" ]; then
  211. tmuxcheck=1 # Added for users compiling tmux from source to bypass check.
  212. else
  213. array_deps_required+=( tmux )
  214. fi
  215. fi
  216. # All servers except ts3,mumble and minecraft servers require glibc.i686 and libstdc++.i686
  217. if [ "${gamename}" != "TeamSpeak 3" ]&&[ "${gamename}" != "Mumble" ]&&[ "${engine}" != "lwjgl2" ]; then
  218. array_deps_required+=( glibc.i686 libstdc++.i686 )
  219. fi
  220. # Game Specific requirements
  221. # Spark
  222. if [ "${engine}" == "spark" ]; then
  223. array_deps_required+=( speex.i686 tbb.i686 )
  224. # 7 Days to Die
  225. elif [ "${gamename}" == "7 Days To Die" ]; then
  226. array_deps_required+=( telnet expect )
  227. # No More Room in Hell, Counter-Strike: Source and Garry's Mod
  228. elif [ "${gamename}" == "No More Room in Hell" ]||[ "${gamename}" == "Counter-Strike: Source" ]||[ "${gamename}" == "Garry's Mod" ]; then
  229. array_deps_required+=( ncurses-libs.i686 )
  230. # Brainbread 2 and Don't Starve Together
  231. elif [ "${gamename}" == "Brainbread 2" ]||[ "${gamename}" == "Don't Starve Together" ]; then
  232. array_deps_required+=( libcurl.i686 )
  233. # Project Zomboid and Minecraft
  234. elif [ "${engine}" == "projectzomboid" ]||[ "${engine}" == "lwjgl2" ]; then
  235. javaversion=$(java -version 2>&1 | grep "version")
  236. if [ -n "${javaversion}" ]; then
  237. javacheck=1 # Added for users using Oracle JRE to bypass the check.
  238. else
  239. array_deps_required+=( java-1.8.0-openjdk )
  240. fi
  241. # GoldenEye: Source
  242. elif [ "${gamename}" == "GoldenEye: Source" ]; then
  243. array_deps_required+=( zlib.i686 )
  244. # Unreal Engine
  245. elif [ "${executable}" == "./ucc-bin" ]; then
  246. #UT2K4
  247. if [ -f "${executabledir}/ut2004-bin" ]; then
  248. array_deps_required+=( compat-libstdc++-33.i686 SDL.i686 bzip2 )
  249. #UT99
  250. else
  251. array_deps_required+=( SDL.i686 bzip2 )
  252. fi
  253. # Unreal Tournament
  254. elif [ "${gamename}" == "Unreal Tournament" ]; then
  255. array_deps_required+=( unzip )
  256. fi
  257. fn_deps_email
  258. fn_check_loop
  259. fi