check_deps.sh 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  1. #!/bin/bash
  2. # LinuxGSM check_deps.sh module
  3. # Author: Daniel Gibbs
  4. # Contributors: https://linuxgsm.com/contrib
  5. # Website: https://linuxgsm.com
  6. # Description: Checks and installs missing dependencies.
  7. moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  8. fn_install_dotnet_repo() {
  9. local dotnetpackage
  10. dotnetpackage="dotnet-runtime-7.0"
  11. for dep in "${array_deps_missing[@]}"; do
  12. if [[ "${dep}" == dotnet-runtime-* ]]; then
  13. dotnetpackage="${dep}"
  14. break
  15. fi
  16. done
  17. if [ "${distroid}" == "ubuntu" ] || [ "${distroid}" == "debian" ]; then
  18. # If the required .NET package is unavailable in Ubuntu/Debian repos, add the Microsoft repo.
  19. if ! apt-cache show "${dotnetpackage}" > /dev/null 2>&1; then
  20. if [ "${autodepinstall}" == "0" ]; then
  21. fn_fetch_file "https://packages.microsoft.com/config/${distroid}/${distroversion}/packages-microsoft-prod.deb" "" "" "" "/tmp" "packages-microsoft-prod.deb" "" "" "" ""
  22. sudo dpkg -i /tmp/packages-microsoft-prod.deb
  23. else
  24. fn_print_information_nl "Installing Microsoft repository."
  25. fn_print_warning_nl "${nosudomessage}"
  26. echo -e "Follow instructions on Microsoft website to install."
  27. echo -e "https://learn.microsoft.com/en-us/dotnet/core/install/linux"
  28. fn_script_log_warn "Unable to install Microsoft repository. ${nosudomessage}"
  29. fi
  30. fi
  31. fi
  32. }
  33. fn_install_mono_repo() {
  34. if [ "${autodepinstall}" == "0" ]; then
  35. fn_print_information_nl "Automatically adding Mono repository."
  36. fn_script_log_info "Automatically adding Mono repository."
  37. if [ -z "${plainoutput}" ]; then
  38. echo -en ".\r"
  39. fn_sleep_time_1
  40. echo -en "..\r"
  41. fn_sleep_time_1
  42. echo -en "...\r"
  43. fn_sleep_time_1
  44. echo -en " \r"
  45. fi
  46. if [ "${distroid}" == "ubuntu" ]; then
  47. if [ "${distroversion}" == "22.04" ]; then
  48. cmd="sudo apt-get install gnupg ca-certificates;sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF;echo 'deb https://download.mono-project.com/repo/ubuntu stable-jammy main' | sudo tee /etc/apt/sources.list.d/mono-official-stable.list;sudo apt update"
  49. elif [ "${distroversion}" == "20.04" ]; then
  50. cmd="sudo apt-get install gnupg ca-certificates;sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF;echo 'deb https://download.mono-project.com/repo/ubuntu stable-focal main' | sudo tee /etc/apt/sources.list.d/mono-official-stable.list;sudo apt update"
  51. elif [ "${distroversion}" == "18.04" ]; then
  52. cmd="sudo apt-get install gnupg ca-certificates;sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF;echo 'deb https://download.mono-project.com/repo/ubuntu stable-bionic main' | sudo tee /etc/apt/sources.list.d/mono-official-stable.list;sudo apt update"
  53. elif [ "${distroversion}" == "16.04" ]; then
  54. cmd="sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF;sudo apt install apt-transport-https ca-certificates;echo 'deb https://download.mono-project.com/repo/ubuntu stable-xenial main' | sudo tee /etc/apt/sources.list.d/mono-official-stable.list;sudo apt update"
  55. else
  56. monoautoinstall="1"
  57. fi
  58. elif [ "${distroid}" == "debian" ]; then
  59. if [ "${distroversion}" == "12" ]; then
  60. cmd="sudo apt-get install apt-transport-https dirmngr gnupg ca-certificates;sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF;echo 'deb https://download.mono-project.com/repo/debian stable-bookworm main' | sudo tee /etc/apt/sources.list.d/mono-official-stable.list;sudo apt update"
  61. elif [ "${distroversion}" == "11" ]; then
  62. cmd="sudo apt-get install apt-transport-https dirmngr gnupg ca-certificates;sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF;echo 'deb https://download.mono-project.com/repo/debian stable-bullseye main' | sudo tee /etc/apt/sources.list.d/mono-official-stable.list;sudo apt update"
  63. elif [ "${distroversion}" == "10" ]; then
  64. cmd="sudo apt-get install apt-transport-https dirmngr gnupg ca-certificates;sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF;echo 'deb https://download.mono-project.com/repo/debian stable-buster main' | sudo tee /etc/apt/sources.list.d/mono-official-stable.list;sudo apt update"
  65. elif [ "${distroversion}" == "9" ]; then
  66. cmd="sudo apt-get install apt-transport-https dirmngr gnupg ca-certificates;sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF;echo 'deb https://download.mono-project.com/repo/debian stable-stretch main' | sudo tee /etc/apt/sources.list.d/mono-official-stable.list;sudo apt update"
  67. else
  68. monoautoinstall="1"
  69. fi
  70. elif [ "${distroid}" == "centos" ] || [ "${distroid}" == "almalinux" ] || [ "${distroid}" == "rocky" ]; then
  71. if [ "${distroversion}" == "8" ]; then
  72. cmd="sudo rpmkeys --import 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF';su -c 'curl https://download.mono-project.com/repo/centos8-stable.repo | tee /etc/yum.repos.d/mono-centos8-stable.repo'"
  73. elif [ "${distroversion}" == "7" ]; then
  74. cmd="sudo rpmkeys --import 'https://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'"
  75. else
  76. monoautoinstall="1"
  77. fi
  78. elif [ "${distroid}" == "fedora" ]; then
  79. if [ "${distroversion}" -ge "29" ]; then
  80. cmd="sudo rpm --import 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF';su -c 'curl https://download.mono-project.com/repo/centos8-stable.repo | tee /etc/yum.repos.d/mono-centos8-stable.repo';dnf update"
  81. else
  82. cmd="sudo rpm --import 'https://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';dnf update"
  83. fi
  84. else
  85. monoautoinstall="1"
  86. fi
  87. # Run the mono repo install.
  88. eval "${cmd}"
  89. monorepoexitcode=$?
  90. # Did Mono repo install correctly?
  91. if [ "${monoautoinstall}" != "1" ]; then
  92. if [ "${monorepoexitcode}" -ne 0 ]; then
  93. fn_print_failure_nl "Unable to install Mono repository."
  94. fn_script_log_fail "Unable to install Mono repository."
  95. else
  96. fn_print_success_nl "Installing Mono repository completed."
  97. fn_script_log_pass "Installing Mono repository completed."
  98. fi
  99. fi
  100. # Mono can not be auto installed with this distro.
  101. if [ "${monoautoinstall}" == "1" ]; then
  102. fn_print_warning_nl "Mono auto install not available for ${distroname}."
  103. echo -e "Follow instructions on Mono website to install."
  104. echo -e "https://www.mono-project.com/download/stable/#download-lin"
  105. fn_script_log_warn "Unable to install Mono repository. Mono auto install not available for ${distroname}."
  106. fi
  107. else
  108. fn_print_information_nl "Installing Mono repository."
  109. fn_print_warning_nl "${nosudomessage}"
  110. echo -e "Follow instructions on Mono website to install."
  111. echo -e "https://www.mono-project.com/download/stable/#download-lin"
  112. fn_script_log_warn "Unable to install Mono repository. ${nosudomessage}"
  113. fi
  114. }
  115. fn_deps_email() {
  116. # Adds postfix to required dependencies if email alert is enabled.
  117. if [ "${emailalert}" == "on" ]; then
  118. if [ -f /usr/bin/mailx ]; then
  119. if [ -d /etc/exim4 ]; then
  120. array_deps_required+=(exim4)
  121. elif [ -d /etc/sendmail ]; then
  122. array_deps_required+=(sendmail)
  123. elif [ "$(command -v apt 2> /dev/null)" ] && [ -d /etc/nullmailer ]; then
  124. # 'mailutils' provides the 'mail' binary, 'nullmailer' is the MTA
  125. array_deps_required+=(mailutils nullmailer)
  126. elif [ "$(command -v yum 2> /dev/null)" ] || [ "$(command -v dnf 2> /dev/null)" ]; then
  127. array_deps_required+=(s-nail postfix)
  128. elif [ "$(command -v apt 2> /dev/null)" ]; then
  129. array_deps_required+=(mailutils postfix)
  130. fi
  131. else
  132. if [ "$(command -v yum 2> /dev/null)" ] || [ "$(command -v dnf 2> /dev/null)" ]; then
  133. array_deps_required+=(s-nail postfix)
  134. elif [ "$(command -v apt 2> /dev/null)" ]; then
  135. array_deps_required+=(mailutils postfix)
  136. fi
  137. fi
  138. fi
  139. }
  140. fn_install_missing_deps() {
  141. # If any dependencies are not installed.
  142. if [ "${#array_deps_missing[*]}" != "0" ]; then
  143. if [ "${commandname}" == "INSTALL" ]; then
  144. fn_print_warning_nl "Missing dependencies: ${red}${array_deps_missing[*]}${default}"
  145. fn_script_log_warn "Missing dependencies: ${array_deps_missing[*]}"
  146. else
  147. fn_print_dots "Missing dependencies"
  148. fn_print_warn "Missing dependencies: ${red}${array_deps_missing[*]}${default}"
  149. fn_script_log_warn "Missing dependencies: ${array_deps_missing[*]}"
  150. fi
  151. # Attempt automatic dependency installation.
  152. # Check for passwordless sudo first: sudo-rs (default sudo from Ubuntu 25.10) always asks
  153. # for a password for sudo -v, even when the user has NOPASSWD.
  154. if sudo -n true > /dev/null 2>&1; then
  155. autodepinstall="0"
  156. elif [ "${autoinstall}" == "1" ]; then
  157. autodepinstall="1"
  158. nosudomessage="sudo cannot run without a password during auto-install."
  159. else
  160. sudo -v > /dev/null 2>&1
  161. autodepinstall="$?"
  162. nosudomessage="$(whoami) does not have sudo access."
  163. fi
  164. if [ "${monoinstalled}" == "false" ]; then
  165. fn_install_mono_repo
  166. fi
  167. if [ "${dotnetinstalled}" == "false" ]; then
  168. fn_install_dotnet_repo
  169. fi
  170. if [ "${commandname}" == "INSTALL" ]; then
  171. if [ "${autodepinstall}" == "0" ]; then
  172. fn_print_information_nl "$(whoami) has sudo access."
  173. fn_script_log_info "$(whoami) has sudo access."
  174. else
  175. fn_print_warning_nl "${nosudomessage} Manually install dependencies or run ./${selfname} install as root."
  176. fn_script_log_warn "${nosudomessage} Manually install dependencies or run ./${selfname} install as root."
  177. fi
  178. fi
  179. # Add sudo dpkg --add-architecture i386 if using i386 packages.
  180. if [ "$(command -v apt 2> /dev/null)" ]; then
  181. if printf '%s\n' "${array_deps_required[@]}" | grep -q -P 'i386'; then
  182. i386installcommand="sudo dpkg --add-architecture i386; "
  183. fi
  184. fi
  185. # If automatic dependency install is available
  186. if [ "${autodepinstall}" == "0" ]; then
  187. fn_print_information_nl "Automatically installing missing dependencies."
  188. fn_script_log_info "Automatically installing missing dependencies."
  189. if [ -z "${plainoutput}" ]; then
  190. echo -en ".\r"
  191. fn_sleep_time_1
  192. echo -en "..\r"
  193. fn_sleep_time_1
  194. echo -en "...\r"
  195. fn_sleep_time_1
  196. echo -en " \r"
  197. fi
  198. if [ "$(command -v apt 2> /dev/null)" ]; then
  199. cmd="echo steamcmd steam/question select \"I AGREE\" | sudo debconf-set-selections; echo steamcmd steam/license note '' | sudo debconf-set-selections; ${i386installcommand}sudo apt-get update; sudo apt-get -y install ${array_deps_missing[*]}"
  200. eval "${cmd}"
  201. elif [ "$(command -v dnf 2> /dev/null)" ]; then
  202. cmd="sudo dnf -y install ${array_deps_missing[*]}"
  203. eval "${cmd}"
  204. elif [ "$(command -v yum 2> /dev/null)" ]; then
  205. cmd="sudo yum -y install ${array_deps_missing[*]}"
  206. eval "${cmd}"
  207. fi
  208. autodepinstall="$?"
  209. # If auto install passes, remove steamcmd install failure and set exit code to 0.
  210. if [ "${autodepinstall}" == "0" ]; then
  211. unset steamcmdfail
  212. exitcode=0
  213. fi
  214. fi
  215. # If automatic dependency install is unavailable.
  216. if [ "${autodepinstall}" != "0" ]; then
  217. if [ "$(command -v apt 2> /dev/null)" ]; then
  218. echo -e " Run: '${green}${i386installcommand}sudo apt update; sudo apt install ${array_deps_missing[*]}${default}' as root to install missing dependencies."
  219. elif [ "$(command -v dnf 2> /dev/null)" ]; then
  220. echo -e " Run: '${green}sudo dnf install ${array_deps_missing[*]}${default}' as root to install missing dependencies."
  221. elif [ "$(command -v yum 2> /dev/null)" ]; then
  222. echo -e " Run: '${green}sudo yum install ${array_deps_missing[*]}${default}' as root to install missing dependencies."
  223. fi
  224. fi
  225. if [ "${steamcmdfail}" ]; then
  226. if [ "${commandname}" == "INSTALL" ]; then
  227. fn_print_failure_nl "Missing dependencies required to run SteamCMD."
  228. fn_script_log_fail "Missing dependencies required to run SteamCMD."
  229. core_exit.sh
  230. else
  231. fn_print_error_nl "Missing dependencies required to run SteamCMD."
  232. fn_script_log_error "Missing dependencies required to run SteamCMD."
  233. fi
  234. fi
  235. else
  236. if [ "${commandname}" == "INSTALL" ]; then
  237. fn_print_skip2_nl "Required dependencies already installed."
  238. fn_script_log_info "Required dependencies already installed."
  239. fi
  240. fi
  241. }
  242. fn_check_loop() {
  243. # Loop though required dependencies checking if they are installed.
  244. for deptocheck in "${array_deps_required[@]}"; do
  245. fn_deps_detector
  246. done
  247. # user will be informed of any missing dependencies.
  248. if [ "${depcheckonly}" != "1" ]; then
  249. fn_install_missing_deps
  250. fi
  251. }
  252. # Checks if dependency is installed or not.
  253. fn_deps_version_ge() {
  254. [ "$(printf '%s\n' "$1" "$2" | sort -V | head -1)" == "$2" ]
  255. }
  256. fn_deps_detector() {
  257. ## Check.
  258. # SteamCMD: Will be removed from required array if no appid is present or non-free repo is not available.
  259. # This will cause SteamCMD to be installed using tar.
  260. if [ "${deptocheck}" == "libsdl2-2.0-0:i386" ] && [ -z "${appid}" ]; then
  261. array_deps_required=("${array_deps_required[@]/libsdl2-2.0-0:i386/}")
  262. steamcmdstatus=1
  263. return
  264. elif [ "${deptocheck}" == "steamcmd" ] && [ -z "${appid}" ]; then
  265. array_deps_required=("${array_deps_required[@]/steamcmd/}")
  266. steamcmdstatus=1
  267. return
  268. # Checks classic and deb822 sources for an uncommented non-free component (non-free-firmware does not count).
  269. elif [ "${deptocheck}" == "steamcmd" ] && [ "${distroid}" == "debian" ] && ! grep -qE '^[[:space:]]*[^#[:space:]].*[[:space:]]non-free([[:space:]]|$)' /etc/apt/sources.list /etc/apt/sources.list.d/*.list /etc/apt/sources.list.d/*.sources 2> /dev/null; then
  270. array_deps_required=("${array_deps_required[@]/steamcmd/}")
  271. steamcmdstatus=1
  272. return
  273. # Java: Added for users using Oracle JRE to bypass check.
  274. elif [[ ${deptocheck} == "openjdk"* ]] || [[ ${deptocheck} == "java"* ]]; then
  275. # Is java already installed?
  276. if [ -n "${javaversion}" ]; then
  277. javamajorversion="$(echo "${javaversion}" | grep -Eo 'version "[0-9]+' | grep -Eo '[0-9]+' | head -1)"
  278. javarequiredmajor="$(echo "${deptocheck}" | grep -Eo '[0-9]+' | head -1)"
  279. if [ "${shortname}" == "mc" ] || [ "${shortname}" == "pmc" ]; then
  280. if [ "${mcversion}" == "latest" ]; then
  281. javarequiredmajor="25"
  282. elif [[ "${mcversion}" =~ ^[0-9]+\.[0-9]+([.][0-9]+)?$ ]]; then
  283. if fn_deps_version_ge "${mcversion}" "26.1"; then
  284. javarequiredmajor="25"
  285. elif [ "${shortname}" == "mc" ] && fn_deps_version_ge "${mcversion}" "1.20.5"; then
  286. javarequiredmajor="21"
  287. elif [ "${shortname}" == "pmc" ] && fn_deps_version_ge "${mcversion}" "1.20" && fn_deps_version_ge "1.21.11" "${mcversion}"; then
  288. javarequiredmajor="21"
  289. elif [ "${shortname}" == "pmc" ] && fn_deps_version_ge "${mcversion}" "1.17" && fn_deps_version_ge "1.19" "${mcversion}"; then
  290. javarequiredmajor="17"
  291. elif [ "${shortname}" == "pmc" ] && [ "${mcversion}" == "1.16.5" ]; then
  292. javarequiredmajor="16"
  293. elif [ "${shortname}" == "pmc" ] && fn_deps_version_ge "${mcversion}" "1.12" && ! fn_deps_version_ge "${mcversion}" "1.16.5"; then
  294. javarequiredmajor="11"
  295. elif [ "${shortname}" == "pmc" ] && ! fn_deps_version_ge "${mcversion}" "1.16.5"; then
  296. javarequiredmajor="8"
  297. fi
  298. fi
  299. fi
  300. if [ "${shortname}" == "hyt" ] && { [ -z "${javamajorversion}" ] || [ "${javamajorversion}" -lt "25" ]; }; then
  301. # Java 25 installed but not the active java: installing it again would not change that.
  302. if compgen -G "/usr/lib/jvm/*25*/bin/java" > /dev/null; then
  303. depstatus=0
  304. deptocheck="${javaversion}"
  305. fn_print_warn_nl "Java 25 is installed but the active java is version ${javamajorversion:-unknown}. Select Java 25 with: sudo update-alternatives --config java"
  306. fn_script_log_warn "Java 25 is installed but the active java is version ${javamajorversion:-unknown}"
  307. else
  308. depstatus=1
  309. fi
  310. elif [ -n "${javamajorversion}" ] && [ "${javamajorversion}" -lt "${javarequiredmajor}" ]; then
  311. if [ "${depcheckonly}" == "1" ]; then
  312. depstatus=1
  313. elif [ "${javarequiredmajor}" -gt "$(echo "${deptocheck}" | grep -Eo '[0-9]+' | head -1)" ]; then
  314. fn_print_failure_nl "${gamename} ${mcversion} requires Java ${javarequiredmajor}; ${distroname} does not provide that version as a package."
  315. echo -e "Install Java ${javarequiredmajor} manually or upgrade to Debian 13 or Ubuntu 24.04+."
  316. fn_script_log_fail "${gamename} ${mcversion} requires Java ${javarequiredmajor}; ${distroname} does not provide it as a package."
  317. core_exit.sh
  318. else
  319. fn_print_failure_nl "${gamename} ${mcversion} requires Java ${javarequiredmajor}; active Java is ${javamajorversion}."
  320. echo -e "Select a compatible Java runtime with: sudo update-alternatives --config java"
  321. fn_script_log_fail "${gamename} ${mcversion} requires Java ${javarequiredmajor}; active Java is ${javamajorversion}."
  322. core_exit.sh
  323. fi
  324. else
  325. # Added for users using Oracle JRE to bypass check.
  326. depstatus=0
  327. deptocheck="${javaversion}"
  328. fi
  329. else
  330. javarequiredmajor="$(echo "${deptocheck}" | grep -Eo '[0-9]+' | head -1)"
  331. if [ "${shortname}" == "mc" ] || [ "${shortname}" == "pmc" ]; then
  332. if [ "${mcversion}" == "latest" ] || fn_deps_version_ge "${mcversion}" "26.1"; then
  333. javarequiredmajor="25"
  334. elif { [ "${shortname}" == "mc" ] && fn_deps_version_ge "${mcversion}" "1.20.5"; } || { [ "${shortname}" == "pmc" ] && fn_deps_version_ge "${mcversion}" "1.20" && fn_deps_version_ge "1.21.11" "${mcversion}"; }; then
  335. javarequiredmajor="21"
  336. fi
  337. fi
  338. if [ "${javarequiredmajor}" -gt "$(echo "${deptocheck}" | grep -Eo '[0-9]+' | head -1)" ] && [ "${depcheckonly}" != "1" ]; then
  339. fn_print_failure_nl "${gamename} ${mcversion} requires Java ${javarequiredmajor}; ${distroname} does not provide that version as a package."
  340. echo -e "Install Java ${javarequiredmajor} manually or upgrade to Debian 13 or Ubuntu 24.04+."
  341. fn_script_log_fail "${gamename} ${mcversion} requires Java ${javarequiredmajor}; ${distroname} does not provide it as a package."
  342. core_exit.sh
  343. else
  344. depstatus=1
  345. fi
  346. fi
  347. # Mono: A Mono repo needs to be installed.
  348. elif [ "${deptocheck}" == "mono-complete" ]; then
  349. if [ -n "${monoversion}" ] && [ "${monoversion}" -ge "5" ]; then
  350. # Mono >= 5.0.0 already installed.
  351. depstatus=0
  352. monoinstalled=true
  353. else
  354. # Mono not installed or installed Mono < 5.0.0.
  355. depstatus=1
  356. monoinstalled=false
  357. fi
  358. # .NET runtime: check installed runtime version for any dotnet-runtime-X.Y package.
  359. elif [[ "${deptocheck}" =~ ^dotnet-runtime-([0-9]+\.[0-9]+)$ ]]; then
  360. dotnetrequired="${BASH_REMATCH[1]}"
  361. if [ "$(command -v dotnet 2> /dev/null)" ] && dotnet --list-runtimes | grep -q "Microsoft.NETCore.App ${dotnetrequired}"; then
  362. depstatus=0
  363. dotnetinstalled=true
  364. else
  365. depstatus=1
  366. dotnetinstalled=false
  367. fi
  368. elif [ "$(command -v apt 2> /dev/null)" ]; then
  369. dpkg-query -W -f='${Status}' "${deptocheck}" 2> /dev/null | grep -q -P '^install ok installed'
  370. depstatus=$?
  371. elif [ "$(command -v dnf 2> /dev/null)" ]; then
  372. dnf list installed "${deptocheck}" > /dev/null 2>&1
  373. depstatus=$?
  374. elif [ "$(command -v rpm 2> /dev/null)" ]; then
  375. rpm -q "${deptocheck}" > /dev/null 2>&1
  376. depstatus=$?
  377. fi
  378. # Outcome of Check.
  379. if [ "${steamcmdstatus}" == "1" ]; then
  380. # If SteamCMD is not available in repo dont check for it.
  381. unset steamcmdstatus
  382. elif [ "${depstatus}" == "0" ]; then
  383. # If dependency is found.
  384. missingdep=0
  385. if [ "${commandname}" == "INSTALL" ]; then
  386. echo -e "${green}${deptocheck}${default}"
  387. fn_sleep_time
  388. fi
  389. elif [ "${depstatus}" != "0" ]; then
  390. # If dependency is not found.
  391. missingdep=1
  392. if [ "${commandname}" == "INSTALL" ]; then
  393. echo -e "${red}${deptocheck}${default}"
  394. fn_sleep_time
  395. fi
  396. # If SteamCMD requirements are not met install will fail.
  397. if [ -n "${appid}" ]; then
  398. for steamcmddeptocheck in "${array_deps_required_steamcmd[@]}"; do
  399. if [ "${deptocheck}" != "steamcmd" ] && [ "${deptocheck}" == "${steamcmddeptocheck}" ]; then
  400. steamcmdfail=1
  401. fi
  402. done
  403. fi
  404. fi
  405. unset depstatus
  406. # Missing dependencies are added to array_deps_missing.
  407. if [ "${missingdep}" == "1" ]; then
  408. array_deps_missing+=("${deptocheck}")
  409. fi
  410. }
  411. if [ "${commandname}" == "DETAILS" ] || [ "${commandname}" == "POST-DETAILS" ]; then
  412. depcheckonly="1"
  413. fi
  414. if [ "${commandname}" == "INSTALL" ]; then
  415. if [ "$(whoami)" == "root" ]; then
  416. echo -e ""
  417. echo -e "${bold}${lightyellow}Checking ${gamename} Dependencies as root${default}"
  418. fn_messages_separator
  419. fn_print_information_nl "Checking any missing dependencies for ${gamename} server only."
  420. fn_print_information_nl "This will NOT install a ${gamename} server."
  421. else
  422. echo -e ""
  423. echo -e "${bold}${lightyellow}Checking ${gamename} Dependencies${default}"
  424. fn_messages_separator
  425. fi
  426. fi
  427. info_distro.sh
  428. if [ "${depcheckonly}" != "1" ]; then
  429. # Will warn user if their distro is no longer supported by the vendor.
  430. if [ -n "${distrosupport}" ]; then
  431. if [ "${distrosupport}" == "unsupported" ]; then
  432. fn_print_warning_nl "${distroname} is no longer supported by the vendor or LinuxGSM. Upgrading is recommended."
  433. fn_script_log_warn "${distroname} is no longer supported by the vendor or LinuxGSM. Upgrading is recommended."
  434. fi
  435. fi
  436. # These titles are only supported up to Ubuntu 20.04 and Debian 11.
  437. if { [ "${distroid}" == "ubuntu" ] && dpkg --compare-versions "${distroversion}" "gt" "20.04"; } || { [ "${distroid}" == "debian" ] && dpkg --compare-versions "${distroversion}" "gt" "11"; }; then
  438. if [ "${shortname}" == "onset" ] || [ "${shortname}" == "btl" ]; then
  439. fn_print_failure_nl "${gamename} is not supported on ${distroname} (requires Ubuntu <= 20.04 or Debian <= 11)."
  440. fn_script_log_fail "${gamename} is not supported on ${distroname}."
  441. core_exit.sh
  442. fi
  443. fi
  444. # Vintage Story tracks newer .NET runtimes; older distro releases may not ship required packages.
  445. if [ "${shortname}" == "vints" ]; then
  446. if { [ "${distroid}" == "ubuntu" ] && dpkg --compare-versions "${distroversion}" "lt" "24.04"; } || { [ "${distroid}" == "debian" ] && dpkg --compare-versions "${distroversion}" "lt" "12"; } || [ "${distroid}" == "centos" ] || [ "${distroid}" == "rhel" ] || [ "${distroid}" == "rocky" ] || [ "${distroid}" == "almalinux" ]; then
  447. fn_print_warning_nl "${gamename} may require newer .NET runtimes than ${distroname} provides."
  448. echo -e "If startup fails due to missing .NET runtime, upgrading to Ubuntu 24.04+ or Debian 12+ is recommended."
  449. fn_script_log_warn "${gamename} may require newer .NET runtimes than ${distroname} provides."
  450. fi
  451. fi
  452. # Hytale needs Java 25, which Ubuntu before 22.04, Debian before 13 and RHEL before 9 do not package.
  453. if [ "${shortname}" == "hyt" ]; then
  454. if { [ "${distroid}" == "ubuntu" ] && [ "${distroversion}" != "22.04" ] && dpkg --compare-versions "${distroversion}" "lt" "24.04"; } || { [ "${distroid}" == "debian" ] && dpkg --compare-versions "${distroversion}" "lt" "13"; } || { [ -n "${distroversionrh}" ] && [ "${distroversionrh}" -lt "9" ]; }; then
  455. if ! echo "${javaversion}" | grep -Eq 'version "(2[5-9]|[3-9][0-9])'; then
  456. fn_print_warning_nl "${gamename} requires Java 25, which ${distroname} does not provide."
  457. echo -e "Install Java 25 manually or upgrade to Ubuntu 22.04+, Debian 13+ or a RHEL 9 based distro."
  458. fn_script_log_warn "${gamename} requires Java 25, which ${distroname} does not provide."
  459. fi
  460. fi
  461. fi
  462. fi
  463. if [ ! -f "${tmpdir}/dependency-no-check.tmp" ] && [ ! -f "${datadir}/${distroid}-${distroversioncsv}.csv" ]; then
  464. # Check that the distro dependency csv file exists.
  465. fn_check_file_github "lgsm/data" "${distroid}-${distroversioncsv}.csv"
  466. if [ -n "${checkflag}" ] && [ "${checkflag}" == "0" ]; then
  467. fn_fetch_file_github "lgsm/data" "${distroid}-${distroversioncsv}.csv" "${datadir}" "chmodx" "norun" "noforce" "nohash"
  468. fi
  469. fi
  470. # If the file successfully downloaded run the dependency check.
  471. if [ -f "${datadir}/${distroid}-${distroversioncsv}.csv" ]; then
  472. depall=$(awk -F, '$1=="all" {$1=""; print $0}' "${datadir}/${distroid}-${distroversioncsv}.csv")
  473. depsteamcmd=$(awk -F, '$1=="steamcmd" {$1=""; print $0}' "${datadir}/${distroid}-${distroversioncsv}.csv")
  474. depshortname=$(awk -v shortname="${shortname}" -F, '$1==shortname {$1=""; print $0}' "${datadir}/${distroid}-${distroversioncsv}.csv")
  475. # Generate array of missing deps.
  476. array_deps_missing=()
  477. array_deps_required=("${depall} ${depsteamcmd} ${depshortname}")
  478. array_deps_required_steamcmd=("${depsteamcmd}")
  479. fn_deps_email
  480. if [ "${logtimestamp}" == "on" ]; then
  481. array_deps_required+=(gawk)
  482. fi
  483. # Unique sort dependency array.
  484. IFS=" " read -r -a array_deps_required <<< "$(echo "${array_deps_required[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' ')"
  485. fn_check_loop
  486. elif [ "${depcheckonly}" == "1" ]; then
  487. # shellcheck disable=SC2034 # Used by info_messages.sh.
  488. depcheckunavailable="1"
  489. # Warn the user that dependency checking is unavailable for their distro.
  490. elif [ "${commandname}" == "INSTALL" ] || [ -n "${checkflag}" ] && [ "${checkflag}" != "0" ]; then
  491. fn_print_warning_nl "LinuxGSM dependency checking currently unavailable for ${distroname}."
  492. # Prevent future dependency checking if unavailable for the distro.
  493. echo "${version}" > "${tmpdir}/dependency-no-check.tmp"
  494. elif [ -f "${tmpdir}/dependency-no-check.tmp" ]; then
  495. # Allow LinuxGSM to try a dependency check if LinuxGSM has been recently updated.
  496. nocheckversion=$(cat "${tmpdir}/dependency-no-check.tmp")
  497. if [ "${version}" != "${nocheckversion}" ]; then
  498. rm -f "${tmpdir:?}/dependency-no-check.tmp"
  499. fi
  500. fi