check_deps.sh 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. #!/bin/bash
  2. # LGSM check_deps.sh function
  3. # Author: Daniel Gibbs
  4. # Website: https://gameservermanagers.com
  5. # Description: Checks that the requires dependencies are installed for LGSM.
  6. local commandnane="CHECK"
  7. local commandaction="Checking"
  8. # Cannot have selfname as breaks the function.
  9. #local selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
  10. fn_deps_detector(){
  11. # Checks if dependency is missing
  12. if [ -n "$(command -v dpkg-query)" ]; then
  13. dpkg-query -W -f='${Status}' ${deptocheck} 2>/dev/null| grep -q -P '^install ok installed$'
  14. depstatus=$?
  15. elif [ -n "$(command -v yum)" ]; then
  16. yum -q list installed ${deptocheck} > /dev/null 2>&1
  17. depstatus=$?
  18. fi
  19. if [ "${depstatus}" == "0" ]; then
  20. missingdep=0
  21. if [ "${selfname}" == "command_install.sh" ]; then
  22. echo -e "${green}${deptocheck}${default}"
  23. sleep 0.5
  24. fi
  25. else
  26. # if missing dependency is found
  27. missingdep=1
  28. if [ "${selfname}" == "command_install.sh" ]; then
  29. echo -e "${red}${deptocheck}${default}"
  30. sleep 0.5
  31. fi
  32. fi
  33. # Missing dependencies are added to array_deps_missing
  34. if [ "${missingdep}" == "1" ]; then
  35. array_deps_missing+=("${deptocheck}")
  36. fi
  37. }
  38. fn_deps_email(){
  39. # Adds postfix to required dependencies if email alert is enabled
  40. if [ "${emailalert}" == "on" ]; then
  41. if [ -f /usr/bin/mailx ]; then
  42. if [ -d /etc/exim4 ]; then
  43. array_deps_required+=( exim4 )
  44. elif [ -d /etc/sendmail ]; then
  45. array_deps_required+=( sendmail )
  46. elif [ -n "$(command -v dpkg-query)" ]; then
  47. array_deps_required+=( mailutils postfix )
  48. elif [ -n "$(command -v yum)" ]; then
  49. array_deps_required+=( mailx postfix )
  50. fi
  51. else
  52. if [ -n "$(command -v dpkg-query)" ]; then
  53. array_deps_required+=( mailutils postfix )
  54. elif [ -n "$(command -v yum)" ]; then
  55. array_deps_required+=( mailx postfix )
  56. fi
  57. fi
  58. fi
  59. }
  60. fn_found_missing_deps(){
  61. if [ "${#array_deps_missing[@]}" != "0" ]; then
  62. fn_print_dots "Checking dependencies"
  63. sleep 2
  64. fn_print_error "Checking dependencies: missing: ${red}${array_deps_missing[@]}${default}"
  65. fn_script_log_error "Checking dependencies: missing: ${red}${array_deps_missing[@]}${default}"
  66. sleep 1
  67. echo -e ""
  68. sudo -n true > /dev/null 2>&1
  69. if [ $? -eq 0 ]; then
  70. fn_print_info_nl "Attempting to install missing dependencies automatically"
  71. echo -en ".\r"
  72. sleep 1
  73. echo -en "..\r"
  74. sleep 1
  75. echo -en "...\r"
  76. sleep 1
  77. echo -en " \r"
  78. if [ -n "$(command -v dpkg-query)" ]; then
  79. cmd="sudo dpkg --add-architecture i386; sudo apt-get -y install ${array_deps_missing[@]}"
  80. eval $cmd
  81. elif [ -n "$(command -v yum)" ]; then
  82. cmd="sudo yum -y install ${array_deps_missing[@]}"
  83. eval $cmd
  84. fi
  85. else
  86. echo ""
  87. fn_print_infomation_nl "$(whoami) does not have sudo access. Please manually install dependencies"
  88. fn_script_log_info "$(whoami) does not have sudo access. Please manually install dependencies"
  89. echo ""
  90. if [ -n "$(command -v dpkg-query)" ]; then
  91. echo "sudo dpkg --add-architecture i386; sudo apt-get install ${array_deps_missing[@]}"
  92. elif [ -n "$(command -v yum)" ]; then
  93. echo "sudo yum install ${array_deps_missing[@]}"
  94. fi
  95. echo ""
  96. fi
  97. if [ "${selfname}" == "command_install.sh" ]; then
  98. sleep 5
  99. fi
  100. fi
  101. }
  102. fn_check_loop(){
  103. # Loop though required depenencies
  104. for deptocheck in "${array_deps_required[@]}"
  105. do
  106. fn_deps_detector
  107. done
  108. # user to be informaed of any missing dependecies
  109. fn_found_missing_deps
  110. }
  111. info_distro.sh
  112. if [ "${selfname}" == "command_install.sh" ]; then
  113. echo ""
  114. echo "Checking Dependecies"
  115. echo "================================="
  116. fi
  117. # Check will only run if using apt-get or yum
  118. if [ -n "$(command -v dpkg-query)" ]; then
  119. # Generate array of missing deps
  120. array_deps_missing=()
  121. # LGSM requirement for curl
  122. array_deps_required=( curl ca-certificates file bsdmainutils python )
  123. # All servers except ts3 require tmux
  124. if [ "${executable}" != "./ts3server_startscript.sh" ]; then
  125. array_deps_required+=( tmux )
  126. fi
  127. # All servers except ts3 & mumble require libstdc++6, lib32gcc1
  128. if [ "${executable}" != "./ts3server_startscript.sh" ]||[ "${executable}" != "./murmur.x86" ]; then
  129. if [ "${arch}" == "x86_64" ]; then
  130. array_deps_required+=( lib32gcc1 libstdc++6:i386 )
  131. else
  132. array_deps_required+=( libstdc++6:i386 )
  133. fi
  134. fi
  135. # Game Specific requirements
  136. # Spark
  137. if [ "${engine}" == "spark" ]; then
  138. array_deps_required+=( speex:i386 libtbb2 )
  139. # 7 Days to Die
  140. elif [ "${gamename}" == "7 Days To Die" ]; then
  141. array_deps_required+=( telnet expect )
  142. # No More Room in Hell
  143. elif [ "${gamename}" == "No More Room in Hell" ]; then
  144. array_deps_required+=( lib32tinfo5 )
  145. # Brainbread 2 and Don't Starve Together
  146. elif [ "${gamename}" == "Brainbread 2" ]||[ "${gamename}" == "Don't Starve Together" ]; then
  147. array_deps_required+=( libcurl4-gnutls-dev:i386 )
  148. elif [ "${engine}" == "projectzomboid" ]; then
  149. array_deps_required+=( openjdk-7-jre )
  150. # Unreal engine
  151. elif [ "${executable}" == "./ucc-bin" ]; then
  152. #UT2K4
  153. if [ -f "${executabledir}/ut2004-bin" ]; then
  154. array_deps_required+=( libsdl1.2debian libstdc++5:i386 bzip2 )
  155. #UT99
  156. else
  157. array_deps_required+=( libsdl1.2debian bzip2 )
  158. fi
  159. fi
  160. fn_deps_email
  161. fn_check_loop
  162. elif [ -n "$(command -v yum)" ]; then
  163. # Generate array of missing deps
  164. array_deps_missing=()
  165. # LGSM requirement for curl
  166. array_deps_required=( curl util-linux python file )
  167. # All servers except ts3 require tmux
  168. if [ "${executable}" != "./ts3server_startscript.sh" ]; then
  169. array_deps_required+=( tmux )
  170. fi
  171. # All servers excelts ts3 & mumble require glibc.i686 libstdc++.i686
  172. if [ "${executable}" != "./ts3server_startscript.sh" ]||[ "${executable}" != "./murmur.x86" ]; then
  173. array_deps_required+=( glibc.i686 libstdc++.i686 )
  174. fi
  175. # Game Specific requirements
  176. # Spark
  177. if [ "${engine}" == "spark" ]; then
  178. array_deps_required+=( speex.i686 tbb.i686 )
  179. # 7 Days to Die
  180. elif [ "${gamename}" == "7 Days To Die" ]; then
  181. array_deps_required+=( telnet expect )
  182. # No More Room in Hell
  183. elif [ "${gamename}" == "No More Room in Hell" ]; then
  184. array_deps_required+=( ncurses-libs.i686 )
  185. # Brainbread 2 and Don't Starve Together
  186. elif [ "${gamename}" == "Brainbread 2" ]||[ "${gamename}" == "Don't Starve Together" ]; then
  187. array_deps_required+=( libcurl.i686 )
  188. elif [ "${engine}" == "projectzomboid" ]; then
  189. array_deps_required+=( java-1.7.0-openjdk )
  190. # Unreal engine
  191. elif [ "${executable}" == "./ucc-bin" ]; then
  192. #UT2K4
  193. if [ -f "${executabledir}/ut2004-bin" ]; then
  194. array_deps_required+=( compat-libstdc++-33.i686 SDL.i686 bzip2 )
  195. #UT99
  196. else
  197. array_deps_required+=( SDL.i686 bzip2 )
  198. fi
  199. fi
  200. fn_deps_email
  201. fn_check_loop
  202. fi