check_deps.sh 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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 require dependencies are installed for LGSM
  7. fn_deps_detector(){
  8. # Checks is 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. else
  19. # if missing dependency is flagged
  20. missingdep=1
  21. fi
  22. # Add missing dependencies are added to array_deps_missing array
  23. if [ "${missingdep}" == "1" ]; then
  24. array_deps_missing+=("${deptocheck}")
  25. fi
  26. }
  27. fn_deps_email(){
  28. # Adds postfix to required dependencies if email notification is enabled
  29. if [ "${emailnotification}" == "on" ]; then
  30. if [ -n "$(command -v dpkg-query)" ]; then
  31. array_deps_required+=( mailutils postfix )
  32. elif [ -n "$(command -v yum)" ]; then
  33. array_deps_required+=( mailx postfix )
  34. fi
  35. fi
  36. }
  37. fn_found_missing_deps(){
  38. if [ "${#array_deps_missing[@]}" != "0" ]; then
  39. fn_printdots "Checking dependencies"
  40. sleep 2
  41. fn_printwarn "Checking dependencies: Dependency missing: \e[0;31m${array_deps_missing[@]}\e[0m"
  42. sleep 1
  43. echo -e ""
  44. sudo -n true > /dev/null 2>&1
  45. if [ $? -eq 0 ]; then
  46. fn_printinfonl "Attempting to install missing dependencies automatically"
  47. echo -en ".\r"
  48. sleep 1
  49. echo -en "..\r"
  50. sleep 1
  51. echo -en "...\r"
  52. sleep 1
  53. echo -en " \r"
  54. if [ -n "$(command -v dpkg-query)" ]; then
  55. echo "sudo apt-get install ${array_deps_missing[@]}"
  56. elif [ -n "$(command -v yum)" ]; then
  57. echo "yum install ${array_deps_missing[@]}"
  58. fi
  59. else
  60. echo ""
  61. fn_printinfomationnl "$(whoami) does not have sudo access. manually install dependencies"
  62. echo ""
  63. if [ -n "$(command -v dpkg-query)" ]; then
  64. echo "sudo apt-get install ${array_deps_missing[@]}"
  65. elif [ -n "$(command -v yum)" ]; then
  66. echo "yum install ${array_deps_missing[@]}"
  67. fi
  68. echo ""
  69. fi
  70. fi
  71. }
  72. fn_check_loop(){
  73. # Loop though required depenencies
  74. for deptocheck in "${array_deps_required[@]}"
  75. do
  76. fn_deps_detector
  77. done
  78. # user to be informaed of any missing dependecies
  79. fn_found_missing_deps
  80. }
  81. # Check will only run if using apt-get or yum
  82. if [ -n "$(command -v dpkg-query)" ]; then
  83. # Generate array of missing deps
  84. array_deps_missing=()
  85. # LGSM requirement for curl
  86. array_deps_required=( curl ca-certificates )
  87. # All servers except ts3 require tmux
  88. if [ "${executable}" != "./ts3server_startscript.sh" ]; then
  89. array_deps_required+=( tmux )
  90. fi
  91. # All servers excelts ts3 & mumble require libstdc++6,lib32gcc1
  92. if [ "${executable}" != "./ts3server_startscript.sh" ]||[ "${executable}" != "./murmur.x86" ]; then
  93. array_deps_required+=( lib32gcc1 libstdc++6:i386 )
  94. fi
  95. # Game Specific requirements
  96. # Spark
  97. if [ "${engine}" == "spark" ]; then
  98. array_deps_required+=( speex:i386 libtbb2 )
  99. # 7 Days to Die
  100. elif [ "${executable}" == "./7DaysToDie.sh" ]; then
  101. array_deps_required+=( telnet expect )
  102. # No More Room in Hell
  103. elif [ "${gamename}" == "No More Room in Hell" ]; then
  104. array_deps_required+=( lib32tinfo5 )
  105. # Brainbread 2 and Don't Starve Together
  106. elif [ "${gamename}" == "Brainbread 2" ]||[ "${gamename}" == "Don't Starve Together" ]; then
  107. array_deps_required+=( libcurl4-gnutls-dev:i386 )
  108. elif [ "${engine}" == "projectzomboid" ]; then
  109. array_deps_required+=( openjdk-7-jre )
  110. # Unreal engine
  111. elif [ "${executable}" == "./ucc-bin" ]; then
  112. #UT2K4
  113. if [ -f "${executabledir}/ut2004-bin" ]; then
  114. array_deps_required+=( libsdl1.2debian libstdc++5:i386 bzip2 unzip )
  115. #UT99
  116. else
  117. array_deps_required+=( libsdl1.2debian bzip2 )
  118. fi
  119. fi
  120. fn_deps_email
  121. fn_check_loop
  122. elif [ -n "$(command -v yum)" ]; then
  123. # Generate array of missing deps
  124. array_deps_missing=()
  125. # LGSM requirement for curl
  126. array_deps_required=( curl )
  127. # All servers except ts3 require tmux
  128. if [ "${executable}" != "./ts3server_startscript.sh" ]; then
  129. array_deps_required+=( tmux )
  130. fi
  131. # All servers excelts ts3 & mumble require libstdc++6,lib32gcc1
  132. if [ "${executable}" != "./ts3server_startscript.sh" ]||[ "${executable}" != "./murmur.x86" ]; then
  133. array_deps_required+=( glibc.i686 libstdc++.i686 )
  134. fi
  135. # Game Specific requirements
  136. # Spark
  137. if [ "${engine}" == "spark" ]; then
  138. array_deps_required+=( speex.i686 tbb.i686 )
  139. # 7 Days to Die
  140. elif [ "${executable}" == "./7DaysToDie.sh" ]; 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+=( ncurses-libs.i686 )
  145. # Brainbread 2 and Don't Starve Together
  146. elif [ "${gamename}" == "Brainbread 2" ]||[ "${gamename}" == "Don't Starve Together" ]; then
  147. array_deps_required+=( libcurl.i686 )
  148. elif [ "${engine}" == "projectzomboid" ]; then
  149. array_deps_required+=( java-1.7.0-openjdk )
  150. # Unreal engine
  151. elif [ "${executable}" == "./ucc-bin" ]; then
  152. #UT2K4
  153. if [ -f "${executabledir}/ut2004-bin" ]; then
  154. array_deps_required+=( compat-libstdc++-33.i686 SDL.i686 bzip2 unzip )
  155. #UT99
  156. else
  157. array_deps_required+=( SDL.i686 bzip2 )
  158. fi
  159. fi
  160. fn_deps_email
  161. fn_check_loop
  162. fi