check_deps.sh 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. #!/bin/bash
  2. # LGSM check_deps.sh function
  3. # Author: Daniel Gibbs
  4. # Website: https://gameservermanagers.com
  5. # Description: Checks that the requires 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. echo -e "${green}${deptocheck}${default}"
  20. sleep 0.5
  21. fi
  22. else
  23. # if missing dependency is found
  24. missingdep=1
  25. if [ "${function_selfname}" == "command_install.sh" ]; then
  26. echo -e "${red}${deptocheck}${default}"
  27. sleep 0.5
  28. fi
  29. fi
  30. # Missing dependencies are added to array_deps_missing
  31. if [ "${missingdep}" == "1" ]; then
  32. array_deps_missing+=("${deptocheck}")
  33. fi
  34. }
  35. fn_deps_email(){
  36. # Adds postfix to required dependencies if email alert is enabled
  37. if [ "${emailalert}" == "on" ]; then
  38. if [ -f /usr/bin/mailx ]; then
  39. if [ -d /etc/exim4 ]; then
  40. array_deps_required+=( exim4 )
  41. elif [ -d /etc/sendmail ]; then
  42. array_deps_required+=( sendmail )
  43. elif [ -n "$(command -v dpkg-query)" ]; then
  44. array_deps_required+=( mailutils postfix )
  45. elif [ -n "$(command -v yum)" ]; then
  46. array_deps_required+=( mailx postfix )
  47. fi
  48. else
  49. if [ -n "$(command -v dpkg-query)" ]; then
  50. array_deps_required+=( mailutils postfix )
  51. elif [ -n "$(command -v yum)" ]; then
  52. array_deps_required+=( mailx postfix )
  53. fi
  54. fi
  55. fi
  56. }
  57. fn_found_missing_deps(){
  58. if [ "${#array_deps_missing[@]}" != "0" ]; then
  59. fn_print_dots "Checking dependencies"
  60. sleep 0.5
  61. fn_print_error "Checking dependencies: missing: ${red}${array_deps_missing[@]}${default}"
  62. fn_script_log_error "Checking dependencies: missing: ${red}${array_deps_missing[@]}${default}"
  63. sleep 1
  64. sudo -v > /dev/null 2>&1
  65. if [ $? -eq 0 ]; then
  66. fn_print_infomation_nl "Automatically installing missing dependencies."
  67. fn_script_log_info "Automatically installing missing dependencies."
  68. echo -en ".\r"
  69. sleep 1
  70. echo -en "..\r"
  71. sleep 1
  72. echo -en "...\r"
  73. sleep 1
  74. echo -en " \r"
  75. if [ -n "$(command -v dpkg-query)" ]; then
  76. cmd="sudo dpkg --add-architecture i386; sudo apt-get -y install ${array_deps_missing[@]}"
  77. eval ${cmd}
  78. elif [ -n "$(command -v yum)" ]; then
  79. cmd="sudo yum -y install ${array_deps_missing[@]}"
  80. eval ${cmd}
  81. fi
  82. if [ $? != 0 ]; then
  83. fn_print_failure_nl "Unable to install dependencies"
  84. fn_script_log_fail "Unable to install dependencies"
  85. else
  86. fn_print_complete_nl "Install dependencies completed"
  87. fn_script_log_pass "Install dependencies completed"
  88. fi
  89. else
  90. echo ""
  91. fn_print_warning_nl "$(whoami) does not have sudo access. Manually install dependencies."
  92. fn_script_log_warn "$(whoami) does not have sudo access. Manually install dependencies."
  93. if [ -n "$(command -v dpkg-query)" ]; then
  94. echo " sudo dpkg --add-architecture i386; sudo apt-get install ${array_deps_missing[@]}"
  95. elif [ -n "$(command -v yum)" ]; then
  96. echo " sudo yum install ${array_deps_missing[@]}"
  97. fi
  98. echo ""
  99. fi
  100. if [ "${function_selfname}" == "command_install.sh" ]; then
  101. sleep 5
  102. fi
  103. fi
  104. }
  105. fn_check_loop(){
  106. # Loop though required depenencies
  107. for deptocheck in "${array_deps_required[@]}"
  108. do
  109. fn_deps_detector
  110. done
  111. # user to be informaed of any missing dependecies
  112. fn_found_missing_deps
  113. }
  114. info_distro.sh
  115. if [ "${function_selfname}" == "command_install.sh" ]; then
  116. echo ""
  117. echo "Checking Dependecies"
  118. echo "================================="
  119. fi
  120. # Check will only run if using apt-get or yum
  121. if [ -n "$(command -v dpkg-query)" ]; then
  122. # Generate array of missing deps
  123. array_deps_missing=()
  124. # LGSM requirements
  125. array_deps_required=( curl ca-certificates file bsdmainutils util-linux python )
  126. # All servers except ts3 require tmux
  127. if [ "${executable}" != "./ts3server_startscript.sh" ]; then
  128. array_deps_required+=( tmux )
  129. fi
  130. # All servers except ts3 & mumble require libstdc++6, lib32gcc1
  131. if [ "${executable}" != "./ts3server_startscript.sh" ]||[ "${executable}" != "./murmur.x86" ]; then
  132. if [ "${arch}" == "x86_64" ]; then
  133. array_deps_required+=( lib32gcc1 libstdc++6:i386 )
  134. else
  135. array_deps_required+=( libstdc++6:i386 )
  136. fi
  137. fi
  138. # Game Specific requirements
  139. # Spark
  140. if [ "${engine}" == "spark" ]; then
  141. array_deps_required+=( speex:i386 libtbb2 )
  142. # 7 Days to Die
  143. elif [ "${gamename}" == "7 Days To Die" ]; then
  144. array_deps_required+=( telnet expect )
  145. # No More Room in Hell
  146. elif [ "${gamename}" == "No More Room in Hell" ]; then
  147. array_deps_required+=( lib32tinfo5 )
  148. # Brainbread 2 and Don't Starve Together
  149. elif [ "${gamename}" == "Brainbread 2" ]||[ "${gamename}" == "Don't Starve Together" ]; then
  150. array_deps_required+=( libcurl4-gnutls-dev:i386 )
  151. elif [ "${engine}" == "projectzomboid" ]; then
  152. array_deps_required+=( openjdk-7-jre )
  153. # Unreal engine
  154. elif [ "${executable}" == "./ucc-bin" ]; then
  155. #UT2K4
  156. if [ -f "${executabledir}/ut2004-bin" ]; then
  157. array_deps_required+=( libsdl1.2debian libstdc++5:i386 bzip2 )
  158. #UT99
  159. else
  160. array_deps_required+=( libsdl1.2debian bzip2 )
  161. fi
  162. fi
  163. fn_deps_email
  164. fn_check_loop
  165. elif [ -n "$(command -v yum)" ]; then
  166. # Generate array of missing deps
  167. array_deps_missing=()
  168. # LGSM requirements
  169. array_deps_required=( curl util-linux python file )
  170. # All servers except ts3 require tmux
  171. if [ "${executable}" != "./ts3server_startscript.sh" ]; then
  172. array_deps_required+=( tmux )
  173. fi
  174. # All servers excelts ts3 & mumble require glibc.i686 libstdc++.i686
  175. if [ "${executable}" != "./ts3server_startscript.sh" ]||[ "${executable}" != "./murmur.x86" ]; then
  176. array_deps_required+=( glibc.i686 libstdc++.i686 )
  177. fi
  178. # Game Specific requirements
  179. # Spark
  180. if [ "${engine}" == "spark" ]; then
  181. array_deps_required+=( speex.i686 tbb.i686 )
  182. # 7 Days to Die
  183. elif [ "${gamename}" == "7 Days To Die" ]; then
  184. array_deps_required+=( telnet expect )
  185. # No More Room in Hell
  186. elif [ "${gamename}" == "No More Room in Hell" ]; then
  187. array_deps_required+=( ncurses-libs.i686 )
  188. # Brainbread 2 and Don't Starve Together
  189. elif [ "${gamename}" == "Brainbread 2" ]||[ "${gamename}" == "Don't Starve Together" ]; then
  190. array_deps_required+=( libcurl.i686 )
  191. elif [ "${engine}" == "projectzomboid" ]; then
  192. array_deps_required+=( java-1.7.0-openjdk )
  193. # Unreal engine
  194. elif [ "${executable}" == "./ucc-bin" ]; then
  195. #UT2K4
  196. if [ -f "${executabledir}/ut2004-bin" ]; then
  197. array_deps_required+=( compat-libstdc++-33.i686 SDL.i686 bzip2 )
  198. #UT99
  199. else
  200. array_deps_required+=( SDL.i686 bzip2 )
  201. fi
  202. fi
  203. fn_deps_email
  204. fn_check_loop
  205. fi