check_deps.sh 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. #!/bin/bash
  2. # LinuxGSM check_deps.sh function
  3. # Author: Daniel Gibbs
  4. # Website: https://linuxgsm.com
  5. # Description: Checks if required dependencies are installed for LinuxGSM.
  6. local commandname="CHECK"
  7. fn_deps_detector(){
  8. # Checks if dependency is missing
  9. if [ "${tmuxcheck}" == "1" ]; then
  10. # Added for users compiling tmux from source to bypass check.
  11. depstatus=0
  12. deptocheck="tmux"
  13. unset tmuxcheck
  14. elif [ "${javacheck}" == "1" ]; then
  15. # Added for users using Oracle JRE to bypass check.
  16. depstatus=0
  17. deptocheck="${javaversion}"
  18. unset javacheck
  19. elif [ -n "$(command -v apt 2>/dev/null)" ]; then
  20. dpkg-query -W -f='${Status}' "${deptocheck}" 2>/dev/null | grep -q -P '^install ok installed'
  21. depstatus=$?
  22. elif [ -n "$(command -v yum 2>/dev/null)" ]; then
  23. yum -q list installed "${deptocheck}" > /dev/null 2>&1
  24. depstatus=$?
  25. fi
  26. if [ "${depstatus}" == "0" ]; then
  27. # if dependency is found
  28. missingdep=0
  29. if [ "${function_selfname}" == "command_install.sh" ]; then
  30. echo -e "${green}${deptocheck}${default}"
  31. sleep 0.5
  32. fi
  33. else
  34. # if dependency is not found
  35. missingdep=1
  36. if [ "${function_selfname}" == "command_install.sh" ]; then
  37. echo -e "${red}${deptocheck}${default}"
  38. sleep 0.5
  39. fi
  40. fi
  41. # Missing dependencies are added to array_deps_missing
  42. if [ "${missingdep}" == "1" ]; then
  43. array_deps_missing+=("${deptocheck}")
  44. fi
  45. }
  46. fn_deps_email(){
  47. # Adds postfix to required dependencies if email alert is enabled
  48. if [ "${emailalert}" == "on" ]; then
  49. if [ -f /usr/bin/mailx ]; then
  50. if [ -d /etc/exim4 ]; then
  51. array_deps_required+=( exim4 )
  52. elif [ -d /etc/sendmail ]; then
  53. array_deps_required+=( sendmail )
  54. elif [ -n "$(command -v dpkg-query 2>/dev/null)" ]; then
  55. array_deps_required+=( mailutils postfix )
  56. elif [ -n "$(command -v yum 2>/dev/null)" ]; then
  57. array_deps_required+=( mailx postfix )
  58. fi
  59. else
  60. if [ -n "$(command -v dpkg-query 2>/dev/null)" ]; then
  61. array_deps_required+=( mailutils postfix )
  62. elif [ -n "$(command -v yum 2>/dev/null)" ]; then
  63. array_deps_required+=( mailx postfix )
  64. fi
  65. fi
  66. fi
  67. }
  68. fn_found_missing_deps(){
  69. if [ "${#array_deps_missing[@]}" != "0" ]; then
  70. fn_print_dots "Checking dependencies"
  71. sleep 0.5
  72. fn_print_error_nl "Checking dependencies: missing: ${red}${array_deps_missing[@]}${default}"
  73. fn_script_log_error "Checking dependencies: missing: ${array_deps_missing[@]}"
  74. sleep 0.5
  75. sudo -v > /dev/null 2>&1
  76. if [ $? -eq 0 ]; then
  77. fn_print_information_nl "Automatically installing missing dependencies."
  78. fn_script_log_info "Automatically installing missing dependencies."
  79. echo -en ".\r"
  80. sleep 1
  81. echo -en "..\r"
  82. sleep 1
  83. echo -en "...\r"
  84. sleep 1
  85. echo -en " \r"
  86. if [ -n "$(command -v dpkg-query 2>/dev/null)" ]; then
  87. cmd="sudo dpkg --add-architecture i386; sudo apt update; sudo apt -y install ${array_deps_missing[@]}"
  88. eval "${cmd}"
  89. elif [ -n "$(command -v yum 2>/dev/null)" ]; then
  90. cmd="sudo yum -y install ${array_deps_missing[@]}"
  91. eval "${cmd}"
  92. fi
  93. if [ $? != 0 ]; then
  94. fn_print_failure_nl "Unable to install dependencies"
  95. fn_script_log_fatal "Unable to install dependencies"
  96. else
  97. fn_print_complete_nl "Install dependencies completed"
  98. fn_script_log_pass "Install dependencies completed"
  99. fi
  100. else
  101. echo ""
  102. fn_print_warning_nl "$(whoami) does not have sudo access. Manually install dependencies."
  103. fn_script_log_warn "$(whoami) does not have sudo access. Manually install dependencies."
  104. if [ -n "$(command -v dpkg-query 2>/dev/null)" ]; then
  105. echo " sudo dpkg --add-architecture i386; sudo apt update; sudo apt install ${array_deps_missing[@]}"
  106. elif [ -n "$(command -v yum 2>/dev/null)" ]; then
  107. echo " sudo yum install ${array_deps_missing[@]}"
  108. fi
  109. echo ""
  110. fi
  111. if [ "${function_selfname}" == "command_install.sh" ]; then
  112. sleep 5
  113. fi
  114. fi
  115. }
  116. fn_check_loop(){
  117. # Loop though required depenencies
  118. for deptocheck in "${array_deps_required[@]}"
  119. do
  120. fn_deps_detector
  121. done
  122. # user to be informed of any missing dependencies
  123. fn_found_missing_deps
  124. }
  125. info_distro.sh
  126. if [ "${function_selfname}" == "command_install.sh" ]; then
  127. echo ""
  128. echo "Checking Dependencies"
  129. echo "================================="
  130. fi
  131. # Check will only run if using apt or yum
  132. if [ -n "$(command -v dpkg-query 2>/dev/null)" ]; then
  133. # Generate array of missing deps
  134. array_deps_missing=()
  135. # LinuxGSM requirements
  136. array_deps_required=( curl wget ca-certificates file bsdmainutils util-linux python bzip2 gzip unzip binutils bc )
  137. # All servers except ts3 require tmux
  138. if [ "${gamename}" != "TeamSpeak 3" ]; then
  139. if [ "$(command -v tmux 2>/dev/null)" ]; then
  140. tmuxcheck=1 # Added for users compiling tmux from source to bypass check.
  141. else
  142. array_deps_required+=( tmux )
  143. fi
  144. fi
  145. # All servers except ts3,mumble,multitheftauto and minecraft servers require libstdc++6 and lib32gcc1
  146. if [ "${gamename}" != "TeamSpeak 3" ]&&[ "${gamename}" != "Mumble" ]&&[ "${engine}" != "lwjgl2" ]&&[ "${engine}" != "renderware" ]; then
  147. if [ "${arch}" == "x86_64" ]; then
  148. array_deps_required+=( lib32gcc1 libstdc++6:i386 )
  149. else
  150. array_deps_required+=( libstdc++6:i386 )
  151. fi
  152. fi
  153. # Game Specific requirements
  154. # Natural Selection 2
  155. if [ "${gamename}" == "Natural Selection 2" ]; then
  156. array_deps_required+=( speex libtbb2 )
  157. # NS2: Combat
  158. elif [ "${gamename}" == "NS2: Combat" ]; then
  159. array_deps_required+=( speex:i386 libtbb2 )
  160. # 7 Days to Die
  161. elif [ "${gamename}" == "7 Days To Die" ]; then
  162. array_deps_required+=( telnet expect )
  163. # No More Room in Hell, Counter-Strike: Source and Garry's Mod
  164. elif [ "${gamename}" == "No More Room in Hell" ]||[ "${gamename}" == "Counter-Strike: Source" ]||[ "${gamename}" == "Garry's Mod" ]||[ "${gamename}" == "Zombie Panic! Source" ]; then
  165. if [ "${arch}" == "x86_64" ]; then
  166. array_deps_required+=( lib32tinfo5 )
  167. else
  168. array_deps_required+=( libtinfo5 )
  169. fi
  170. # Brainbread 2 ,Don't Starve Together & Team Fortress 2
  171. elif [ "${gamename}" == "Brainbread 2" ]||[ "${gamename}" == "Don't Starve Together" ]||[ "${gamename}" == "Team Fortress 2" ]; then
  172. array_deps_required+=( libcurl4-gnutls-dev:i386 )
  173. if [ "${gamename}" == "Team Fortress 2" ]; then
  174. array_deps_required+=( libtcmalloc-minimal4:i386 )
  175. fi
  176. # Battlefield: 1942
  177. elif [ "${gamename}" == "Battlefield: 1942" ]; then
  178. array_deps_required+=( libncurses5:i386 )
  179. # Call of Duty
  180. elif [ "${gamename}" == "Call of Duty" ]||[ "${gamename}" == "Call of Duty: United Offensive" ]||[ "${gamename}" == "Call of Duty 2" ]; then
  181. array_deps_required+=( libstdc++5:i386 )
  182. # Factorio
  183. elif [ "${gamename}" == "Factorio" ]; then
  184. array_deps_required+=( xz-utils )
  185. # Hurtword/Rust
  186. elif [ "${gamename}" == "Hurtword" ]||[ "${gamename}" == "Rust" ]; then
  187. array_deps_required+=( lib32z1 )
  188. # Project Zomboid and Minecraft
  189. elif [ "${engine}" == "projectzomboid" ]||[ "${engine}" == "lwjgl2" ]; then
  190. javaversion=$(java -version 2>&1 | grep "version")
  191. if [ -n "${javaversion}" ]; then
  192. javacheck=1 # Added for users using Oracle JRE to bypass the check.
  193. else
  194. array_deps_required+=( default-jre )
  195. fi
  196. # GoldenEye: Source
  197. elif [ "${gamename}" == "GoldenEye: Source" ]; then
  198. array_deps_required+=( zlib1g:i386 libldap-2.4-2:i386 )
  199. # Serious Sam 3: BFE
  200. elif [ "${gamename}" == "Serious Sam 3: BFE" ]; then
  201. array_deps_required+=( libxrandr2:i386 libglu1-mesa:i386 libxtst6:i386 libusb-1.0-0-dev:i386 libxxf86vm1:i386 libopenal1:i386 libssl1.0.0:i386 libgtk2.0-0:i386 libdbus-glib-1-2:i386 libnm-glib-dev:i386 )
  202. # Unreal Engine
  203. elif [ "${executable}" == "./ucc-bin" ]; then
  204. #UT2K4
  205. if [ -f "${executabledir}/ut2004-bin" ]; then
  206. array_deps_required+=( libsdl1.2debian libstdc++5:i386 bzip2 )
  207. #UT99
  208. else
  209. array_deps_required+=( libsdl1.2debian bzip2 )
  210. fi
  211. # Unreal Tournament
  212. elif [ "${gamename}" == "Unreal Tournament" ]; then
  213. array_deps_required+=( unzip )
  214. fi
  215. fn_deps_email
  216. fn_check_loop
  217. elif [ -n "$(command -v yum 2>/dev/null)" ]; then
  218. # Generate array of missing deps
  219. array_deps_missing=()
  220. # LinuxGSM requirements
  221. if [ "${distroversion}" == "6" ]; then
  222. array_deps_required=( curl wget util-linux-ng python file gzip bzip2 unzip binutils bc )
  223. elif [[ "${distroname}" == *"Amazon Linux AMI"* ]]; then
  224. array_deps_required=( curl wget util-linux python27 file gzip bzip2 unzip binutils bc )
  225. else
  226. array_deps_required=( curl wget util-linux python file gzip bzip2 unzip binutils bc )
  227. fi
  228. # All servers except ts3 require tmux
  229. if [ "${gamename}" != "TeamSpeak 3" ]; then
  230. if [ "$(command -v tmux 2>/dev/null)" ]; then
  231. tmuxcheck=1 # Added for users compiling tmux from source to bypass check.
  232. else
  233. array_deps_required+=( tmux )
  234. fi
  235. fi
  236. # All servers except ts3,mumble,multitheftauto and minecraft servers require glibc.i686 and libstdc++.i686
  237. if [ "${gamename}" != "TeamSpeak 3" ]&&[ "${gamename}" != "Mumble" ]&&[ "${engine}" != "lwjgl2" ]&&[ "${engine}" != "renderware" ]; then
  238. if [[ "${distroname}" == *"Amazon Linux AMI"* ]]; then
  239. array_deps_required+=( glibc.i686 libstdc++64.i686 )
  240. else
  241. array_deps_required+=( glibc.i686 libstdc++.i686 )
  242. fi
  243. fi
  244. # Game Specific requirements
  245. # Natural Selection 2
  246. if [ "${gamename}" == "Natural Selection 2" ]; then
  247. array_deps_required+=( speex tbb )
  248. # NS2: Combat
  249. elif [ "${gamename}" == "NS2: Combat" ]; then
  250. array_deps_required+=( speex.i686 tbb.i686 )
  251. # 7 Days to Die
  252. elif [ "${gamename}" == "7 Days To Die" ]; then
  253. array_deps_required+=( telnet expect )
  254. # No More Room in Hell, Counter-Strike: Source and Garry's Mod
  255. elif [ "${gamename}" == "No More Room in Hell" ]||[ "${gamename}" == "Counter-Strike: Source" ]||[ "${gamename}" == "Garry's Mod" ]||[ "${gamename}" == "Zombie Panic! Source" ]; then
  256. array_deps_required+=( ncurses-libs.i686 )
  257. # Brainbread 2, Don't Starve Together & Team Fortress 2
  258. elif [ "${gamename}" == "Brainbread 2" ]||[ "${gamename}" == "Don't Starve Together" ]||[ "${gamename}" == "Team Fortress 2" ]; then
  259. array_deps_required+=( libcurl.i686 )
  260. if [ "${gamename}" == "Team Fortress 2" ]; then
  261. array_deps_required+=( gperftools-libs.i686 )
  262. fi
  263. # Battlefield: 1942
  264. elif [ "${gamename}" == "Battlefield: 1942" ]; then
  265. array_deps_required+=( ncurses-libs.i686 )
  266. # Call of Duty
  267. elif [ "${gamename}" == "Call of Duty" ]||[ "${gamename}" == "Call of Duty: United Offensive" ]||[ "${gamename}" == "Call of Duty 2" ]; then
  268. array_deps_required+=( compat-libstdc++-33.i686 )
  269. # Factorio
  270. elif [ "${gamename}" == "Factorio" ]; then
  271. array_deps_required+=( xz )
  272. elif [ "${gamename}" == "Hurtword" ]||[ "${gamename}" == "Rust" ]; then
  273. array_deps_required+=( zlib-devel )
  274. # Project Zomboid and Minecraft
  275. elif [ "${engine}" == "projectzomboid" ]||[ "${engine}" == "lwjgl2" ]; then
  276. javaversion=$(java -version 2>&1 | grep "version")
  277. if [ -n "${javaversion}" ]; then
  278. javacheck=1 # Added for users using Oracle JRE to bypass the check.
  279. else
  280. array_deps_required+=( java-1.8.0-openjdk )
  281. fi
  282. # GoldenEye: Source
  283. elif [ "${gamename}" == "GoldenEye: Source" ]; then
  284. array_deps_required+=( zlib.i686 openldap.i686 )
  285. # Unreal Engine
  286. elif [ "${executable}" == "./ucc-bin" ]; then
  287. #UT2K4
  288. if [ -f "${executabledir}/ut2004-bin" ]; then
  289. array_deps_required+=( compat-libstdc++-33.i686 SDL.i686 bzip2 )
  290. #UT99
  291. else
  292. array_deps_required+=( SDL.i686 bzip2 )
  293. fi
  294. # Unreal Tournament
  295. elif [ "${gamename}" == "Unreal Tournament" ]; then
  296. array_deps_required+=( unzip )
  297. fi
  298. fn_deps_email
  299. fn_check_loop
  300. fi