check_deps.sh 5.9 KB

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