check_deps.sh 14 KB

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