check_deps.sh 6.1 KB

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