check_deps.sh 5.7 KB

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