check_deps.sh 8.5 KB

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