check_deps.sh 6.3 KB

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