check_deps.sh 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. #!/bin/bash
  2. # LGSM check_deps.sh function
  3. # Author: Daniel Gibbs
  4. # Website: http://gameservermanagers.com
  5. lgsm_version="310116"
  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 excelts ts3 & mumble require libstdc++6,lib32gcc1
  108. if [ "${executable}" != "./ts3server_startscript.sh" ]||[ "${executable}" != "./murmur.x86" ]; then
  109. array_deps_required+=( lib32gcc1 libstdc++6:i386 )
  110. fi
  111. # Game Specific requirements
  112. # Spark
  113. if [ "${engine}" == "spark" ]; then
  114. array_deps_required+=( speex:i386 libtbb2 )
  115. # 7 Days to Die
  116. elif [ "${executable}" == "./7DaysToDie.sh" ]; then
  117. array_deps_required+=( telnet expect )
  118. # No More Room in Hell
  119. elif [ "${gamename}" == "No More Room in Hell" ]; then
  120. array_deps_required+=( lib32tinfo5 )
  121. # Brainbread 2 and Don't Starve Together
  122. elif [ "${gamename}" == "Brainbread 2" ]||[ "${gamename}" == "Don't Starve Together" ]; then
  123. array_deps_required+=( libcurl4-gnutls-dev:i386 )
  124. elif [ "${engine}" == "projectzomboid" ]; then
  125. array_deps_required+=( openjdk-7-jre )
  126. # Unreal engine
  127. elif [ "${executable}" == "./ucc-bin" ]; then
  128. #UT2K4
  129. if [ -f "${executabledir}/ut2004-bin" ]; then
  130. array_deps_required+=( libsdl1.2debian libstdc++5:i386 bzip2 unzip )
  131. #UT99
  132. else
  133. array_deps_required+=( libsdl1.2debian bzip2 )
  134. fi
  135. fi
  136. fn_deps_email
  137. fn_check_loop
  138. elif [ -n "$(command -v yum)" ]; then
  139. # Generate array of missing deps
  140. array_deps_missing=()
  141. # LGSM requirement for curl
  142. array_deps_required=( curl )
  143. # All servers except ts3 require tmux
  144. if [ "${executable}" != "./ts3server_startscript.sh" ]; then
  145. array_deps_required+=( tmux )
  146. fi
  147. # All servers excelts ts3 & mumble require libstdc++6,lib32gcc1
  148. if [ "${executable}" != "./ts3server_startscript.sh" ]||[ "${executable}" != "./murmur.x86" ]; then
  149. array_deps_required+=( glibc.i686 libstdc++.i686 )
  150. fi
  151. # Game Specific requirements
  152. # Spark
  153. if [ "${engine}" == "spark" ]; then
  154. array_deps_required+=( speex.i686 tbb.i686 )
  155. # 7 Days to Die
  156. elif [ "${executable}" == "./7DaysToDie.sh" ]; then
  157. array_deps_required+=( telnet expect )
  158. # No More Room in Hell
  159. elif [ "${gamename}" == "No More Room in Hell" ]; then
  160. array_deps_required+=( ncurses-libs.i686 )
  161. # Brainbread 2 and Don't Starve Together
  162. elif [ "${gamename}" == "Brainbread 2" ]||[ "${gamename}" == "Don't Starve Together" ]; then
  163. array_deps_required+=( libcurl.i686 )
  164. elif [ "${engine}" == "projectzomboid" ]; then
  165. array_deps_required+=( java-1.7.0-openjdk )
  166. # Unreal engine
  167. elif [ "${executable}" == "./ucc-bin" ]; then
  168. #UT2K4
  169. if [ -f "${executabledir}/ut2004-bin" ]; then
  170. array_deps_required+=( compat-libstdc++-33.i686 SDL.i686 bzip2 unzip )
  171. #UT99
  172. else
  173. array_deps_required+=( SDL.i686 bzip2 )
  174. fi
  175. fi
  176. fn_deps_email
  177. fn_check_loop
  178. fi