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.
Austin S. Hemmelgarn committed
Jun 7, 2020 at 22:59 UTC
b400a1cfbcc1482fe2155290df2d136c55723343
1 file changed
+105
-4
packaging/installer/install-required-packages.sh
+105
-4
@@ -39,6 +39,7 @@ lsb_release=$(command -v lsb_release 2> /dev/null)
39
# Check which package managers are available
40
apk=$(command -v apk 2> /dev/null)
41
apt_get=$(command -v apt-get 2> /dev/null)
42
+brew=$(command -v brew 2> /dev/null)
43
dnf=$(command -v dnf 2> /dev/null)
44
emerge=$(command -v emerge 2> /dev/null)
45
equo=$(command -v equo 2> /dev/null)
@@ -77,6 +78,7 @@ Supported distributions (DD):
78
- redhat, fedora (all Red Hat and Fedora derivatives)
79
- suse, opensuse (all SUSE and openSUSE derivatives)
80
- clearlinux (all Clear Linux derivatives)
81
+ - macos (Apple's macOS)
82
83
Supported installers (IN):
84
@@ -89,6 +91,7 @@ Supported installers (IN):
91
- zypper all SUSE Linux derivatives
92
- apk all Alpine derivatives
93
- swupd all Clear Linux derivatives
94
+ - brew macOS Homebrew
95
96
Supported packages (you can append many of them):
97
@@ -267,8 +270,24 @@ find_etc_any_release() {
270
}
271
272
autodetect_distribution() {
270
- # autodetection of distribution
271
- get_os_release || get_lsb_release || find_etc_any_release
273
+ # autodetection of distribution/OS
274
+ case "$(uname -s)" in
275
+ "Linux")
276
+ get_os_release || get_lsb_release || find_etc_any_release
277
+ ;;
278
+ "Darwin")
279
+ distribution="macos"
280
+ version="$(uname -r)"
281
+ detection="uname"
282
+
283
+ if [ ${EUID} -eq 0 ] ; then
284
+ echo >&2 "This script does not support running as EUID 0 on macOS. Please run it as a regular user."
285
+ exit 1
286
+ fi
287
+ ;;
288
+ *)
289
+ return 1
290
+ esac
291
}
292
293
user_picks_distribution() {
@@ -302,6 +321,7 @@ user_picks_distribution() {
321
[ -n "${equo}" ] && echo >&2 " - Sabayon based (installer is: equo)" && opts="equo ${opts}"
322
[ -n "${apk}" ] && echo >&2 " - Alpine Linux based (installer is: apk)" && opts="apk ${opts}"
323
[ -n "${swupd}" ] && echo >&2 " - Clear Linux based (installer is: swupd)" && opts="swupd ${opts}"
324
+ [ -n "${brew}" ] && echo >&2 " - macOS based (installer is: brew)" && opts="brew ${opts}"
325
echo >&2
326
327
REPLY=
@@ -426,6 +446,15 @@ detect_package_manager_from_distribution() {
446
fi
447
;;
448
449
+ macos)
450
+ package_installer="install_brew"
451
+ tree="macos"
452
+ if [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${brew}" ]; then
453
+ echo >&2 "command 'brew' is required to install packages on a '${distribution} ${version}' system."
454
+ exit 1
455
+ fi
456
+ ;;
457
+
458
*)
459
# oops! unknown system
460
user_picks_distribution
@@ -517,6 +546,15 @@ check_package_manager() {
546
return 0
547
;;
548
549
+ brew)
550
+ [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${brew}" ] && echo >&2 "${1} is not available." && return 1
551
+ package_installer="install_brew"
552
+ tree="macos"
553
+ detection="user-input"
554
+
555
+ return 0
556
+ ;;
557
+
558
*)
559
echo >&2 "Invalid package manager: '${1}'."
560
return 1
@@ -546,6 +584,7 @@ declare -A pkg_find=(
584
['gentoo']="sys-apps/findutils"
585
['fedora']="findutils"
586
['clearlinux']="findutils"
587
+ ['macos']="NOTREQUIRED"
588
['default']="WARNING|"
589
)
590
@@ -613,12 +652,14 @@ declare -A pkg_json_c_dev=(
652
declare -A pkg_bridge_utils=(
653
['gentoo']="net-misc/bridge-utils"
654
['clearlinux']="network-basic"
655
+ ['macos']="WARNING|"
656
['default']="bridge-utils"
657
)
658
659
declare -A pkg_chrony=(
660
['gentoo']="net-misc/chrony"
661
['clearlinux']="time-server-basic"
662
+ ['macos']="WARNING|"
663
['default']="chrony"
664
)
665
@@ -630,12 +671,14 @@ declare -A pkg_curl=(
671
672
declare -A pkg_gzip=(
673
['gentoo']="app-arch/gzip"
674
+ ['macos']="NOTREQUIRED"
675
['default']="gzip"
676
)
677
678
declare -A pkg_tar=(
679
['gentoo']="app-arch/tar"
680
['clearlinux']="os-core-update"
681
+ ['macos']="NOTREQUIRED"
682
['default']="tar"
683
)
684
@@ -647,16 +690,19 @@ declare -A pkg_git=(
690
declare -A pkg_gcc=(
691
['gentoo']="sys-devel/gcc"
692
['clearlinux']="c-basic"
693
+ ['macos']="NOTREQUIRED"
694
['default']="gcc"
695
)
696
697
declare -A pkg_gdb=(
698
['gentoo']="sys-devel/gdb"
699
+ ['macos']="NOTREQUIRED"
700
['default']="gdb"
701
)
702
703
declare -A pkg_iotop=(
704
['gentoo']="sys-process/iotop"
705
+ ['macos']="WARNING|"
706
['default']="iotop"
707
)
708
@@ -666,6 +712,7 @@ declare -A pkg_iproute2=(
712
['gentoo']="sys-apps/iproute2"
713
['sabayon']="sys-apps/iproute2"
714
['clearlinux']="iproute2"
715
+ ['macos']="WARNING|"
716
['default']="iproute"
717
718
# exceptions
@@ -675,6 +722,7 @@ declare -A pkg_iproute2=(
722
declare -A pkg_ipset=(
723
['gentoo']="net-firewall/ipset"
724
['clearlinux']="network-basic"
725
+ ['macos']="WARNING|"
726
['default']="ipset"
727
)
728
@@ -685,6 +733,7 @@ declare -A pkg_jq=(
733
734
declare -A pkg_iptables=(
735
['gentoo']="net-firewall/iptables"
736
+ ['macos']="WARNING|"
737
['default']="iptables"
738
)
739
@@ -698,6 +747,7 @@ declare -A pkg_libz_dev=(
747
['rhel']="zlib-devel"
748
['suse']="zlib-devel"
749
['clearlinux']="devpkg-zlib"
750
+ ['macos']="NOTREQUIRED"
751
['default']=""
752
)
753
@@ -711,6 +761,7 @@ declare -A pkg_libuuid_dev=(
761
['sabayon']="sys-apps/util-linux"
762
['rhel']="libuuid-devel"
763
['suse']="libuuid-devel"
764
+ ['macos']="NOTREQUIRED"
765
['default']=""
766
)
767
@@ -724,6 +775,7 @@ declare -A pkg_libmnl_dev=(
775
['rhel']="libmnl-devel"
776
['suse']="libmnl-devel"
777
['clearlinux']="devpkg-libmnl"
778
+ ['macos']="NOTREQUIRED"
779
['default']=""
780
)
781
@@ -737,29 +789,34 @@ declare -A pkg_lm_sensors=(
789
['rhel']="lm_sensors"
790
['suse']="sensors"
791
['clearlinux']="lm-sensors"
792
+ ['macos']="WARNING|"
793
['default']="lm_sensors"
794
)
795
796
declare -A pkg_logwatch=(
797
['gentoo']="sys-apps/logwatch"
798
['clearlinux']="WARNING|"
799
+ ['macos']="WARNING|"
800
['default']="logwatch"
801
)
802
803
declare -A pkg_lxc=(
804
['gentoo']="app-emulation/lxc"
805
['clearlinux']="WARNING|"
806
+ ['macos']="WARNING|"
807
['default']="lxc"
808
)
809
810
declare -A pkg_mailutils=(
811
['gentoo']="net-mail/mailutils"
812
['clearlinux']="WARNING|"
813
+ ['macos']="WARNING|"
814
['default']="mailutils"
815
)
816
817
declare -A pkg_make=(
818
['gentoo']="sys-devel/make"
819
+ ['macos']="NOTREQUIRED"
820
['default']="make"
821
)
822
@@ -774,6 +831,7 @@ declare -A pkg_netcat=(
831
['suse']="netcat-openbsd"
832
['clearlinux']="sysadmin-basic"
833
['arch']="gnu-netcat"
834
+ ['macos']="NOTREQUIRED"
835
['default']="netcat"
836
837
# exceptions
@@ -801,6 +859,7 @@ declare -A pkg_nodejs=(
859
860
declare -A pkg_postfix=(
861
['gentoo']="mail-mta/postfix"
862
+ ['macos']="WARNING|"
863
['default']="postfix"
864
)
865
@@ -824,6 +883,7 @@ declare -A pkg_python=(
883
['default']="python"
884
885
# Exceptions
886
+ ['macos']="WARNING|"
887
['centos-8']="python2"
888
)
889
@@ -853,6 +913,7 @@ declare -A pkg_python3_mysqldb=(
913
['rhel']="WARNING|"
914
['suse']="WARNING|"
915
['clearlinux']="WARNING|"
916
+ ['macos']="WARNING|"
917
['default']="WARNING|"
918
919
# exceptions
@@ -879,6 +940,7 @@ declare -A pkg_python_psycopg2=(
940
['rhel']="python-psycopg2"
941
['suse']="python-psycopg2"
942
['clearlinux']="WARNING|"
943
+ ['macos']="WARNING|"
944
['default']="python-psycopg2"
945
)
946
@@ -892,6 +954,7 @@ declare -A pkg_python3_psycopg2=(
954
['rhel']="WARNING|"
955
['suse']="WARNING|"
956
['clearlinux']="WARNING|"
957
+ ['macos']="WARNING|"
958
['default']="WARNING|"
959
)
960
@@ -900,6 +963,7 @@ declare -A pkg_python_pip=(
963
['gentoo']="dev-python/pip"
964
['sabayon']="dev-python/pip"
965
['clearlinux']="python-basic"
966
+ ['macos']="WARNING|"
967
['default']="python-pip"
968
)
969
@@ -911,6 +975,7 @@ declare -A pkg_python3_pip=(
975
['sabayon']="dev-python/pip"
976
['rhel']="WARNING|"
977
['clearlinux']="python3-basic"
978
+ ['macos']="NOTREQUIRED"
979
['default']="python3-pip"
980
)
981
@@ -922,6 +987,7 @@ declare -A pkg_python_pymongo=(
987
['gentoo']="dev-python/pymongo"
988
['suse']="python-pymongo"
989
['clearlinux']="WARNING|"
990
+ ['macos']="WARNING|"
991
['default']="python-pymongo"
992
)
993
@@ -933,6 +999,7 @@ declare -A pkg_python3_pymongo=(
999
['gentoo']="dev-python/pymongo"
1000
['suse']="python3-pymongo"
1001
['clearlinux']="WARNING|"
1002
+ ['macos']="WARNING|"
1003
['default']="python3-pymongo"
1004
)
1005
@@ -946,6 +1013,7 @@ declare -A pkg_python_requests=(
1013
['rhel']="python-requests"
1014
['suse']="python-requests"
1015
['clearlinux']="python-extras"
1016
+ ['macos']="WARNING|"
1017
['default']="python-requests"
1018
['alpine-3.1.4']="WARNING|"
1019
['alpine-3.2.3']="WARNING|"
@@ -961,6 +1029,7 @@ declare -A pkg_python3_requests=(
1029
['rhel']="WARNING|"
1030
['suse']="WARNING|"
1031
['clearlinux']="python-extras"
1032
+ ['macos']="WARNING|"
1033
['default']="WARNING|"
1034
)
1035
@@ -972,6 +1041,7 @@ declare -A pkg_lz4=(
1041
['gentoo']="app-arch/lz4"
1042
['clearlinux']="devpkg-lz4"
1043
['arch']="lz4"
1044
+ ['macos']="lz4"
1045
['default']="lz4-devel"
1046
)
1047
@@ -982,6 +1052,7 @@ declare -A pkg_libuv=(
1052
['gentoo']="dev-libs/libuv"
1053
['arch']="libuv"
1054
['clearlinux']="devpkg-libuv"
1055
+ ['macos']="libuv"
1056
['default']="libuv-devel"
1057
)
1058
@@ -993,12 +1064,14 @@ declare -A pkg_openssl=(
1064
['clearlinux']="devpkg-openssl"
1065
['gentoo']="dev-libs/openssl"
1066
['arch']="openssl"
1067
+ ['macos']="openssl@1.1"
1068
['default']="openssl-devel"
1069
)
1070
1071
declare -A pkg_judy=(
1072
['alpine']="WARNING|" # TODO - need to add code to download and install judy for alpine and clearlinux
1073
['clearlinux']="WARNING|"
1074
+ ['macos']="WARNING|"
1075
['debian']="libjudy-dev"
1076
['ubuntu']="libjudy-dev"
1077
['suse']="judy-devel"
@@ -1011,6 +1084,7 @@ declare -A pkg_python3=(
1084
['gentoo']="dev-lang/python"
1085
['sabayon']="dev-lang/python:3.4"
1086
['clearlinux']="python3-basic"
1087
+ ['macos']="python"
1088
['default']="python3"
1089
1090
# exceptions
@@ -1026,11 +1100,13 @@ declare -A pkg_screen=(
1100
1101
declare -A pkg_sudo=(
1102
['gentoo']="app-admin/sudo"
1103
+ ['macos']="NOTREQUIRED"
1104
['default']="sudo"
1105
)
1106
1107
declare -A pkg_sysstat=(
1108
['gentoo']="app-admin/sysstat"
1109
+ ['macos']="WARNING|"
1110
['default']="sysstat"
1111
)
1112
@@ -1044,6 +1120,7 @@ declare -A pkg_traceroute=(
1120
['alpine']=" "
1121
['gentoo']="net-analyzer/traceroute"
1122
['clearlinux']="network-basic"
1123
+ ['macos']="NOTREQUIRED"
1124
['default']="traceroute"
1125
)
1126
@@ -1058,16 +1135,19 @@ declare -A pkg_ulogd=(
1135
['clearlinux']="WARNING|"
1136
['gentoo']="app-admin/ulogd"
1137
['arch']="ulogd"
1138
+ ['macos']="WARNING|"
1139
['default']="ulogd2"
1140
)
1141
1142
declare -A pkg_unzip=(
1143
['gentoo']="app-arch/unzip"
1144
+ ['macos']="NOTREQUIRED"
1145
['default']="unzip"
1146
)
1147
1148
declare -A pkg_zip=(
1149
['gentoo']="app-arch/zip"
1150
+ ['macos']="NOTREQUIRED"
1151
['default']="zip"
1152
)
1153
@@ -1280,7 +1360,7 @@ run() {
1360
}
1361
1362
sudo=
1283
-if [ ${UID} -ne 0 ]; then
1363
+if [ ${UID} -ne 0 ] ; then
1364
sudo="sudo"
1365
fi
1366
@@ -1653,6 +1733,25 @@ install_swupd() {
1733
run ${sudo} swupd bundle-add "${@}"
1734
}
1735
1736
+# -----------------------------------------------------------------------------
1737
+# macOS
1738
+
1739
+validate_install_brew() {
1740
+ brew list | grep -q "${*}" || echo "${*}"
1741
+}
1742
+
1743
+install_brew() {
1744
+ # download the latest package info
1745
+ if [ "${DRYRUN}" -eq 1 ]; then
1746
+ echo >&2 " >> IMPORTANT << "
1747
+ echo >&2 " Please make sure your system is up to date"
1748
+ echo >&2 " by running: brew upgrade "
1749
+ echo >&2
1750
+ fi
1751
+
1752
+ run brew install "${@}"
1753
+}
1754
+
1755
# -----------------------------------------------------------------------------
1756
1757
install_failed() {
@@ -1697,7 +1796,9 @@ if [ -z "${1}" ]; then
1796
fi
1797
1798
pv=$(python --version 2>&1)
1700
-if [[ "${pv}" =~ ^Python\ 2.* ]]; then
1799
+if [ "${tree}" = macos ] ; then
1800
+ pv=3
1801
+elif [[ "${pv}" =~ ^Python\ 2.* ]]; then
1802
pv=2
1803
elif [[ "${pv}" =~ ^Python\ 3.* ]]; then
1804
pv=3