check_deps.sh 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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_infomation_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 informaed of any missing dependecies
  117. fn_found_missing_deps
  118. }
  119. info_distro.sh
  120. if [ "${function_selfname}" == "command_install.sh" ]; then
  121. echo ""
  122. echo "Checking Dependecies"
  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 require libstdc++6, lib32gcc1
  140. if [ "${gamename}" != "TeamSpeak 3" ]||[ "${gamename}" != "Mumble" ]; 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. # Project Zomboid
  165. elif [ "${engine}" == "projectzomboid" ]; then
  166. array_deps_required+=( default-jdk )
  167. # Unreal engine
  168. elif [ "${executable}" == "./ucc-bin" ]; then
  169. #UT2K4
  170. if [ -f "${executabledir}/ut2004-bin" ]; then
  171. array_deps_required+=( libsdl1.2debian libstdc++5:i386 bzip2 )
  172. #UT99
  173. else
  174. array_deps_required+=( libsdl1.2debian bzip2 )
  175. fi
  176. # Unreal Tournament
  177. elif [ "${gamename}" == "Unreal Tournament" ]; then
  178. array_deps_required+=( unzip )
  179. fi
  180. fn_deps_email
  181. fn_check_loop
  182. elif [ -n "$(command -v yum)" ]; then
  183. # Generate array of missing deps
  184. array_deps_missing=()
  185. # LGSM requirements
  186. if [ "${distroversion}" == "6" ]; then
  187. array_deps_required=( curl wget util-linux-ng python file gzip bzip2 )
  188. else
  189. array_deps_required=( curl wget util-linux python file gzip bzip2 )
  190. fi
  191. # All servers except ts3 require tmux
  192. if [ "${executable}" != "./ts3server_startscript.sh" ]; then
  193. if [ "$(command -v tmux)" ]||[ "$(which tmux 2>/dev/null)" ]||[ -f "/usr/bin/tmux" ]||[ -f "/bin/tmux" ]; then
  194. tmuxcheck=1 # Added for users compiling tmux from source to bypass rpm check
  195. else
  196. array_deps_required+=( tmux )
  197. fi
  198. fi
  199. # All servers excelts ts3 & mumble require glibc.i686 libstdc++.i686
  200. if [ "${executable}" != "./ts3server_startscript.sh" ]||[ "${executable}" != "./murmur.x86" ]; then
  201. array_deps_required+=( glibc.i686 libstdc++.i686 )
  202. fi
  203. # Game Specific requirements
  204. # Spark
  205. if [ "${engine}" == "spark" ]; then
  206. array_deps_required+=( speex.i686 tbb.i686 )
  207. # 7 Days to Die
  208. elif [ "${gamename}" == "7 Days To Die" ]; then
  209. array_deps_required+=( telnet expect )
  210. # No More Room in Hell, Counter Strike: Source and Garry's Mod
  211. elif [ "${gamename}" == "No More Room in Hell" ]||[ "${gamename}" == "Counter Strike: Source" ]||[ "${gamename}" == "Garry's Mod" ]; then
  212. array_deps_required+=( ncurses-libs.i686 )
  213. # Brainbread 2 and Don't Starve Together
  214. elif [ "${gamename}" == "Brainbread 2" ]||[ "${gamename}" == "Don't Starve Together" ]; then
  215. array_deps_required+=( libcurl.i686 )
  216. # Project Zomboid
  217. elif [ "${engine}" == "projectzomboid" ]; then
  218. array_deps_required+=( java-1.8.0-openjdk )
  219. # Unreal Engine
  220. elif [ "${executable}" == "./ucc-bin" ]; then
  221. #UT2K4
  222. if [ -f "${executabledir}/ut2004-bin" ]; then
  223. array_deps_required+=( compat-libstdc++-33.i686 SDL.i686 bzip2 )
  224. #UT99
  225. else
  226. array_deps_required+=( SDL.i686 bzip2 )
  227. fi
  228. # Unreal Tournament
  229. elif [ "${gamename}" == "Unreal Tournament" ]; then
  230. array_deps_required+=( unzip )
  231. fi
  232. fn_deps_email
  233. fn_check_loop
  234. fi