check_deps.sh 6.4 KB

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