summaryrefslogtreecommitdiffstats
path: root/packaging/installer
diff options
context:
space:
mode:
authorAustin S. Hemmelgarn <austin@netdata.cloud>2020-06-07 22:59:36 -0400
committerGitHub <noreply@github.com>2020-06-08 12:59:36 +1000
commitb400a1cfbcc1482fe2155290df2d136c55723343 (patch)
tree6757ce2b9915d9f5667241f4553eee4c5891baed /packaging/installer
parent903a5c2e73f1a408fd20d71b3af53822eaa46067 (diff)
Added support for macOS/Homebrew in `install-required-packages.sh`. (#8286)
* Add basic macOS support to install-required-packages.sh This uses Homebrew for the package installs, and skips anything that macOS already has as part of the base system. * Use Python 3 on macOS. Homebrew defaults to python 3, just use that because it makes life easier for users. * Disable running as EUID=0 on macOS. Homebrew only works properly for regular users. * Use macOS's native version of zlib. * Assorted fixes. * Fix typos in package mappings.
Diffstat (limited to 'packaging/installer')
-rwxr-xr-xpackaging/installer/install-required-packages.sh109
1 files changed, 105 insertions, 4 deletions
diff --git a/packaging/installer/install-required-packages.sh b/packaging/installer/install-required-packages.sh
index 072b992279..5c0f230cdb 100755
--- a/packaging/installer/install-required-packages.sh
+++ b/packaging/installer/install-required-packages.sh
@@ -39,6 +39,7 @@ lsb_release=$(command -v lsb_release 2> /dev/null)
# Check which package managers are available
apk=$(command -v apk 2> /dev/null)
apt_get=$(command -v apt-get 2> /dev/null)
+brew=$(command -v brew 2> /dev/null)
dnf=$(command -v dnf 2> /dev/null)
emerge=$(command -v emerge 2> /dev/null)
equo=$(command -v equo 2> /dev/null)
@@ -77,6 +78,7 @@ Supported distributions (DD):
- redhat, fedora (all Red Hat and Fedora derivatives)
- suse, opensuse (all SUSE and openSUSE derivatives)
- clearlinux (all Clear Linux derivatives)
+ - macos (Apple's macOS)
Supported installers (IN):
@@ -89,6 +91,7 @@ Supported installers (IN):
- zypper all SUSE Linux derivatives
- apk all Alpine derivatives
- swupd all Clear Linux derivatives
+ - brew macOS Homebrew
Supported packages (you can append many of them):
@@ -267,8 +270,24 @@ find_etc_any_release() {
}
autodetect_distribution() {
- # autodetection of distribution
- get_os_release || get_lsb_release || find_etc_any_release
+ # autodetection of distribution/OS
+ case "$(uname -s)" in
+ "Linux")
+ get_os_release || get_lsb_release || find_etc_any_release
+ ;;
+ "Darwin")
+ distribution="macos"
+ version="$(uname -r)"
+ detection="uname"
+
+ if [ ${EUID} -eq 0 ] ; then
+ echo >&2 "This script does not support running as EUID 0 on macOS. Please run it as a regular user."
+ exit 1
+ fi
+ ;;
+ *)
+ return 1
+ esac
}
user_picks_distribution() {
@@ -302,6 +321,7 @@ user_picks_distribution() {
[ -n "${equo}" ] && echo >&2 " - Sabayon based (installer is: equo)" && opts="equo ${opts}"
[ -n "${apk}" ] && echo >&2 " - Alpine Linux based (installer is: apk)" && opts="apk ${opts}"
[ -n "${swupd}" ] && echo >&2 " - Clear Linux based (installer is: swupd)" && opts="swupd ${opts}"
+ [ -n "${brew}" ] && echo >&2 " - macOS based (installer is: brew)" && opts="brew ${opts}"
echo >&2
REPLY=
@@ -426,6 +446,15 @@ detect_package_manager_from_distribution() {
fi
;;
+ macos)
+ package_installer="install_brew"
+ tree="macos"
+ if [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${brew}" ]; then
+ echo >&2 "command 'brew' is required to install packages on a '${distribution} ${version}' system."
+ exit 1
+ fi
+ ;;
+
*)
# oops! unknown system
user_picks_distribution
@@ -517,6 +546,15 @@ check_package_manager() {
return 0
;;
+ brew)
+ [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${brew}" ] && echo >&2 "${1} is not available." && return 1
+ package_installer="install_brew"
+ tree="macos"
+ detection="user-input"
+
+ return 0
+ ;;
+
*)
echo >&2 "Invalid package manager: '${1}'."
return 1
@@ -546,6 +584,7 @@ declare -A pkg_find=(
['gentoo']="sys-apps/findutils"
['fedora']="findutils"
['clearlinux']="findutils"
+ ['macos']="NOTREQUIRED"
['default']="WARNING|"
)
@@ -613,12 +652,14 @@ declare -A pkg_json_c_dev=(
declare -A pkg_bridge_utils=(
['gentoo']="net-misc/bridge-utils"
['clearlinux']="network-basic"
+ ['macos']="WARNING|"
['default']="bridge-utils"
)
declare -A pkg_chrony=(
['gentoo']="net-misc/chrony"
['clearlinux']="time-server-basic"
+ ['macos']="WARNING|"
['default']="chrony"
)
@@ -630,12 +671,14 @@ declare -A pkg_curl=(
declare -A pkg_gzip=(
['gentoo']="app-arch/gzip"
+ ['macos']="NOTREQUIRED"
['default']="gzip"
)
declare -A pkg_tar=(
['gentoo']="app-arch/tar"
['clearlinux']="os-core-update"
+ ['macos']="NOTREQUIRED"
['default']="tar"
)
@@ -647,16 +690,19 @@ declare -A pkg_git=(
declare -A pkg_gcc=(
['gentoo']="sys-devel/gcc"
['clearlinux']="c-basic"
+ ['macos']="NOTREQUIRED"
['default']="gcc"
)
declare -A pkg_gdb=(
['gentoo']="sys-devel/gdb"
+ ['macos']="NOTREQUIRED"
['default']="gdb"
)
declare -A pkg_iotop=(
['gentoo']="sys-process/iotop"
+ ['macos']="WARNING|"
['default']="iotop"
)
@@ -666,6 +712,7 @@ declare -A pkg_iproute2=(
['gentoo']="sys-apps/iproute2"
['sabayon']="sys-apps/iproute2"
['clearlinux']="iproute2"
+ ['macos']="WARNING|"
['default']="iproute"
# exceptions
@@ -675,6 +722,7 @@ declare -A pkg_iproute2=(
declare -A pkg_ipset=(
['gentoo']="net-firewall/ipset"
['clearlinux']="network-basic"
+ ['macos']="WARNING|"
['default']="ipset"
)
@@ -685,6 +733,7 @@ declare -A pkg_jq=(
declare -A pkg_iptables=(
['gentoo']="net-firewall/iptables"
+ ['macos']="WARNING|"
['default']="iptables"
)
@@ -698,6 +747,7 @@ declare -A pkg_libz_dev=(
['rhel']="zlib-devel"
['suse']="zlib-devel"
['clearlinux']="devpkg-zlib"
+ ['macos']="NOTREQUIRED"
['default']=""
)
@@ -711,6 +761,7 @@ declare -A pkg_libuuid_dev=(
['sabayon']="sys-apps/util-linux"
['rhel']="libuuid-devel"
['suse']="libuuid-devel"
+ ['macos']="NOTREQUIRED"
['default']=""
)
@@ -724,6 +775,7 @@ declare -A pkg_libmnl_dev=(
['rhel']="libmnl-devel"
['suse']="libmnl-devel"
['clearlinux']="devpkg-libmnl"
+ ['macos']="NOTREQUIRED"
['default']=""
)
@@ -737,29 +789,34 @@ declare -A pkg_lm_sensors=(
['rhel']="lm_sensors"
['suse']="sensors"
['clearlinux']="lm-sensors"
+ ['macos']="WARNING|"
['default']="lm_sensors"
)
declare -A pkg_logwatch=(
['gentoo']="sys-apps/logwatch"
['clearlinux']="WARNING|"
+ ['macos']="WARNING|"
['default']="logwatch"
)
declare -A pkg_lxc=(
['gentoo']="app-emulation/lxc"
['clearlinux']="WARNING|"
+ ['macos']="WARNING|"
['default']="lxc"
)
declare -A pkg_mailutils=(
['gentoo']="net-mail/mailutils"
['clearlinux']="WARNING|"
+ ['macos']="WARNING|"
['default']="mailutils"
)
declare -A pkg_make=(
['gentoo']="sys-devel/make"
+ ['macos']="NOTREQUIRED"
['default']="make"
)
@@ -774,6 +831,7 @@ declare -A pkg_netcat=(
['suse']="netcat-openbsd"
['clearlinux']="sysadmin-basic"
['arch']="gnu-netcat"
+ ['macos']="NOTREQUIRED"
['default']="netcat"
# exceptions
@@ -801,6 +859,7 @@ declare -A pkg_nodejs=(
declare -A pkg_postfix=(
['gentoo']="mail-mta/postfix"
+ ['macos']="WARNING|"
['default']="postfix"
)
@@ -824,6 +883,7 @@ declare -A pkg_python=(
['default']="python"
# Exceptions
+ ['macos']="WARNING|"
['centos-8']="python2"
)
@@ -853,6 +913,7 @@ declare -A pkg_python3_mysqldb=(
['rhel']="WARNING|"
['suse']="WARNING|"
['clearlinux']="WARNING|"
+ ['macos']="WARNING|"
['default']="WARNING|"
# exceptions
@@ -879,6 +940,7 @@ declare -A pkg_python_psycopg2=(
['rhel']="python-psycopg2"
['suse']="python-psycopg2"
['clearlinux']="WARNING|"
+ ['macos']="WARNING|"
['default']="python-psycopg2"
)
@@ -892,6 +954,7 @@ declare -A pkg_python3_psycopg2=(
['rhel']="WARNING|"
['suse']="WARNING|"
['clearlinux']="WARNING|"
+ ['macos']="WARNING|"
['default']="WARNING|"
)
@@ -900,6 +963,7 @@ declare -A pkg_python_pip=(
['gentoo']="dev-python/pip"
['sabayon']="dev-python/pip"
['clearlinux']="python-basic"
+ ['macos']="WARNING|"
['default']="python-pip"
)
@@ -911,6 +975,7 @@ declare -A pkg_python3_pip=(
['sabayon']="dev-python/pip"
['rhel']="WARNING|"
['clearlinux']="python3-basic"
+ ['macos']="NOTREQUIRED"
['default']="python3-pip"
)
@@ -922,6 +987,7 @@ declare -A pkg_python_pymongo=(
['gentoo']="dev-python/pymongo"
['suse']="python-pymongo"
['clearlinux']="WARNING|"
+ ['macos']="WARNING|"
['default']="python-pymongo"
)
@@ -933,6 +999,7 @@ declare -A pkg_python3_pymongo=(
['gentoo']="dev-python/pymongo"
['suse']="python3-pymongo"
['clearlinux']="WARNING|"
+ ['macos']="WARNING|"
['default']="python3-pymongo"
)
@@ -946,6 +1013,7 @@ declare -A pkg_python_requests=(
['rhel']="python-requests"
['suse']="python-requests"
['clearlinux']="python-extras"
+ ['macos']="WARNING|"
['default']="python-requests"
['alpine-3.1.4']="WARNING|"
['alpine-3.2.3']="WARNING|"
@@ -961,6 +1029,7 @@ declare -A pkg_python3_requests=(
['rhel']="WARNING|"
['suse']="WARNING|"
['clearlinux']="python-extras"
+ ['macos']="WARNING|"
['default']="WARNING|"
)
@@ -972,6 +1041,7 @@ declare -A pkg_lz4=(
['gentoo']="app-arch/lz4"
['clearlinux']="devpkg-lz4"
['arch']="lz4"
+ ['macos']="lz4"
['default']="lz4-devel"
)
@@ -982,6 +1052,7 @@ declare -A pkg_libuv=(
['gentoo']="dev-libs/libuv"
['arch']="libuv"
['clearlinux']="devpkg-libuv"
+ ['macos']="libuv"
['default']="libuv-devel"
)
@@ -993,12 +1064,14 @@ declare -A pkg_openssl=(
['clearlinux']="devpkg-openssl"
['gentoo']="dev-libs/openssl"
['arch']="openssl"
+ ['macos']="openssl@1.1"
['default']="openssl-devel"
)
declare -A pkg_judy=(
['alpine']="WARNING|" # TODO - need to add code to download and install judy for alpine and clearlinux
['clearlinux']="WARNING|"
+ ['macos']="WARNING|"
['debian']="libjudy-dev"
['ubuntu']="libjudy-dev"
['suse']="judy-devel"
@@ -1011,6 +1084,7 @@ declare -A pkg_python3=(
['gentoo']="dev-lang/python"
['sabayon']="dev-lang/python:3.4"
['clearlinux']="python3-basic"
+ ['macos']="python"
['default']="python3"
# exceptions
@@ -1026,11 +1100,13 @@ declare -A pkg_screen=(
declare -A pkg_sudo=(
['gentoo']="app-admin/sudo"
+ ['macos']="NOTREQUIRED"
['default']="sudo"
)
declare -A pkg_sysstat=(
['gentoo']="app-admin/sysstat"
+ ['macos']="WARNING|"
['default']="sysstat"
)
@@ -1044,6 +1120,7 @@ declare -A pkg_traceroute=(
['alpine']=" "
['gentoo']="net-analyzer/traceroute"
['clearlinux']="network-basic"
+ ['macos']="NOTREQUIRED"
['default']="traceroute"
)
@@ -1058,16 +1135,19 @@ declare -A pkg_ulogd=(
['clearlinux']="WARNING|"
['gentoo']="app-admin/ulogd"
['arch']="ulogd"
+ ['macos']="WARNING|"
['default']="ulogd2"
)
declare -A pkg_unzip=(
['gentoo']="app-arch/unzip"
+ ['macos']="NOTREQUIRED"
['default']="unzip"
)
declare -A pkg_zip=(
['gentoo']="app-arch/zip"
+ ['macos']="NOTREQUIRED"
['default']="zip"
)
@@ -1280,7 +1360,7 @@ run() {
}
sudo=
-if [ ${UID} -ne 0 ]; then
+if [ ${UID} -ne 0 ] ; then
sudo="sudo"
fi
@@ -1654,6 +1734,25 @@ install_swupd() {
}
# -----------------------------------------------------------------------------
+# macOS
+
+validate_install_brew() {
+ brew list | grep -q "${*}" || echo "${*}"
+}
+
+install_brew() {
+ # download the latest package info
+ if [ "${DRYRUN}" -eq 1 ]; then
+ echo >&2 " >> IMPORTANT << "
+ echo >&2 " Please make sure your system is up to date"
+ echo >&2 " by running: brew upgrade "
+ echo >&2
+ fi
+
+ run brew install "${@}"
+}
+
+# -----------------------------------------------------------------------------
install_failed() {
local ret="${1}"
@@ -1697,7 +1796,9 @@ if [ -z "${1}" ]; then
fi
pv=$(python --version 2>&1)
-if [[ "${pv}" =~ ^Python\ 2.* ]]; then
+if [ "${tree}" = macos ] ; then
+ pv=3
+elif [[ "${pv}" =~ ^Python\ 2.* ]]; then
pv=2
elif [[ "${pv}" =~ ^Python\ 3.* ]]; then
pv=3