check_deps.sh 6.5 KB

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