check_deps.sh 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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 2
  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. echo -e ""
  67. sudo -n true > /dev/null 2>&1
  68. if [ $? -eq 0 ]; then
  69. fn_print_infomation_nl "Attempting to install missing dependencies automatically"
  70. fn_script_log_info "Attempting to install missing dependencies automatically"
  71. echo -en ".\r"
  72. sleep 1
  73. echo -en "..\r"
  74. sleep 1
  75. echo -en "...\r"
  76. sleep 1
  77. echo -en " \r"
  78. if [ -n "$(command -v dpkg-query)" ]; then
  79. cmd="sudo dpkg --add-architecture i386; sudo apt-get -y install ${array_deps_missing[@]}"
  80. eval ${cmd}
  81. elif [ -n "$(command -v yum)" ]; then
  82. cmd="sudo yum -y install ${array_deps_missing[@]}"
  83. eval ${cmd}
  84. fi
  85. if [ $? != 0 ]; then
  86. fn_print_failure_nl "Unable to install dependencies"
  87. fn_script_log_fail "Unable to install dependencies"
  88. else
  89. fn_print_success_nl "install dependencies completed"
  90. fn_script_log_pass "install dependencies completed"
  91. fi
  92. else
  93. echo ""
  94. fn_print_warning_nl "$(whoami) does not have sudo access. Please manually install dependencies"
  95. fn_script_log_warn "$(whoami) does not have sudo access. Please manually install dependencies"
  96. echo ""
  97. if [ -n "$(command -v dpkg-query)" ]; then
  98. echo "sudo dpkg --add-architecture i386; sudo apt-get install ${array_deps_missing[@]}"
  99. elif [ -n "$(command -v yum)" ]; then
  100. echo "sudo yum install ${array_deps_missing[@]}"
  101. fi
  102. echo ""
  103. fi
  104. if [ "${selfname}" == "command_install.sh" ]; then
  105. sleep 5
  106. fi
  107. fi
  108. }
  109. fn_check_loop(){
  110. # Loop though required depenencies
  111. for deptocheck in "${array_deps_required[@]}"
  112. do
  113. fn_deps_detector
  114. done
  115. # user to be informaed of any missing dependecies
  116. fn_found_missing_deps
  117. }
  118. info_distro.sh
  119. if [ "${selfname}" == "command_install.sh" ]; then
  120. echo ""
  121. echo "Checking Dependecies"
  122. echo "================================="
  123. fi
  124. # Check will only run if using apt-get or yum
  125. if [ -n "$(command -v dpkg-query)" ]; then
  126. # Generate array of missing deps
  127. array_deps_missing=()
  128. # LGSM requirement for curl
  129. array_deps_required=( curl ca-certificates file bsdmainutils python )
  130. # All servers except ts3 require tmux
  131. if [ "${executable}" != "./ts3server_startscript.sh" ]; then
  132. array_deps_required+=( tmux )
  133. fi
  134. # All servers except ts3 & mumble require libstdc++6, lib32gcc1
  135. if [ "${executable}" != "./ts3server_startscript.sh" ]||[ "${executable}" != "./murmur.x86" ]; then
  136. if [ "${arch}" == "x86_64" ]; then
  137. array_deps_required+=( lib32gcc1 libstdc++6:i386 )
  138. else
  139. array_deps_required+=( libstdc++6:i386 )
  140. fi
  141. fi
  142. # Game Specific requirements
  143. # Spark
  144. if [ "${engine}" == "spark" ]; then
  145. array_deps_required+=( speex:i386 libtbb2 )
  146. # 7 Days to Die
  147. elif [ "${gamename}" == "7 Days To Die" ]; then
  148. array_deps_required+=( telnet expect )
  149. # No More Room in Hell
  150. elif [ "${gamename}" == "No More Room in Hell" ]; then
  151. array_deps_required+=( lib32tinfo5 )
  152. # Brainbread 2 and Don't Starve Together
  153. elif [ "${gamename}" == "Brainbread 2" ]||[ "${gamename}" == "Don't Starve Together" ]; then
  154. array_deps_required+=( libcurl4-gnutls-dev:i386 )
  155. elif [ "${engine}" == "projectzomboid" ]; then
  156. array_deps_required+=( openjdk-7-jre )
  157. # Unreal engine
  158. elif [ "${executable}" == "./ucc-bin" ]; then
  159. #UT2K4
  160. if [ -f "${executabledir}/ut2004-bin" ]; then
  161. array_deps_required+=( libsdl1.2debian libstdc++5:i386 bzip2 )
  162. #UT99
  163. else
  164. array_deps_required+=( libsdl1.2debian bzip2 )
  165. fi
  166. fi
  167. fn_deps_email
  168. fn_check_loop
  169. elif [ -n "$(command -v yum)" ]; then
  170. # Generate array of missing deps
  171. array_deps_missing=()
  172. # LGSM requirement for curl
  173. array_deps_required=( curl util-linux python file )
  174. # All servers except ts3 require tmux
  175. if [ "${executable}" != "./ts3server_startscript.sh" ]; then
  176. array_deps_required+=( tmux )
  177. fi
  178. # All servers excelts ts3 & mumble require glibc.i686 libstdc++.i686
  179. if [ "${executable}" != "./ts3server_startscript.sh" ]||[ "${executable}" != "./murmur.x86" ]; then
  180. array_deps_required+=( glibc.i686 libstdc++.i686 )
  181. fi
  182. # Game Specific requirements
  183. # Spark
  184. if [ "${engine}" == "spark" ]; then
  185. array_deps_required+=( speex.i686 tbb.i686 )
  186. # 7 Days to Die
  187. elif [ "${gamename}" == "7 Days To Die" ]; then
  188. array_deps_required+=( telnet expect )
  189. # No More Room in Hell
  190. elif [ "${gamename}" == "No More Room in Hell" ]; then
  191. array_deps_required+=( ncurses-libs.i686 )
  192. # Brainbread 2 and Don't Starve Together
  193. elif [ "${gamename}" == "Brainbread 2" ]||[ "${gamename}" == "Don't Starve Together" ]; then
  194. array_deps_required+=( libcurl.i686 )
  195. elif [ "${engine}" == "projectzomboid" ]; then
  196. array_deps_required+=( java-1.7.0-openjdk )
  197. # Unreal engine
  198. elif [ "${executable}" == "./ucc-bin" ]; then
  199. #UT2K4
  200. if [ -f "${executabledir}/ut2004-bin" ]; then
  201. array_deps_required+=( compat-libstdc++-33.i686 SDL.i686 bzip2 )
  202. #UT99
  203. else
  204. array_deps_required+=( SDL.i686 bzip2 )
  205. fi
  206. fi
  207. fn_deps_email
  208. fn_check_loop
  209. fi