From c0b7228b675fb62085ac7a2f993706bb31c7ec26 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Sun, 12 Sep 2021 23:01:54 +0100 Subject: [PATCH] re-word of mono repo install --- lgsm/functions/check_deps.sh | 294 ++++++++++++++++------------------- 1 file changed, 130 insertions(+), 164 deletions(-) diff --git a/lgsm/functions/check_deps.sh b/lgsm/functions/check_deps.sh index 2f0b2d169..f794b5d6c 100755 --- a/lgsm/functions/check_deps.sh +++ b/lgsm/functions/check_deps.sh @@ -3,104 +3,85 @@ # Author: Daniel Gibbs # Contributors: http://linuxgsm.com/contrib # Website: https://linuxgsm.com -# Description: Checks if required dependencies are installed for LinuxGSM. +# Description: Checks and installs missing dependencies. functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")" fn_install_mono_repo(){ - if [ "${monostatus}" != "0" ]; then - if [ "${autoinstall}" == "1" ]; then - sudo -n true > /dev/null 2>&1 - else - sudo -v > /dev/null 2>&1 - fi - if [ $? -eq 0 ]; then - fn_print_information_nl "Automatically adding Mono repository." - fn_script_log_info "Automatically adding Mono repository." - echo -en ".\r" - sleep 1 - echo -en "..\r" - sleep 1 - echo -en "...\r" - sleep 1 - echo -en " \r" - if [ "${distroid}" == "ubuntu" ]; then - if [ "${distroversion}" == "20.04" ]; then - cmd="sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF;sudo apt-add-repository 'deb https://download.mono-project.com/repo/ubuntu stable-focal main';sudo apt-get update" - eval "${cmd}" - elif [ "${distroversion}" == "18.04" ]; then - cmd="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-get update" - eval "${cmd}" - elif [ "${distroversion}" == "16.04" ]; then - cmd="sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF;sudo apt-get install apt-transport-https;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-get update" - eval "${cmd}" - elif [ "${distroversion}" == "14.04" ]; then - cmd="sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF;sudo apt-get install apt-transport-https;echo 'deb https://download.mono-project.com/repo/ubuntu stable-trusty main' | sudo tee /etc/apt/sources.list.d/mono-official-stable.list;sudo apt-get update" - eval "${cmd}" - else - fn_print_warning_nl "Installing Mono repository." - echo -e "Mono auto install not available for ${distroname}" - echo -e " Follow instructions on mono site to install the latest version of Mono." - echo -e " https://www.mono-project.com/download/stable/#download-lin" - monoautoinstall="1" - fi - elif [ "${distroid}" == "debian" ]; then - if [ "${distroversion}" == "10" ]; then - cmd="sudo apt-get install apt-transport-https dirmngr;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-get update" - eval "${cmd}" - elif [ "${distroversion}" == "9" ]; then - cmd="sudo apt-get install apt-transport-https dirmngr;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-get update" - eval "${cmd}" - elif [ "${distroversion}" == "8" ]; then - cmd="sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF;sudo apt-get install apt-transport-https;echo 'deb https://download.mono-project.com/repo/debian stable-jessie main' | sudo tee /etc/apt/sources.list.d/mono-official-stable.list;sudo apt-get update" - eval "${cmd}" - else - echo -e "Mono auto install not available for ${distroname}" - echo -e " Follow instructions on mono site to install the latest version of Mono." - echo -e " https://www.mono-project.com/download/stable/#download-lin" - monoautoinstall="1" - fi - elif [ "${distroid}" == "centos" ]; then - if [ "${distroversion}" == "8" ]; then - cmd="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'" - eval "${cmd}" - elif [ "${distroversion}" == "7" ]; then - cmd="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'" - eval "${cmd}" - else - echo -e "Mono auto install not available for ${distroname}" - echo -e " Follow instructions on mono site to install the latest version of Mono." - echo -e " https://www.mono-project.com/download/stable/#download-lin" - monoautoinstall="1" - fi - elif [ "${distroid}" == "fedora" ]; then - cmd="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" - eval "${cmd}" + if [ "${autodepinstall}" == "0" ]; then + fn_print_information_nl "Automatically adding Mono repository." + fn_script_log_info "Automatically adding Mono repository." + echo -en ".\r" + sleep 1 + echo -en "..\r" + sleep 1 + echo -en "...\r" + sleep 1 + echo -en " \r" + if [ "${distroid}" == "ubuntu" ]; then + if [ "${distroversion}" == "20.04" ]; then + cmd="sudo apt 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" + elif [ "${distroversion}" == "18.04" ]; then + cmd="sudo apt 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" + elif [ "${distroversion}" == "16.04" ]; then + 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" + else + monoautoinstall="1" + fi + elif [ "${distroid}" == "debian" ]; then + if [ "${distroversion}" == "10" ]; then + cmd="sudo apt 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" + elif [ "${distroversion}" == "9" ]; then + cmd="sudo apt 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" else - echo -e "Mono auto install not available for ${distroname}" - echo -e " Follow instructions on mono site to install the latest version of Mono." - echo -e " https://www.mono-project.com/download/stable/#download-lin" monoautoinstall="1" fi - if [ "${monoautoinstall}" != "1" ]; then - if [ $? != 0 ]; then - fn_print_failure_nl "Unable to install Mono repository." - fn_script_log_fatal "Unable to installMono repository." - monoautoinstall=1 - else - fn_print_complete_nl "Installing Mono repository completed." - fn_script_log_pass "Installing Mono repository completed." - monoautoinstall=0 - fi + elif [ "${distroid}" == "centos" ]||[ "${distroid}" == "almalinux" ]||[ "${distroid}" == "rocky" ]; then + if [ "${distroversion}" == "8" ]; then + 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'" + elif [ "${distroversion}" == "7" ]; then + 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'" + else + monoautoinstall="1" + fi + elif [ "${distroid}" == "fedora" ]; then + if [ "${distroversion}" -ge "29" ]; then + 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" + else + 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" fi else - fn_print_information_nl "Installing Mono repository." - echo -e "" - fn_print_warning_nl "$(whoami) does not have sudo access. Manually install Mono repository." - fn_script_log_warn "$(whoami) does not have sudo access. Manually install Mono repository." - echo -e "* Follow instructions on mono site to install the latest version of Mono." - echo -e " https://www.mono-project.com/download/stable/#download-lin" + monoautoinstall="1" + fi + + # Run the mono repo install. + eval "${cmd}" + + # Did Mono repo install correctly? + if [ "${monoautoinstall}" != "1" ]; then + if [ $? != 0 ]; then + fn_print_failure_nl "Unable to install Mono repository." + fn_script_log_fatal "Unable to install Mono repository." + else + fn_print_complete_nl "Installing Mono repository completed." + fn_script_log_pass "Installing Mono repository completed." + fi + fi + + # Mono can not be auto installed with this distro. + if [ "${monoautoinstall}" == "1" ]; then + fn_print_warning_nl "Mono auto install not available for ${distroname}." + echo -e "Follow instructions on Mono website to install." + echo -e "https://www.mono-project.com/download/stable/#download-lin" + fn_script_log_warn "Unable to install Mono repository. Mono auto install not available for ${distroname}." fi + + else + fn_print_information_nl "Installing Mono repository." + fn_print_warning_nl "$(whoami) does not have sudo access." + echo -e "Follow instructions on Mono website to install." + echo -e "https://www.mono-project.com/download/stable/#download-lin" + fn_script_log_warn "Unable to install Mono repository. $(whoami) does not have sudo access." fi } @@ -127,7 +108,8 @@ fn_deps_email(){ fi } -fn_found_missing_deps(){ +fn_install_missing_deps(){ + # If any dependencies are not installed. if [ "${#array_deps_missing[*]}" != "0" ]; then if [ "${commandname}" == "INSTALL" ]; then fn_print_warning_nl "Missing dependencies: ${red}${array_deps_missing[*]}${default}" @@ -138,15 +120,31 @@ fn_found_missing_deps(){ fn_script_log_warn "Missing dependencies: ${array_deps_missing[*]}" fi fn_sleep_time - if [ -n "${monostatus}" ]; then - fn_install_mono_repo - fi + + # Attempt automatic dependency installation if [ "${autoinstall}" == "1" ]; then sudo -n true > /dev/null 2>&1 else sudo -v > /dev/null 2>&1 fi - if [ $? -eq 0 ]; then + autodepinstall="$?" + + if [ "${commandname}" == "INSTALL" ]; then + if [ "${autodepinstall}" == "0" ]; then + fn_print_information_nl "$(whoami) has sudo access." + fn_script_log_info "$(whoami) has sudo access." + else + fn_print_information_nl "$(whoami) does not have sudo access. Manually install dependencies." + fn_script_log_info "$(whoami) does not have sudo access. Manually install dependencies." + fi + fi + + if [ -n "${monostatus}" ]; then + fn_install_mono_repo + fi + + # If automatic dependency install is available + if [ "${autodepinstall}" == "0" ]; then fn_print_information_nl "Automatically installing missing dependencies." fn_script_log_info "Automatically installing missing dependencies." echo -en ".\r" @@ -166,63 +164,31 @@ fn_found_missing_deps(){ cmd="sudo yum -y install ${array_deps_missing[*]}" eval "${cmd}" fi - if [ $? != 0 ]; then - fn_print_failure_nl "Unable to install dependencies." - fn_script_log_fatal "Unable to install dependencies." - echo -e "" - fn_print_warning_nl "Manually install dependencies." - fn_script_log_warn "Manually install dependencies." - if [ "$(command -v dpkg-query 2>/dev/null)" ]; then - echo -e "sudo dpkg --add-architecture i386; sudo apt update; sudo apt install ${array_deps_missing[*]}" - elif [ "$(command -v dnf 2>/dev/null)" ]; then - echo -e "sudo dnf install ${array_deps_missing[*]}" - elif [ "$(command -v yum 2>/dev/null)" ]; then - echo -e "sudo yum install ${array_deps_missing[*]}" - fi - if [ -n "${steamcmdfail}" ]; then - echo -e "" - if [ "${commandname}" == "INSTALL" ]; then - fn_print_failure_nl "Missing dependencies required to run SteamCMD." - fn_script_log_fatal "Missing dependencies required to run SteamCMD." - core_exit.sh - else - fn_print_error_nl "Missing dependencies required to run SteamCMD." - fn_script_log_error "Missing dependencies required to run SteamCMD." - fi - fi - else - fn_print_complete_nl "Install dependencies completed." - fn_script_log_pass "Install dependencies completed." + autodepinstall="$?" + fi + + # If automatic dependency install is unavailable. + if [ "${autodepinstall}" != "0" ]; then + if [ "$(command -v dpkg-query 2>/dev/null)" ]; then + echo -e "sudo dpkg --add-architecture i386; sudo apt update; sudo apt install ${array_deps_missing[*]}" + elif [ "$(command -v dnf 2>/dev/null)" ]; then + echo -e "sudo dnf install ${array_deps_missing[*]}" + elif [ "$(command -v yum 2>/dev/null)" ]; then + echo -e "sudo yum install ${array_deps_missing[*]}" fi - else + fi + + if [ "${steamcmdfail}" ]; then if [ "${commandname}" == "INSTALL" ]; then - fn_print_warning_nl "$(whoami) does not have sudo access. Manually install dependencies." - fn_script_log_warn "$(whoami) does not have sudo access. Manually install dependencies." - echo -e "" - if [ "$(command -v dpkg-query 2>/dev/null)" ]; then - echo -e "sudo dpkg --add-architecture i386; sudo apt update; sudo apt install ${array_deps_missing[*]}" - elif [ "$(command -v dnf 2>/dev/null)" ]; then - echo -e "sudo dnf install ${array_deps_missing[*]}" - elif [ "$(command -v yum 2>/dev/null)" ]; then - echo -e "sudo yum install ${array_deps_missing[*]}" - fi - fi - if [ "${steamcmdfail}" ]; then - echo -e "" - if [ "${commandname}" == "INSTALL" ]; then - fn_print_failure_nl "Missing dependencies required to run SteamCMD." - fn_script_log_fatal "Missing dependencies required to run SteamCMD." - core_exit.sh - else - fn_print_error_nl "Missing dependencies required to run SteamCMD." - fn_script_log_error "Missing dependencies required to run SteamCMD." - fi + fn_print_failure_nl "Missing dependencies required to run SteamCMD." + fn_script_log_fatal "Missing dependencies required to run SteamCMD." + core_exit.sh + else + fn_print_error_nl "Missing dependencies required to run SteamCMD." + fn_script_log_error "Missing dependencies required to run SteamCMD." fi - echo -e "" - fi - if [ "${commandname}" == "INSTALL" ]; then - sleep 5 fi + else if [ "${commandname}" == "INSTALL" ]; then fn_print_information_nl "Required dependencies already installed." @@ -232,31 +198,31 @@ fn_found_missing_deps(){ } fn_check_loop(){ - # Loop though required depenencies. + # Loop though required depenencies checking if they are installed. for deptocheck in ${array_deps_required[*]}; do fn_deps_detector done - # user to be informed of any missing dependencies. - fn_found_missing_deps + # user eill be informed of any missing dependencies. + fn_install_missing_deps } +# Checks if dependency is installed or not. fn_deps_detector(){ - # Checks if dependency is missing. - # Java: Added for users using Oracle JRE to bypass check. if [ ${deptocheck} == "openjdk-16-jre" ]||[ ${deptocheck} == "java-11-openjdk" ]; then + # Is java already installed? javaversion=$(java -version 2>&1 | grep "version") - if [ "${javaversion}" ]; then - javacheck=1 + if [ -n "${javaversion}" ]; then + javastatus=1 fi fi - if [ "${javacheck}" == "1" ]; then + if [ "${javastatus}" == "1" ]; then # Added for users using Oracle JRE to bypass check. depstatus=0 deptocheck="${javaversion}" - unset javacheck - # Mono + unset javastatus + # Mono: A Mono repo needs to be installed. elif [ "${deptocheck}" == "mono-complete" ]; then if [ "$(command -v mono 2>/dev/null)" ]&&[ "$(mono --version 2>&1 | grep -Po '(?<=version )\d')" -ge 5 ]; then # Mono >= 5.0.0 already installed. @@ -291,7 +257,7 @@ fn_deps_detector(){ fi # Define required dependencies for SteamCMD. if [ -n "${appid}" ]; then - array_steamcmd_deps_required=("${dependencysteamcmd}") + array_steamcmd_deps_required=("${depsteamcmd}") for steamcmddeptocheck in ${array_steamcmd_deps_required[*]}; do if [ "${deptocheck}" == "${steamcmddeptocheck}" ]; then steamcmdfail=1 @@ -333,19 +299,19 @@ fi # If the file successfully downloaded run the dependency check. if [ -f "${datadir}/${distroid}-${distroversion}.csv" ]; then - dependencyinstall=$(awk -F, '$1=="install" {$1=""; print $0}' "${datadir}/${distroid}-${distroversion}.csv") - dependencyall=$(awk -F, '$1=="all" {$1=""; print $0}' "${datadir}/${distroid}-${distroversion}.csv") - dependencysteamcmd=$(awk -F, '$1=="steamcmd" {$1=""; print $0}' "${datadir}/${distroid}-${distroversion}.csv") - dependencyshortname=$(awk -v shortname="$shortname" -F, '$1==shortname {$1=""; print $0}' "${datadir}/${distroid}-${distroversion}.csv") + depinstall=$(awk -F, '$1=="install" {$1=""; print $0}' "${datadir}/${distroid}-${distroversion}.csv") + depall=$(awk -F, '$1=="all" {$1=""; print $0}' "${datadir}/${distroid}-${distroversion}.csv") + depsteamcmd=$(awk -F, '$1=="steamcmd" {$1=""; print $0}' "${datadir}/${distroid}-${distroversion}.csv") + depshortname=$(awk -v shortname="$shortname" -F, '$1==shortname {$1=""; print $0}' "${datadir}/${distroid}-${distroversion}.csv") # Generate array of missing deps. array_deps_missing=() - array_deps_required=("${dependencyall} ${dependencysteamcmd} ${dependencyshortname}") + array_deps_required=("${depall} ${depsteamcmd} ${depshortname}") + fn_deps_email # Unique sort dependency array. IFS=" " read -r -a array_deps_required <<< "$(echo "${array_deps_required[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' ')" - fn_deps_email fn_check_loop # Warn the user that dependency checking is unavailable for their distro. elif [ "${commandname}" == "INSTALL" ]||[ -n "${checkflag}" ]&&[ "${checkflag}" != "0" ]; then @@ -354,7 +320,7 @@ elif [ "${commandname}" == "INSTALL" ]||[ -n "${checkflag}" ]&&[ "${checkflag}" echo "${version}" > "${tmpdir}/dependency-no-check.tmp" elif [ -f "${tmpdir}/dependency-no-check.tmp" ]; then # Allow LinuxGSM to try a dependency check if LinuxGSM has been recently updated. - nocheckversion=$(cat "${tmpdir}/dependency-no-check.tmp" ) + nocheckversion=$(cat "${tmpdir}/dependency-no-check.tmp") if [ "${version}" != "${nocheckversion}" ]; then rm -f "${tmpdir:?}/dependency-no-check.tmp" fi