check_deps.sh 7.7 KB

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