diff options
-rwxr-xr-x | packaging/installer/install-required-packages.sh | 2596 |
1 files changed, 1260 insertions, 1336 deletions
diff --git a/packaging/installer/install-required-packages.sh b/packaging/installer/install-required-packages.sh index f7083eae11..11dd70025d 100755 --- a/packaging/installer/install-required-packages.sh +++ b/packaging/installer/install-required-packages.sh @@ -4,14 +4,13 @@ export PATH="${PATH}:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbi export LC_ALL=C # Be nice on production environments -renice 19 $$ >/dev/null 2>/dev/null +renice 19 $$ > /dev/null 2> /dev/null ME="${0}" -if [ "${BASH_VERSINFO[0]}" -lt "4" ] -then - echo >&2 "Sorry! This script needs BASH version 4+, but you have BASH version ${BASH_VERSION}" - exit 1 +if [ "${BASH_VERSINFO[0]}" -lt "4" ]; then + echo >&2 "Sorry! This script needs BASH version 4+, but you have BASH version ${BASH_VERSION}" + exit 1 fi # These options control which packages we are going to install @@ -33,17 +32,17 @@ PACKAGES_NETDATA_SENSORS=${PACKAGES_NETDATA_SENSORS-0} PACKAGES_NETDATA_DATABASE=${PACKAGES_NETDATA_DATABASE-0} # needed commands -lsb_release=$(which lsb_release 2>/dev/null || command -v lsb_release 2>/dev/null) +lsb_release=$(which lsb_release 2> /dev/null || command -v lsb_release 2> /dev/null) # Check which package managers are available -apk=$(which apk 2>/dev/null || command -v apk 2>/dev/null) -apt_get=$(which apt-get 2>/dev/null || command -v apt-get 2>/dev/null) -dnf=$(which dnf 2>/dev/null || command -v dnf 2>/dev/null) -emerge=$(which emerge 2>/dev/null || command -v emerge 2>/dev/null) -equo=$(which equo 2>/dev/null || command -v equo 2>/dev/null) -pacman=$(which pacman 2>/dev/null || command -v pacman 2>/dev/null) -yum=$(which yum 2>/dev/null || command -v yum 2>/dev/null) -zypper=$(which zypper 2>/dev/null || command -v zypper 2>/dev/null) +apk=$(which apk 2> /dev/null || command -v apk 2> /dev/null) +apt_get=$(which apt-get 2> /dev/null || command -v apt-get 2> /dev/null) +dnf=$(which dnf 2> /dev/null || command -v dnf 2> /dev/null) +emerge=$(which emerge 2> /dev/null || command -v emerge 2> /dev/null) +equo=$(which equo 2> /dev/null || command -v equo 2> /dev/null) +pacman=$(which pacman 2> /dev/null || command -v pacman 2> /dev/null) +yum=$(which yum 2> /dev/null || command -v yum 2> /dev/null) +zypper=$(which zypper 2> /dev/null || command -v zypper 2> /dev/null) distribution= version= @@ -58,7 +57,7 @@ VERSION= VERSION_ID= usage() { - cat <<EOF + cat << EOF OPTIONS: ${ME} [--dont-wait] [--non-interactive] \\ @@ -129,1282 +128,1219 @@ EOF } release2lsb_release() { - # loads the given /etc/x-release file - # this file is normaly a single line containing something like - # - # X Linux release 1.2.3 (release-name) - # - # It attempts to parse it - # If it succeeds, it returns 0 - # otherwise it returns 1 - - local file="${1}" x DISTRIB_ID= DISTRIB_RELEASE= DISTRIB_CODENAME= DISTRIB_DESCRIPTION= - echo >&2 "Loading ${file} ..." - - - x="$(cat "${file}" | grep -v "^$" | head -n 1)" - - if [[ "${x}" =~ ^.*[[:space:]]+Linux[[:space:]]+release[[:space:]]+.*[[:space:]]+(.*)[[:space:]]*$ ]] - then - eval "$(echo "${x}" | sed "s|^\(.*\)[[:space:]]\+Linux[[:space:]]\+release[[:space:]]\+\(.*\)[[:space:]]\+(\(.*\))[[:space:]]*$|DISTRIB_ID=\"\1\"\nDISTRIB_RELEASE=\"\2\"\nDISTRIB_CODENAME=\"\3\"|g" | grep "^DISTRIB")" - elif [[ "${x}" =~ ^.*[[:space:]]+Linux[[:space:]]+release[[:space:]]+.*[[:space:]]+$ ]] - then - eval "$(echo "${x}" | sed "s|^\(.*\)[[:space:]]\+Linux[[:space:]]\+release[[:space:]]\+\(.*\)[[:space:]]*$|DISTRIB_ID=\"\1\"\nDISTRIB_RELEASE=\"\2\"|g" | grep "^DISTRIB")" - elif [[ "${x}" =~ ^.*[[:space:]]+release[[:space:]]+.*[[:space:]]+(.*)[[:space:]]*$ ]] - then - eval "$(echo "${x}" | sed "s|^\(.*\)[[:space:]]\+release[[:space:]]\+\(.*\)[[:space:]]\+(\(.*\))[[:space:]]*$|DISTRIB_ID=\"\1\"\nDISTRIB_RELEASE=\"\2\"\nDISTRIB_CODENAME=\"\3\"|g" | grep "^DISTRIB")" - elif [[ "${x}" =~ ^.*[[:space:]]+release[[:space:]]+.*[[:space:]]+$ ]] - then - eval "$(echo "${x}" | sed "s|^\(.*\)[[:space:]]\+release[[:space:]]\+\(.*\)[[:space:]]*$|DISTRIB_ID=\"\1\"\nDISTRIB_RELEASE=\"\2\"|g" | grep "^DISTRIB")" - fi - - distribution="${DISTRIB_ID}" - version="${DISTRIB_RELEASE}" - codename="${DISTRIB_CODENAME}" - - [ -z "${distribution}" ] && echo >&2 "Cannot parse this lsb-release: ${x}" && return 1 - detection="${file}" - return 0 + # loads the given /etc/x-release file + # this file is normaly a single line containing something like + # + # X Linux release 1.2.3 (release-name) + # + # It attempts to parse it + # If it succeeds, it returns 0 + # otherwise it returns 1 + + local file="${1}" x DISTRIB_ID= DISTRIB_RELEASE= DISTRIB_CODENAME= DISTRIB_DESCRIPTION= + echo >&2 "Loading ${file} ..." + + x="$(cat "${file}" | grep -v "^$" | head -n 1)" + + if [[ "${x}" =~ ^.*[[:space:]]+Linux[[:space:]]+release[[:space:]]+.*[[:space:]]+(.*)[[:space:]]*$ ]]; then + eval "$(echo "${x}" | sed "s|^\(.*\)[[:space:]]\+Linux[[:space:]]\+release[[:space:]]\+\(.*\)[[:space:]]\+(\(.*\))[[:space:]]*$|DISTRIB_ID=\"\1\"\nDISTRIB_RELEASE=\"\2\"\nDISTRIB_CODENAME=\"\3\"|g" | grep "^DISTRIB")" + elif [[ "${x}" =~ ^.*[[:space:]]+Linux[[:space:]]+release[[:space:]]+.*[[:space:]]+$ ]]; then + eval "$(echo "${x}" | sed "s|^\(.*\)[[:space:]]\+Linux[[:space:]]\+release[[:space:]]\+\(.*\)[[:space:]]*$|DISTRIB_ID=\"\1\"\nDISTRIB_RELEASE=\"\2\"|g" | grep "^DISTRIB")" + elif [[ "${x}" =~ ^.*[[:space:]]+release[[:space:]]+.*[[:space:]]+(.*)[[:space:]]*$ ]]; then + eval "$(echo "${x}" | sed "s|^\(.*\)[[:space:]]\+release[[:space:]]\+\(.*\)[[:space:]]\+(\(.*\))[[:space:]]*$|DISTRIB_ID=\"\1\"\nDISTRIB_RELEASE=\"\2\"\nDISTRIB_CODENAME=\"\3\"|g" | grep "^DISTRIB")" + elif [[ "${x}" =~ ^.*[[:space:]]+release[[:space:]]+.*[[:space:]]+$ ]]; then + eval "$(echo "${x}" | sed "s|^\(.*\)[[:space:]]\+release[[:space:]]\+\(.*\)[[:space:]]*$|DISTRIB_ID=\"\1\"\nDISTRIB_RELEASE=\"\2\"|g" | grep "^DISTRIB")" + fi + + distribution="${DISTRIB_ID}" + version="${DISTRIB_RELEASE}" + codename="${DISTRIB_CODENAME}" + + [ -z "${distribution}" ] && echo >&2 "Cannot parse this lsb-release: ${x}" && return 1 + detection="${file}" + return 0 } get_os_release() { - # Loads the /etc/os-release file - # Only the required fields are loaded - # - # If it manages to load /etc/os-release, it returns 0 - # otherwise it returns 1 - # - # It searches the ID_LIKE field for a compatible distribution - - local x - if [ -f "/etc/os-release" ] - then - echo >&2 "Loading /etc/os-release ..." - - eval "$(cat /etc/os-release | grep -E "^(NAME|ID|ID_LIKE|VERSION|VERSION_ID)=")" - for x in "${ID}" ${ID_LIKE} - do - case "${x,,}" in - alpine|arch|centos|debian|fedora|gentoo|sabayon|rhel|ubuntu|suse|opensuse-leap|sles) - distribution="${x}" - version="${VERSION_ID}" - codename="${VERSION}" - detection="/etc/os-release" - break - ;; - *) - echo >&2 "Unknown distribution ID: ${x}" - ;; - esac - done - [ -z "${distribution}" ] && echo >&2 "Cannot find valid distribution in: ${ID} ${ID_LIKE}" && return 1 - else - echo >&2 "Cannot find /etc/os-release" && return 1 - fi - - [ -z "${distribution}" ] && return 1 - return 0 + # Loads the /etc/os-release file + # Only the required fields are loaded + # + # If it manages to load /etc/os-release, it returns 0 + # otherwise it returns 1 + # + # It searches the ID_LIKE field for a compatible distribution + + local x + if [ -f "/etc/os-release" ]; then + echo >&2 "Loading /etc/os-release ..." + + eval "$(cat /etc/os-release | grep -E "^(NAME|ID|ID_LIKE|VERSION|VERSION_ID)=")" + for x in "${ID}" ${ID_LIKE}; do + case "${x,,}" in + alpine | arch | centos | debian | fedora | gentoo | sabayon | rhel | ubuntu | suse | opensuse-leap | sles) + distribution="${x}" + version="${VERSION_ID}" + codename="${VERSION}" + detection="/etc/os-release" + break + ;; + *) + echo >&2 "Unknown distribution ID: ${x}" + ;; + esac + done + [ -z "${distribution}" ] && echo >&2 "Cannot find valid distribution in: ${ID} ${ID_LIKE}" && return 1 + else + echo >&2 "Cannot find /etc/os-release" && return 1 + fi + + [ -z "${distribution}" ] && return 1 + return 0 } get_lsb_release() { - # Loads the /etc/lsb-release file - # If it fails, it attempts to run the command: lsb_release -a - # and parse its output - # - # If it manages to find the lsb-release, it returns 0 - # otherwise it returns 1 - - if [ -f "/etc/lsb-release" ] - then - echo >&2 "Loading /etc/lsb-release ..." - local DISTRIB_ID= ISTRIB_RELEASE= DISTRIB_CODENAME= DISTRIB_DESCRIPTION= - eval "$(cat /etc/lsb-release | grep -E "^(DISTRIB_ID|DISTRIB_RELEASE|DISTRIB_CODENAME)=")" - distribution="${DISTRIB_ID}" - version="${DISTRIB_RELEASE}" - codename="${DISTRIB_CODENAME}" - detection="/etc/lsb-release" - fi - - if [ -z "${distribution}" -a ! -z "${lsb_release}" ] - then - echo >&2 "Cannot find distribution with /etc/lsb-release" - echo >&2 "Running command: lsb_release ..." - eval "declare -A release=( $(lsb_release -a 2>/dev/null | sed -e "s|^\(.*\):[[:space:]]*\(.*\)$|[\1]=\"\2\"|g") )" - distribution="${release[Distributor ID]}" - version="${release[Release]}" - codename="${release[Codename]}" - detection="lsb_release" - fi - - [ -z "${distribution}" ] && echo >&2 "Cannot find valid distribution with lsb-release" && return 1 - return 0 + # Loads the /etc/lsb-release file + # If it fails, it attempts to run the command: lsb_release -a + # and parse its output + # + # If it manages to find the lsb-release, it returns 0 + # otherwise it returns 1 + + if [ -f "/etc/lsb-release" ]; then + echo >&2 "Loading /etc/lsb-release ..." + local DISTRIB_ID= ISTRIB_RELEASE= DISTRIB_CODENAME= DISTRIB_DESCRIPTION= + eval "$(cat /etc/lsb-release | grep -E "^(DISTRIB_ID|DISTRIB_RELEASE|DISTRIB_CODENAME)=")" + distribution="${DISTRIB_ID}" + version="${DISTRIB_RELEASE}" + codename="${DISTRIB_CODENAME}" + detection="/etc/lsb-release" + fi + + if [ -z "${distribution}" -a ! -z "${lsb_release}" ]; then + echo >&2 "Cannot find distribution with /etc/lsb-release" + echo >&2 "Running command: lsb_release ..." + eval "declare -A release=( $(lsb_release -a 2> /dev/null | sed -e "s|^\(.*\):[[:space:]]*\(.*\)$|[\1]=\"\2\"|g") )" + distribution="${release["Distributor ID"]}" + version="${release[Release]}" + codename="${release[Codename]}" + detection="lsb_release" + fi + + [ -z "${distribution}" ] && echo >&2 "Cannot find valid distribution with lsb-release" && return 1 + return 0 } find_etc_any_release() { - # Check for any of the known /etc/x-release files - # If it finds one, it loads it and returns 0 - # otherwise it returns 1 - - if [ -f "/etc/arch-release" ] - then - release2lsb_release "/etc/arch-release" && return 0 - fi - - if [ -f "/etc/centos-release" ] - then - release2lsb_release "/etc/centos-release" && return 0 - fi - - if [ -f "/etc/redhat-release" ] - then - release2lsb_release "/etc/redhat-release" && return 0 - fi - - if [ -f "/etc/SuSe-release" ] - then - release2lsb_release "/etc/SuSe-release" && return 0 - fi - - return 1 + # Check for any of the known /etc/x-release files + # If it finds one, it loads it and returns 0 + # otherwise it returns 1 + + if [ -f "/etc/arch-release" ]; then + release2lsb_release "/etc/arch-release" && return 0 + fi + + if [ -f "/etc/centos-release" ]; then + release2lsb_release "/etc/centos-release" && return 0 + fi + + if [ -f "/etc/redhat-release" ]; then + release2lsb_release "/etc/redhat-release" && return 0 + fi + + if [ -f "/etc/SuSe-release" ]; then + release2lsb_release "/etc/SuSe-release" && return 0 + fi + + return 1 } autodetect_distribution() { - # autodetection of distribution - get_os_release || get_lsb_release || find_etc_any_release + # autodetection of distribution + get_os_release || get_lsb_release || find_etc_any_release } user_picks_distribution() { - # let the user pick a distribution - - echo >&2 - echo >&2 "I NEED YOUR HELP" - echo >&2 "It seems I cannot detect your system automatically." - if [ -z "${equo}" -a -z "${emerge}" -a -z "${apt_get}" -a -z "${yum}" -a -z "${dnf}" -a -z "${pacman}" -a -z "${apk}" ] - then - echo >&2 "And it seems I cannot find a known package manager in this system." - echo >&2 "Please open a github issue to help us support your system too." - exit 1 - fi - - local opts= - echo >&2 "I found though that the following installers are available:" - echo >&2 - [ ! -z "${apt_get}" ] && echo >&2 " - Debian/Ubuntu based (installer is: apt-get)" && opts="apt-get ${opts}" - [ ! -z "${yum}" ] && echo >&2 " - Redhat/Fedora/Centos based (installer is: yum)" && opts="yum ${opts}" - [ ! -z "${dnf}" ] && echo >&2 " - Redhat/Fedora/Centos based (installer is: dnf)" && opts="dnf ${opts}" - [ ! -z "${zypper}" ] && echo >&2 " - SuSe based (installer is: zypper)" && opts="zypper ${opts}" - [ ! -z "${pacman}" ] && echo >&2 " - Arch Linux based (installer is: pacman)" && opts="pacman ${opts}" - [ ! -z "${emerge}" ] && echo >&2 " - Gentoo based (installer is: emerge)" && opts="emerge ${opts}" - [ ! -z "${equo}" ] && echo >&2 " - Sabayon based (installer is: equo)" && opts="equo ${opts}" - [ ! -z "${apk}" ] && echo >&2 " - Alpine Linux based (installer is: apk)" && opts="apk ${opts}" - echo >&2 - - REPLY= - while [ -z "${REPLY}" ] - do - echo "To proceed please write one of these:" - echo "${opts}" | sed -e 's/ /, /g' - read -p ">" REPLY - [ $? -ne 0 ] && REPLY= && continue - - if [ "${REPLY}" = "yum" -a -z "${distribution}" ] - then - REPLY= - while [ -z "${REPLY}" ] - do - read -p "yum in centos, rhel or fedora? > " - [ $? -ne 0 ] && continue - - case "${REPLY,,}" in - fedora|rhel) - distribution="rhel" - ;; - centos) - distribution="centos" - ;; - *) - echo >&2 "Please enter 'centos', 'fedora' or 'rhel'." - REPLY= - ;; - esac - done - REPLY="yum" - fi - check_package_manager "${REPLY}" || REPLY= - done + # let the user pick a distribution + + echo >&2 + echo >&2 "I NEED YOUR HELP" + echo >&2 "It seems I cannot detect your system automatically." + if [ -z "${equo}" -a -z "${emerge}" -a -z "${apt_get}" -a -z "${yum}" -a -z "${dnf}" -a -z "${pacman}" -a -z "${apk}" ]; then + echo >&2 "And it seems I cannot find a known package manager in this system." + echo >&2 "Please open a github issue to help us support your system too." + exit 1 + fi + + local opts= + echo >&2 "I found though that the following installers are available:" + echo >&2 + [ ! -z "${apt_get}" ] && echo >&2 " - Debian/Ubuntu based (installer is: apt-get)" && opts="apt-get ${opts}" + [ ! -z "${yum}" ] && echo >&2 " - Redhat/Fedora/Centos based (installer is: yum)" && opts="yum ${opts}" + [ ! -z "${dnf}" ] && echo >&2 " - Redhat/Fedora/Centos based (installer is: dnf)" && opts="dnf ${opts}" + [ ! -z "${zypper}" ] && echo >&2 " - SuSe based (installer is: zypper)" && opts="zypper ${opts}" + [ ! -z "${pacman}" ] && echo >&2 " - Arch Linux based (installer is: pacman)" && opts="pacman ${opts}" + [ ! -z "${emerge}" ] && echo >&2 " - Gentoo based (installer is: emerge)" && opts="emerge ${opts}" + [ ! -z "${equo}" ] && echo >&2 " - Sabayon based (installer is: equo)" && opts="equo ${opts}" + [ ! -z "${apk}" ] && echo >&2 " - Alpine Linux based (installer is: apk)" && opts="apk ${opts}" + echo >&2 + + REPLY= + while [ -z "${REPLY}" ]; do + echo "To proceed please write one of these:" + echo "${opts}" | sed -e 's/ /, /g' + read -p ">" REPLY + [ $? -ne 0 ] && REPLY= && continue + + if [ "${REPLY}" = "yum" -a -z "${distribution}" ]; then + REPLY= + while [ -z "${REPLY}" ]; do + read -p "yum in centos, rhel or fedora? > " + [ $? -ne 0 ] && continue + + case "${REPLY,,}" in + fedora | rhel) + distribution="rhel" + ;; + centos) + distribution="centos" + ;; + *) + echo >&2 "Please enter 'centos', 'fedora' or 'rhel'." + REPLY= + ;; + esac + done + REPLY="yum" + fi + check_package_manager "${REPLY}" || REPLY= + done } detect_package_manager_from_distribution() { - case "${1,,}" in - arch*|manjaro*) - package_installer="install_pacman" - tree="arch" - if [ ${IGNORE_INSTALLED} -eq 0 -a -z "${pacman}" ] - then - echo >&2 "command 'pacman' is required to install packages on a '${distribution} ${version}' system." - exit 1 - fi - ;; - - sabayon*) - package_installer="install_equo" - tree="sabayon" - if [ ${IGNORE_INSTALLED} -eq 0 -a -z "${equo}" ] - then - echo >&2 "command 'equo' is required to install packages on a '${distribution} ${version}' system." - # Maybe offer to fall back on emerge? Both installers exist in Sabayon... - exit 1 - fi - ;; - - alpine*) - package_installer="install_apk" - tree="alpine" - if [ ${IGNORE_INSTALLED} -eq 0 -a -z "${apk}" ] - then - echo >&2 "command 'apk' is required to install packages on a '${distribution} ${version}' system." - exit 1 - fi - ;; - - gentoo*) - package_installer="install_emerge" - tree="gentoo" - if [ ${IGNORE_INSTALLED} -eq 0 -a -z "${emerge}" ] - then - echo >&2 "command 'emerge' is required to install packages on a '${distribution} ${version}' system." - exit 1 - fi - ;; - - debian*|ubuntu*) - package_installer="install_apt_get" - tree="debian" - if [ ${IGNORE_INSTALLED} -eq 0 -a -z "${apt_get}" ] - then - echo >&2 "command 'apt-get' is required to install packages on a '${distribution} ${version}' system." - exit 1 - fi - ;; - - centos*|clearos*) - echo >&2 "You should have EPEL enabled to install all the prerequisites." - echo >&2 "Check: http://www.tecmint.com/how-to-enable-epel-repository-for-rhel-centos-6-5/" - package_installer="install_yum" - tree="centos" - if [ ${IGNORE_INSTALLED} -eq 0 -a -z "${yum}" ] - then - echo >&2 "command 'yum' is required to install packages on a '${distribution} ${version}' system." - exit 1 - fi - ;; - - fedora*|redhat*|red\ hat*|rhel*) - package_installer= - tree="rhel" - [ ! -z "${yum}" ] && package_installer="install_yum" - [ ! -z "${dnf}" ] && package_installer="install_dnf" - if [ ${IGNORE_INSTALLED} -eq 0 -a -z "${package_installer}" ] - then - echo >&2 "command 'yum' or 'dnf' is required to install packages on a '${distribution} ${version}' system." - exit 1 - fi - ;; - - suse*|opensuse*|sles*) - package_installer="install_zypper" - tree="suse" - if [ ${IGNORE_INSTALLED} -eq 0 -a -z "${zypper}" ] - then - echo >&2 "command 'zypper' is required to install packages on a '${distribution} ${version}' system." - exit 1 - fi - ;; - - *) - # oops! unknown system - user_picks_distribution - ;; - esac + case "${1,,}" in + arch* | manjaro*) + package_installer="install_pacman" + tree="arch" + if [ ${IGNORE_INSTALLED} -eq 0 -a -z "${pacman}" ]; then + echo >&2 "command 'pacman' is required to install packages on a '${distribution} ${version}' system." + exit 1 + fi + ;; + + sabayon*) + package_installer="install_equo" + tree="sabayon" + if [ ${IGNORE_INSTALLED} -eq 0 -a -z "${equo}" ]; then + echo >&2 "command 'equo' is required to install packages on a '${distribution} ${version}' system." + # Maybe offer to fall back on emerge? Both installers exist in Sabayon... + exit 1 + fi + ;; + + alpine*) + package_installer="install_apk" + tree="alpine" + if [ ${IGNORE_INSTALLED} -eq 0 -a -z "${apk}" ]; then + echo >&2 "command 'apk' is required to install packages on a '${distribution} ${version}' system." + exit 1 + fi + ;; + + gentoo*) + package_installer="install_emerge" + tree="gentoo" + if [ ${IGNORE_INSTALLED} -eq 0 -a -z "${emerge}" ]; then + echo >&2 "command 'emerge' is required to install packages on a '${distribution} ${version}' system." + exit 1 + fi + ;; + + debian* | ubuntu*) + package_installer="install_apt_get" + tree="debian" + if [ ${IGNORE_INSTALLED} -eq 0 -a -z "${apt_get}" ]; then + echo >&2 "command 'apt-get' is required to install packages on a '${distribution} ${version}' system." + exit 1 + fi + ;; + + centos* | clearos*) + echo >&2 "You should have EPEL enabled to install all the prerequisites." + echo >&2 "Check: http://www.tecmint.com/how-to-enable-epel-repository-for-rhel-centos-6-5/" + package_installer="install_yum" + tree="centos" + if [ ${IGNORE_INSTALLED} -eq 0 -a -z "${yum}" ]; then + echo >&2 "command 'yum' is required to install packages on a '${distribution} ${version}' system." + exit 1 + fi + ;; + + fedora* | redhat* | red\ hat* | rhel*) + package_installer= + tree="rhel" + [ ! -z "${yum}" ] && package_installer="install_yum" + [ ! -z "${dnf}" ] && package_installer="install_dnf" + if [ ${IGNORE_INSTALLED} -eq 0 -a -z "${package_installer}" ]; then + echo >&2 "command 'yum' or 'dnf' is required to install packages on a '${distribution} ${version}' system." + exit 1 + fi + ;; + + suse* | opensuse* | sles*) + package_installer="install_zypper" + tree="suse" + if [ ${IGNORE_INSTALLED} -eq 0 -a -z "${zypper}" ]; then + echo >&2 "command 'zypper' is required to install packages on a '${distribution} ${version}' system." + exit 1 + fi + ;; + + *) + # oops! unknown system + user_picks_distribution + ;; + esac } check_package_manager() { - # This is called only when the user is selecting a package manager - # It is used to verify the user selection is right - - echo >&2 "Checking package manager: ${1}" - - case "${1}" in - apt-get) - [ ${IGNORE_INSTALLED} -eq 0 -a -z "${apt_get}" ] && echo >&2 "${1} is not available." && return 1 - package_installer="install_apt_get" - tree="debian" - detection="user-input" - return 0 - ;; - - dnf) - [ ${IGNORE_INSTALLED} -eq 0 -a -z "${dnf}" ] && echo >&2 "${1} is not available." && return 1 - package_installer="install_dnf" - tree="rhel" - detection="user-input" - return 0 - ;; - - apk) - [ ${IGNORE_INSTALLED} -eq 0 -a -z "${apk}" ] && echo >&2 "${1} is not available." && return 1 - package_installer="install_apk" - tree="alpine" - detection="user-input" - return 0 - ;; - - equo) - [ ${IGNORE_INSTALLED} -eq 0 -a -z "${equo}" ] && echo >&2 "${1} is not available." && return 1 - package_installer="install_equo" - tree="sabayon" - detection="user-input" - return 0 - ;; - - emerge) - [ ${IGNORE_INSTALLED} -eq 0 -a -z "${emerge}" ] && echo >&2 "${1} is not available." && return 1 - package_installer="install_emerge" - tree="gentoo" - detection="user-input" - return 0 - ;; - - pacman) - [ ${IGNORE_INSTALLED} -eq 0 -a -z "${pacman}" ] && echo >&2 "${1} is not available." && return 1 - package_installer="install_pacman" - tree="arch" - detection="user-input" - - return 0 - ;; - - zypper) - [ ${IGNORE_INSTALLED} -eq 0 -a -z "${zypper}" ] && echo >&2 "${1} is not available." && return 1 - package_installer="install_zypper" - tree="suse" - detection="user-input" - return 0 - ;; - - yum) - [ ${IGNORE_INSTALLED} -eq 0 -a -z "${yum}" ] && echo >&2 "${1} is not available." && return 1 - package_installer="install_yum" - if [ "${distribution}" = "centos" ] - then - tree="centos" - else - tree="rhel" - fi - detection="user-input" - return 0 - ;; - - *) - echo >&2 "Invalid package manager: '${1}'." - return 1 - ;; - esac + # This is called only when the user is selecting a package manager + # It is used to verify the user selection is right + + echo >&2 "Checking package manager: ${1}" + + case "${1}" in + apt-get) + [ ${IGNORE_INSTALLED} -eq 0 -a -z "${apt_get}" ] && echo >&2 "${1} is not available." && return 1 + package_installer="install_apt_get" + tree="debian" + detection="user-input" + return 0 + ;; + + dnf) + [ ${IGNORE_INSTALLED} -eq 0 -a -z "${dnf}" ] && echo >&2 "${1} is not available." && return 1 + package_installer="install_dnf" + tree="rhel" + detection="user-input" + return 0 + ;; + + apk) + [ ${IGNORE_INSTALLED} -eq 0 -a -z "${apk}" ] && echo >&2 "${1} is not available." && return 1 + package_installer="install_apk" + tree="alpine" + detection="user-input" + return 0 + ;; + + equo) + [ ${IGNORE_INSTALLED} -eq 0 -a -z "${equo}" ] && echo >&2 "${1} is not available." && return 1 + package_installer="install_equo" + tree="sabayon" + detection="user-input" + return 0 + ;; + + emerge) + [ ${IGNORE_INSTALLED} -eq 0 -a -z "${emerge}" ] && echo >&2 "${1} is not available." && return 1 + package_installer="install_emerge" + tree="gentoo" + detection="user-input" + return 0 + ;; + + pacman) + [ ${IGNORE_INSTALLED} -eq 0 -a -z "${pacman}" ] && echo >&2 "${1} is not available." && return 1 + package_installer="install_pacman" + tree="arch" + detection="user-input" + + return 0 + ;; + + zypper) + [ ${IGNORE_INSTALLED} -eq 0 -a -z "${zypper}" ] && echo >&2 "${1} is not available." && return 1 + package_installer="install_zypper" + tree="suse" + detection="user-input" + return 0 + ;; + + yum) + [ ${IGNORE_INSTALLED} -eq 0 -a -z "${yum}" ] && echo >&2 "${1} is not available." && return 1 + package_installer="install_yum" + if [ "${distribution}" = "centos" ]; then + tree="centos" + else + tree="rhel" + fi + detection="user-input" + return 0 + ;; + + *) + echo >&2 "Invalid package manager: '${1}'." + return 1 + ;; + esac } require_cmd() { - # check if any of the commands given as argument - # are present on this system - # If any of them is available, it returns 0 - # otherwise 1 - - [ ${IGNORE_INSTALLED} -eq 1 ] && return 1 - - local wanted found - for wanted in "${@}" - do - found="$(which "${wanted}" 2>/dev/null)" - [ -z "${found}" ] && found="$(command -v "${wanted}" 2>/dev/null)" - [ ! -z "${found}" -a -x "${found}" ] && return 0 - done - - return 1 + # check if any of the commands given as argument + # are present on this system + # If any of them is available, it returns 0 + # otherwise 1 + + [ ${IGNORE_INSTALLED} -eq 1 ] && return 1 + + local wanted found + for wanted in "${@}"; do + found="$(which "${wanted}" 2> /dev/null)" + [ -z "${found}" ] && found="$(command -v "${wanted}" 2> /dev/null)" + [ ! -z "${found}" -a -x "${found}" ] && return 0 + done + + return 1 } declare -A pkg_find=( - ['fedora']="findutils" - ['default']="WARNING|" + ['fedora']="findutils" + ['default']="WARNING|" ) declare -A pkg_distro_sdk=( - ['alpine']="alpine-sdk" - ['default']="NOTREQUIRED" - ) + ['alpine']="alpine-sdk" + ['default']="NOTREQUIRED" +) declare -A pkg_autoconf=( - ['gentoo']="sys-devel/autoconf" - ['default']="autoconf" - ) + ['gentoo']="sys-devel/autoconf" + ['default']="autoconf" +) # required to compile netdata with --enable-sse # https://github.com/firehol/netdata/pull/450 declare -A pkg_autoconf_archive=( - ['gentoo']="sys-devel/autoconf-archive" - ['alpine']="WARNING|" - ['default']="autoconf-archive" - - # exceptions - ['centos-6']="WARNING|" - ['rhel-6']="WARNING|" - ['rhel-7']="WARNING|" - ) + ['gentoo']="sys-devel/autoconf-archive" + ['alpine']="WARNING|" + ['default']="autoconf-archive" + + # exceptions + ['centos-6']="WARNING|" + ['rhel-6']="WARNING|" + ['rhel-7']="WARNING|" +) declare -A pkg_autogen=( - ['gentoo']="sys-devel/autogen" - ['alpine']="WARNING|" - ['default']="autogen" - - # exceptions - ['centos-6']="WARNING|" - ['rhel-6']="WARNING|" - ['ubuntu-18']="WARNING|" - ) + ['gentoo']="sys-devel/autogen" + ['alpine']="WARNING|" + ['default']="autogen" + + # exceptions + ['centos-6']="WARNING|" + ['rhel-6']="WARNING|" + ['ubuntu-18']="WARNING|" +) declare -A pkg_automake=( - ['gentoo']="sys-devel/automake" - ['default']="automake" - ) + ['gentoo']="sys-devel/automake" + ['default']="automake" +) declare -A pkg_bridge_utils=( - ['gentoo']="net-misc/bridge-utils" - ['default']="bridge-utils" - ) + ['gentoo']="net-misc/bridge-utils" + ['default']="bridge-utils" +) declare -A pkg_chrony=( - ['default']="chrony" - ) + ['default']="chrony" +) declare -A pkg_curl=( - ['gentoo']="net-misc/curl" - ['sabayon']="net-misc/curl" - ['default']="curl" - ) + ['gentoo']="net-misc/curl" + ['sabayon']="net-misc/curl" + ['default']="curl" +) declare -A pkg_gzip=( - ['default']="gzip" + ['default']="gzip" ) declare -A pkg_tar=( - ['default']="tar" - ) + ['default']="tar" +) declare -A pkg_git=( - ['gentoo']="dev-vcs/git" - ['default']="git" - ) + ['gentoo']="dev-vcs/git" + ['default']="git" +) declare -A pkg_gcc=( - ['gentoo']="sys-devel/gcc" - ['default']="gcc" - ) + ['gentoo']="sys-devel/gcc" + ['default']="gcc" +) declare -A pkg_gdb=( - ['gentoo']="sys-devel/gdb" - ['default']="gdb" - ) + ['gentoo']="sys-devel/gdb" + ['default']="gdb" +) declare -A pkg_iotop=( - ['default']="iotop" - ) + ['default']="iotop" +) declare -A pkg_iproute2=( - ['alpine']="iproute2" - ['debian']="iproute2" - ['gentoo']="sys-apps/iproute2" - ['sabayon']="sys-apps/iproute2" - ['default']="iproute" - - # exceptions - ['ubuntu-12.04']="iproute" - ) + ['alpine']="iproute2" + ['debian']="iproute2" + ['gentoo']="sys-apps/iproute2" + ['sabayon']="sys-apps/iproute2" + ['default']="iproute" + + # exceptions + ['ubuntu-12.04']="iproute" +) declare -A pkg_ipset=( - ['gentoo']="net-firewall/ipset" - ['default']="ipset" - ) + ['gentoo']="net-firewall/ipset" + ['default']="ipset" +) declare -A pkg_jq=( - ['gentoo']="app-misc/jq" - ['default']="jq" - ) + ['gentoo']="app-misc/jq" + ['default']="jq" +) declare -A pkg_iptables=( - ['gentoo']="net-firewall/iptables" - ['default']="iptables" - ) + ['gentoo']="net-firewall/iptables" + ['default']="iptables" +) declare -A pkg_libz_dev=( - ['alpine']="zlib-dev" - ['arch']="zlib" - ['centos']="zlib-devel" - ['debian']="zlib1g-dev" - ['gentoo']="sys-libs/zlib" - ['sabayon']="sys-libs/zlib" - ['rhel']="zlib-devel" - ['suse']="zlib-devel" - ['default']="" - ) + ['alpine']="zlib-dev" + ['arch']="zlib" + ['centos']="zlib-devel" + ['debian']="zlib1g-dev" + ['gentoo']="sys-libs/zlib" + ['sabayon']="sys-libs/zlib" + ['rhel']="zlib-devel" + ['suse']="zlib-devel" + ['default']="" +) declare -A pkg_libuuid_dev=( - ['alpine']="util-linux-dev" - ['arch']="util-linux" - ['centos']="libuuid-devel" - ['debian']="uuid-dev" - ['gentoo']="sys-apps/util-linux" - ['sabayon']="sys-apps/util-linux" - ['rhel']="libuuid-devel" - ['suse']="libuuid-devel" - ['default']="" - ) + ['alpine']="util-linux-dev" + ['arch']="util-linux" + ['centos']="libuuid-devel" + ['debian']="uuid-dev" + ['gentoo']="sys-apps/util-linux" + ['sabayon']="sys-apps/util-linux" + ['rhel']="libuuid-devel" + ['suse']="libuuid-devel" + ['default']="" +) declare -A pkg_libmnl_dev=( - ['alpine']="libmnl-dev" - ['arch']="libmnl" - ['centos']="libmnl-devel" - ['debian']="libmnl-dev" - ['gentoo']="net-libs/libmnl" - ['sabayon']="net-libs/libmnl" - ['rhel']="libmnl-devel" - ['suse']="libmnl-devel" - ['default']="" - ) + ['alpine']="libmnl-dev" + ['arch']="libmnl" + ['centos']="libmnl-devel" + ['debian']="libmnl-dev" + ['gentoo']="net-libs/libmnl" + ['sabayon']="net-libs/libmnl" + ['rhel']="libmnl-devel" + ['suse']="libmnl-devel" + ['default']="" +) declare -A pkg_lm_sensors=( - ['alpine']="lm_sensors" - ['arch']="lm_sensors" |