check_deps.sh 6.8 KB

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