install-required-packages.sh 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080
  1. #!/usr/bin/env bash
  2. # shellcheck disable=SC2034
  3. # We use lots of computed variable names in here, so we need to disable shellcheck 2034
  4. export PATH="${PATH}:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
  5. export LC_ALL=C
  6. # Be nice on production environments
  7. renice 19 $$ > /dev/null 2> /dev/null
  8. ME="${0}"
  9. if [ "${BASH_VERSINFO[0]}" -lt "4" ]; then
  10. echo >&2 "Sorry! This script needs BASH version 4+, but you have BASH version ${BASH_VERSION}"
  11. exit 1
  12. fi
  13. # These options control which packages we are going to install
  14. # They can be pre-set, but also can be controlled with command line options
  15. PACKAGES_NETDATA=${PACKAGES_NETDATA-1}
  16. PACKAGES_NETDATA_PYTHON=${PACKAGES_NETDATA_PYTHON-0}
  17. PACKAGES_NETDATA_PYTHON3=${PACKAGES_NETDATA_PYTHON3-1}
  18. PACKAGES_DEBUG=${PACKAGES_DEBUG-0}
  19. PACKAGES_IPRANGE=${PACKAGES_IPRANGE-0}
  20. PACKAGES_FIREHOL=${PACKAGES_FIREHOL-0}
  21. PACKAGES_FIREQOS=${PACKAGES_FIREQOS-0}
  22. PACKAGES_UPDATE_IPSETS=${PACKAGES_UPDATE_IPSETS-0}
  23. PACKAGES_NETDATA_DEMO_SITE=${PACKAGES_NETDATA_DEMO_SITE-0}
  24. PACKAGES_NETDATA_SENSORS=${PACKAGES_NETDATA_SENSORS-0}
  25. PACKAGES_NETDATA_DATABASE=${PACKAGES_NETDATA_DATABASE-1}
  26. PACKAGES_NETDATA_STREAMING_COMPRESSION=${PACKAGES_NETDATA_STREAMING_COMPRESSION-0}
  27. PACKAGES_NETDATA_EBPF=${PACKAGES_NETDATA_EBPF-1}
  28. # needed commands
  29. lsb_release=$(command -v lsb_release 2> /dev/null)
  30. # Check which package managers are available
  31. apk=$(command -v apk 2> /dev/null)
  32. apt_get=$(command -v apt-get 2> /dev/null)
  33. brew=$(command -v brew 2> /dev/null)
  34. pkg=$(command -v pkg 2> /dev/null)
  35. dnf=$(command -v dnf 2> /dev/null)
  36. emerge=$(command -v emerge 2> /dev/null)
  37. equo=$(command -v equo 2> /dev/null)
  38. pacman=$(command -v pacman 2> /dev/null)
  39. swupd=$(command -v swupd 2> /dev/null)
  40. yum=$(command -v yum 2> /dev/null)
  41. zypper=$(command -v zypper 2> /dev/null)
  42. distribution=
  43. release=
  44. version=
  45. codename=
  46. package_installer=
  47. tree=
  48. detection=
  49. NAME=
  50. ID=
  51. ID_LIKE=
  52. VERSION=
  53. VERSION_ID=
  54. usage() {
  55. cat << EOF
  56. OPTIONS:
  57. ${ME} [--dont-wait] [--non-interactive] \\
  58. [distribution DD [version VV] [codename CN]] [installer IN] [packages]
  59. Supported distributions (DD):
  60. - arch (all Arch Linux derivatives)
  61. - centos (all CentOS derivatives)
  62. - gentoo (all Gentoo Linux derivatives)
  63. - sabayon (all Sabayon Linux derivatives)
  64. - debian, ubuntu (all Debian and Ubuntu derivatives)
  65. - redhat, fedora (all Red Hat and Fedora derivatives)
  66. - suse, opensuse (all SUSE and openSUSE derivatives)
  67. - clearlinux (all Clear Linux derivatives)
  68. - macos (Apple's macOS)
  69. Supported installers (IN):
  70. - apt-get all Debian / Ubuntu Linux derivatives
  71. - dnf newer Red Hat / Fedora Linux
  72. - emerge all Gentoo Linux derivatives
  73. - equo all Sabayon Linux derivatives
  74. - pacman all Arch Linux derivatives
  75. - yum all Red Hat / Fedora / CentOS Linux derivatives
  76. - zypper all SUSE Linux derivatives
  77. - apk all Alpine derivatives
  78. - swupd all Clear Linux derivatives
  79. - brew macOS Homebrew
  80. - pkg FreeBSD Ports
  81. Supported packages (you can append many of them):
  82. - netdata-all all packages required to install netdata
  83. including python, sensors, etc
  84. - netdata minimum packages required to install netdata
  85. (includes python)
  86. - python install python
  87. - python3 install python3
  88. - sensors install lm_sensors for monitoring h/w sensors
  89. - firehol-all packages required for FireHOL, FireQOS, update-ipsets
  90. - firehol packages required for FireHOL
  91. - fireqos packages required for FireQOS
  92. - update-ipsets packages required for update-ipsets
  93. - demo packages required for running a netdata demo site
  94. (includes nginx and various debugging tools)
  95. If you don't supply the --dont-wait option, the program
  96. will ask you before touching your system.
  97. EOF
  98. }
  99. release2lsb_release() {
  100. # loads the given /etc/x-release file
  101. # this file is normally a single line containing something like
  102. #
  103. # X Linux release 1.2.3 (release-name)
  104. #
  105. # It attempts to parse it
  106. # If it succeeds, it returns 0
  107. # otherwise it returns 1
  108. local file="${1}" x DISTRIB_ID="" DISTRIB_RELEASE="" DISTRIB_CODENAME=""
  109. echo >&2 "Loading ${file} ..."
  110. x="$(grep -v "^$" "${file}" | head -n 1)"
  111. if [[ "${x}" =~ ^.*[[:space:]]+Linux[[:space:]]+release[[:space:]]+.*[[:space:]]+(.*)[[:space:]]*$ ]]; then
  112. eval "$(echo "${x}" | sed "s|^\(.*\)[[:space:]]\+Linux[[:space:]]\+release[[:space:]]\+\(.*\)[[:space:]]\+(\(.*\))[[:space:]]*$|DISTRIB_ID=\"\1\"\nDISTRIB_RELEASE=\"\2\"\nDISTRIB_CODENAME=\"\3\"|g" | grep "^DISTRIB")"
  113. elif [[ "${x}" =~ ^.*[[:space:]]+Linux[[:space:]]+release[[:space:]]+.*[[:space:]]+$ ]]; then
  114. eval "$(echo "${x}" | sed "s|^\(.*\)[[:space:]]\+Linux[[:space:]]\+release[[:space:]]\+\(.*\)[[:space:]]*$|DISTRIB_ID=\"\1\"\nDISTRIB_RELEASE=\"\2\"|g" | grep "^DISTRIB")"
  115. elif [[ "${x}" =~ ^.*[[:space:]]+release[[:space:]]+.*[[:space:]]+(.*)[[:space:]]*$ ]]; then
  116. eval "$(echo "${x}" | sed "s|^\(.*\)[[:space:]]\+release[[:space:]]\+\(.*\)[[:space:]]\+(\(.*\))[[:space:]]*$|DISTRIB_ID=\"\1\"\nDISTRIB_RELEASE=\"\2\"\nDISTRIB_CODENAME=\"\3\"|g" | grep "^DISTRIB")"
  117. elif [[ "${x}" =~ ^.*[[:space:]]+release[[:space:]]+.*[[:space:]]+$ ]]; then
  118. eval "$(echo "${x}" | sed "s|^\(.*\)[[:space:]]\+release[[:space:]]\+\(.*\)[[:space:]]*$|DISTRIB_ID=\"\1\"\nDISTRIB_RELEASE=\"\2\"|g" | grep "^DISTRIB")"
  119. fi
  120. distribution="${DISTRIB_ID}"
  121. version="${DISTRIB_RELEASE}"
  122. codename="${DISTRIB_CODENAME}"
  123. [ -z "${distribution}" ] && echo >&2 "Cannot parse this lsb-release: ${x}" && return 1
  124. detection="${file}"
  125. return 0
  126. }
  127. get_os_release() {
  128. # Loads the /etc/os-release or /usr/lib/os-release file(s)
  129. # Only the required fields are loaded
  130. #
  131. # If it manages to load a valid os-release, it returns 0
  132. # otherwise it returns 1
  133. #
  134. # It searches the ID_LIKE field for a compatible distribution
  135. os_release_file=
  136. if [ -s "/etc/os-release" ]; then
  137. os_release_file="/etc/os-release"
  138. elif [ -s "/usr/lib/os-release" ]; then
  139. os_release_file="/usr/lib/os-release"
  140. else
  141. echo >&2 "Cannot find an os-release file ..."
  142. return 1
  143. fi
  144. local x
  145. echo >&2 "Loading ${os_release_file} ..."
  146. eval "$(grep -E "^(NAME|ID|ID_LIKE|VERSION|VERSION_ID)=" "${os_release_file}")"
  147. for x in "${ID}" ${ID_LIKE}; do
  148. case "${x,,}" in
  149. almalinux | alpine | arch | centos | clear-linux-os | debian | fedora | gentoo | manjaro | opensuse-leap | opensuse-tumbleweed | ol | rhel | rocky | sabayon | sles | suse | ubuntu)
  150. distribution="${x}"
  151. if [[ "${ID}" = "opensuse-tumbleweed" ]]; then
  152. version="tumbleweed"
  153. codename="tumbleweed"
  154. else
  155. version="${VERSION_ID}"
  156. codename="${VERSION}"
  157. fi
  158. detection="${os_release_file}"
  159. break
  160. ;;
  161. *)
  162. echo >&2 "Unknown distribution ID: ${x}"
  163. ;;
  164. esac
  165. done
  166. [[ -z "${distribution}" ]] && echo >&2 "Cannot find valid distribution in: \
  167. ${ID} ${ID_LIKE}" && return 1
  168. [[ -z "${distribution}" ]] && return 1
  169. return 0
  170. }
  171. get_lsb_release() {
  172. # Loads the /etc/lsb-release file
  173. # If it fails, it attempts to run the command: lsb_release -a
  174. # and parse its output
  175. #
  176. # If it manages to find the lsb-release, it returns 0
  177. # otherwise it returns 1
  178. if [ -f "/etc/lsb-release" ]; then
  179. echo >&2 "Loading /etc/lsb-release ..."
  180. local DISTRIB_ID="" DISTRIB_RELEASE="" DISTRIB_CODENAME=""
  181. eval "$(grep -E "^(DISTRIB_ID|DISTRIB_RELEASE|DISTRIB_CODENAME)=" /etc/lsb-release)"
  182. distribution="${DISTRIB_ID}"
  183. version="${DISTRIB_RELEASE}"
  184. codename="${DISTRIB_CODENAME}"
  185. detection="/etc/lsb-release"
  186. fi
  187. if [ -z "${distribution}" ] && [ -n "${lsb_release}" ]; then
  188. echo >&2 "Cannot find distribution with /etc/lsb-release"
  189. echo >&2 "Running command: lsb_release ..."
  190. eval "declare -A release=( $(lsb_release -a 2> /dev/null | sed -e "s|^\(.*\):[[:space:]]*\(.*\)$|[\1]=\"\2\"|g") )"
  191. distribution="${release["Distributor ID"]}"
  192. version="${release[Release]}"
  193. codename="${release[Codename]}"
  194. detection="lsb_release"
  195. fi
  196. [ -z "${distribution}" ] && echo >&2 "Cannot find valid distribution with lsb-release" && return 1
  197. return 0
  198. }
  199. find_etc_any_release() {
  200. # Check for any of the known /etc/x-release files
  201. # If it finds one, it loads it and returns 0
  202. # otherwise it returns 1
  203. if [ -f "/etc/arch-release" ]; then
  204. release2lsb_release "/etc/arch-release" && return 0
  205. fi
  206. if [ -f "/etc/centos-release" ]; then
  207. release2lsb_release "/etc/centos-release" && return 0
  208. fi
  209. if [ -f "/etc/redhat-release" ]; then
  210. release2lsb_release "/etc/redhat-release" && return 0
  211. fi
  212. if [ -f "/etc/SuSe-release" ]; then
  213. release2lsb_release "/etc/SuSe-release" && return 0
  214. fi
  215. return 1
  216. }
  217. autodetect_distribution() {
  218. # autodetection of distribution/OS
  219. case "$(uname -s)" in
  220. "Linux")
  221. get_os_release || get_lsb_release || find_etc_any_release
  222. ;;
  223. "FreeBSD")
  224. distribution="freebsd"
  225. version="$(uname -r)"
  226. detection="uname"
  227. ;;
  228. "Darwin")
  229. distribution="macos"
  230. version="$(uname -r)"
  231. detection="uname"
  232. if [ ${EUID} -eq 0 ]; then
  233. echo >&2 "This script does not support running as EUID 0 on macOS. Please run it as a regular user."
  234. exit 1
  235. fi
  236. ;;
  237. *)
  238. return 1
  239. ;;
  240. esac
  241. }
  242. user_picks_distribution() {
  243. # let the user pick a distribution
  244. echo >&2
  245. echo >&2 "I NEED YOUR HELP"
  246. echo >&2 "It seems I cannot detect your system automatically."
  247. if [ "${NON_INTERACTIVE}" -eq 1 ]; then
  248. echo >&2 "Running in non-interactive mode"
  249. echo >&2 " > Bailing out..."
  250. exit 1
  251. fi
  252. if [ -z "${equo}" ] && [ -z "${emerge}" ] && [ -z "${apt_get}" ] && [ -z "${yum}" ] && [ -z "${dnf}" ] && [ -z "${pacman}" ] && [ -z "${apk}" ] && [ -z "${swupd}" ]; then
  253. echo >&2 "And it seems I cannot find a known package manager in this system."
  254. echo >&2 "Please open a github issue to help us support your system too."
  255. exit 1
  256. fi
  257. local opts=
  258. echo >&2 "I found though that the following installers are available:"
  259. echo >&2
  260. [ -n "${apt_get}" ] && echo >&2 " - Debian/Ubuntu based (installer is: apt-get)" && opts="apt-get ${opts}"
  261. [ -n "${yum}" ] && echo >&2 " - Red Hat/Fedora/CentOS based (installer is: yum)" && opts="yum ${opts}"
  262. [ -n "${dnf}" ] && echo >&2 " - Red Hat/Fedora/CentOS based (installer is: dnf)" && opts="dnf ${opts}"
  263. [ -n "${zypper}" ] && echo >&2 " - SuSe based (installer is: zypper)" && opts="zypper ${opts}"
  264. [ -n "${pacman}" ] && echo >&2 " - Arch Linux based (installer is: pacman)" && opts="pacman ${opts}"
  265. [ -n "${emerge}" ] && echo >&2 " - Gentoo based (installer is: emerge)" && opts="emerge ${opts}"
  266. [ -n "${equo}" ] && echo >&2 " - Sabayon based (installer is: equo)" && opts="equo ${opts}"
  267. [ -n "${apk}" ] && echo >&2 " - Alpine Linux based (installer is: apk)" && opts="apk ${opts}"
  268. [ -n "${swupd}" ] && echo >&2 " - Clear Linux based (installer is: swupd)" && opts="swupd ${opts}"
  269. [ -n "${brew}" ] && echo >&2 " - macOS based (installer is: brew)" && opts="brew ${opts}"
  270. # XXX: This is being removed in another PR.
  271. echo >&2
  272. REPLY=
  273. while [ -z "${REPLY}" ]; do
  274. echo "To proceed please write one of these:"
  275. echo "${opts// /, }"
  276. if ! read -r -p ">" REPLY; then
  277. continue
  278. fi
  279. if [ "${REPLY}" = "yum" ] && [ -z "${distribution}" ]; then
  280. REPLY=
  281. while [ -z "${REPLY}" ]; do
  282. if ! read -r -p "yum in centos, rhel, ol or fedora? > "; then
  283. continue
  284. fi
  285. case "${REPLY,,}" in
  286. fedora | rhel)
  287. distribution="rhel"
  288. ;;
  289. ol)
  290. distribution="ol"
  291. ;;
  292. centos)
  293. distribution="centos"
  294. ;;
  295. *)
  296. echo >&2 "Please enter 'centos', 'fedora', 'ol' or 'rhel'."
  297. REPLY=
  298. ;;
  299. esac
  300. done
  301. REPLY="yum"
  302. fi
  303. check_package_manager "${REPLY}" || REPLY=
  304. done
  305. }
  306. detect_package_manager_from_distribution() {
  307. case "${1,,}" in
  308. arch* | manjaro*)
  309. package_installer="install_pacman"
  310. tree="arch"
  311. if [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${pacman}" ]; then
  312. echo >&2 "command 'pacman' is required to install packages on a '${distribution} ${version}' system."
  313. exit 1
  314. fi
  315. ;;
  316. sabayon*)
  317. package_installer="install_equo"
  318. tree="sabayon"
  319. if [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${equo}" ]; then
  320. echo >&2 "command 'equo' is required to install packages on a '${distribution} ${version}' system."
  321. # Maybe offer to fall back on emerge? Both installers exist in Sabayon...
  322. exit 1
  323. fi
  324. ;;
  325. alpine*)
  326. package_installer="install_apk"
  327. tree="alpine"
  328. if [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${apk}" ]; then
  329. echo >&2 "command 'apk' is required to install packages on a '${distribution} ${version}' system."
  330. exit 1
  331. fi
  332. ;;
  333. gentoo*)
  334. package_installer="install_emerge"
  335. tree="gentoo"
  336. if [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${emerge}" ]; then
  337. echo >&2 "command 'emerge' is required to install packages on a '${distribution} ${version}' system."
  338. exit 1
  339. fi
  340. ;;
  341. debian* | ubuntu*)
  342. package_installer="install_apt_get"
  343. tree="debian"
  344. if [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${apt_get}" ]; then
  345. echo >&2 "command 'apt-get' is required to install packages on a '${distribution} ${version}' system."
  346. exit 1
  347. fi
  348. ;;
  349. centos* | clearos* | rocky* | almalinux*)
  350. package_installer=""
  351. tree="centos"
  352. [[ -n "${dnf}" ]] && package_installer="install_dnf"
  353. [[ -n "${yum}" ]] && package_installer="install_yum"
  354. if [[ "${IGNORE_INSTALLED}" -eq 0 ]] && [[ -z "${package_installer}" ]]; then
  355. echo >&2 "command 'yum' or 'dnf' is required to install packages on a '${distribution} ${version}' system."
  356. exit 1
  357. fi
  358. ;;
  359. redhat* | red\ hat* | rhel*)
  360. package_installer=
  361. tree="rhel"
  362. [[ -n "${dnf}" ]] && package_installer="install_dnf"
  363. [[ -n "${yum}" ]] && package_installer="install_yum"
  364. if [[ "${IGNORE_INSTALLED}" -eq 0 ]] && [[ -z "${package_installer}" ]]; then
  365. echo >&2 "command 'yum' or 'dnf' is required to install packages on a '${distribution} ${version}' system."
  366. exit 1
  367. fi
  368. ;;
  369. fedora*)
  370. package_installer="install_dnf"
  371. tree="rhel"
  372. if [[ "${IGNORE_INSTALLED}" -eq 0 ]] && [[ -z "${package_installer}" ]]; then
  373. echo >&2 "command 'yum' or 'dnf' is required to install packages on a '${distribution} ${version}' system."
  374. exit 1
  375. fi
  376. ;;
  377. ol*)
  378. package_installer=
  379. tree="ol"
  380. [ -n "${yum}" ] && package_installer="install_yum"
  381. [ -n "${dnf}" ] && package_installer="install_dnf"
  382. if [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${package_installer}" ]; then
  383. echo >&2 "command 'yum' or 'dnf' is required to install packages on a '${distribution} ${version}' system."
  384. exit 1
  385. fi
  386. ;;
  387. suse* | opensuse* | sles*)
  388. package_installer="install_zypper"
  389. tree="suse"
  390. if [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${zypper}" ]; then
  391. echo >&2 "command 'zypper' is required to install packages on a '${distribution} ${version}' system."
  392. exit 1
  393. fi
  394. ;;
  395. clear-linux* | clearlinux*)
  396. package_installer="install_swupd"
  397. tree="clearlinux"
  398. if [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${swupd}" ]; then
  399. echo >&2 "command 'swupd' is required to install packages on a '${distribution} ${version}' system."
  400. exit 1
  401. fi
  402. ;;
  403. freebsd)
  404. package_installer="install_pkg"
  405. tree="freebsd"
  406. if [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${pkg}" ]; then
  407. echo >&2 "command 'pkg' is required to install packages on a '${distribution} ${version}' system."
  408. exit 1
  409. fi
  410. ;;
  411. macos)
  412. package_installer="install_brew"
  413. tree="macos"
  414. if [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${brew}" ]; then
  415. echo >&2 "command 'brew' is required to install packages on a '${distribution} ${version}' system. Get instructions at https://brew.sh/"
  416. exit 1
  417. fi
  418. ;;
  419. *)
  420. # oops! unknown system
  421. user_picks_distribution
  422. ;;
  423. esac
  424. }
  425. # XXX: This is being removed in another PR.
  426. check_package_manager() {
  427. # This is called only when the user is selecting a package manager
  428. # It is used to verify the user selection is right
  429. echo >&2 "Checking package manager: ${1}"
  430. case "${1}" in
  431. apt-get)
  432. [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${apt_get}" ] && echo >&2 "${1} is not available." && return 1
  433. package_installer="install_apt_get"
  434. tree="debian"
  435. detection="user-input"
  436. return 0
  437. ;;
  438. dnf)
  439. [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${dnf}" ] && echo >&2 "${1} is not available." && return 1
  440. package_installer="install_dnf"
  441. if [ "${distribution}" = "centos" ]; then
  442. tree="centos"
  443. elif [ "${distribution}" = "ol" ]; then
  444. tree="ol"
  445. else
  446. tree="rhel"
  447. fi
  448. detection="user-input"
  449. return 0
  450. ;;
  451. apk)
  452. [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${apk}" ] && echo >&2 "${1} is not available." && return 1
  453. package_installer="install_apk"
  454. tree="alpine"
  455. detection="user-input"
  456. return 0
  457. ;;
  458. equo)
  459. [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${equo}" ] && echo >&2 "${1} is not available." && return 1
  460. package_installer="install_equo"
  461. tree="sabayon"
  462. detection="user-input"
  463. return 0
  464. ;;
  465. emerge)
  466. [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${emerge}" ] && echo >&2 "${1} is not available." && return 1
  467. package_installer="install_emerge"
  468. tree="gentoo"
  469. detection="user-input"
  470. return 0
  471. ;;
  472. pacman)
  473. [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${pacman}" ] && echo >&2 "${1} is not available." && return 1
  474. package_installer="install_pacman"
  475. tree="arch"
  476. detection="user-input"
  477. return 0
  478. ;;
  479. zypper)
  480. [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${zypper}" ] && echo >&2 "${1} is not available." && return 1
  481. package_installer="install_zypper"
  482. tree="suse"
  483. detection="user-input"
  484. return 0
  485. ;;
  486. yum)
  487. [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${yum}" ] && echo >&2 "${1} is not available." && return 1
  488. package_installer="install_yum"
  489. if [ "${distribution}" = "centos" ]; then
  490. tree="centos"
  491. elif [ "${distribution}" = "ol" ]; then
  492. tree="ol"
  493. else
  494. tree="rhel"
  495. fi
  496. detection="user-input"
  497. return 0
  498. ;;
  499. swupd)
  500. [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${swupd}" ] && echo >&2 "${1} is not available." && return 1
  501. package_installer="install_swupd"
  502. tree="clear-linux"
  503. detection="user-input"
  504. return 0
  505. ;;
  506. brew)
  507. [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${brew}" ] && echo >&2 "${1} is not available." && return 1
  508. package_installer="install_brew"
  509. tree="macos"
  510. detection="user-input"
  511. return 0
  512. ;;
  513. *)
  514. echo >&2 "Invalid package manager: '${1}'."
  515. return 1
  516. ;;
  517. esac
  518. }
  519. require_cmd() {
  520. # check if any of the commands given as argument
  521. # are present on this system
  522. # If any of them is available, it returns 0
  523. # otherwise 1
  524. [ "${IGNORE_INSTALLED}" -eq 1 ] && return 1
  525. local wanted found
  526. for wanted in "${@}"; do
  527. if command -v "${wanted}" > /dev/null 2>&1; then
  528. found="$(command -v "$wanted" 2> /dev/null)"
  529. fi
  530. [ -n "${found}" ] && [ -x "${found}" ] && return 0
  531. done
  532. return 1
  533. }
  534. declare -A pkg_find=(
  535. ['gentoo']="sys-apps/findutils"
  536. ['fedora']="findutils"
  537. ['clearlinux']="findutils"
  538. ['rhel']="findutils"
  539. ['centos']="findutils"
  540. ['macos']="NOTREQUIRED"
  541. ['freebsd']="NOTREQUIRED"
  542. ['default']="WARNING|"
  543. )
  544. declare -A pkg_distro_sdk=(
  545. ['alpine']="alpine-sdk"
  546. ['centos']="kernel-headers"
  547. ['default']="NOTREQUIRED"
  548. )
  549. declare -A pkg_coreutils=(
  550. ['alpine']="coreutils"
  551. ['default']="NOTREQUIRED"
  552. )
  553. declare -A pkg_cmake=(
  554. ['gentoo']="dev-util/cmake"
  555. ['clearlinux']="c-basic"
  556. ['default']="cmake"
  557. )
  558. declare -A pkg_json_c_dev=(
  559. ['alpine']="json-c-dev"
  560. ['arch']="json-c"
  561. ['clearlinux']="devpkg-json-c"
  562. ['debian']="libjson-c-dev"
  563. ['gentoo']="dev-libs/json-c"
  564. ['sabayon']="dev-libs/json-c"
  565. ['suse']="libjson-c-devel"
  566. ['freebsd']="json-c"
  567. ['macos']="json-c"
  568. ['default']="json-c-devel"
  569. )
  570. #TODO:: clearlinux ?
  571. declare -A pkg_libyaml_dev=(
  572. ['alpine']="yaml-dev"
  573. ['arch']="libyaml"
  574. ['clearlinux']="yaml-dev"
  575. ['debian']="libyaml-dev"
  576. ['gentoo']="dev-libs/libyaml"
  577. ['sabayon']="dev-libs/libyaml"
  578. ['suse']="libyaml-devel"
  579. ['freebsd']="libyaml"
  580. ['macos']="libyaml"
  581. ['default']="libyaml-devel"
  582. )
  583. declare -A pkg_libatomic=(
  584. ['arch']="NOTREQUIRED"
  585. ['clearlinux']="NOTREQUIRED"
  586. ['debian']="libatomic1"
  587. ['freebsd']="NOTREQUIRED"
  588. ['gentoo']="NOTREQUIRED"
  589. ['macos']="NOTREQUIRED"
  590. ['sabayon']="NOTREQUIRED"
  591. ['suse']="libatomic1"
  592. ['ubuntu']="libatomic1"
  593. ['default']="libatomic"
  594. )
  595. declare -A pkg_libsystemd_dev=(
  596. ['alpine']="NOTREQUIRED"
  597. ['arch']="NOTREQUIRED" # inherently present on systems actually using systemd
  598. ['clearlinux']="system-os-dev"
  599. ['debian']="libsystemd-dev"
  600. ['freebsd']="NOTREQUIRED"
  601. ['gentoo']="NOTREQUIRED" # inherently present on systems actually using systemd
  602. ['macos']="NOTREQUIRED"
  603. ['sabayon']="NOTREQUIRED" # inherently present on systems actually using systemd
  604. ['ubuntu']="libsystemd-dev"
  605. ['default']="systemd-devel"
  606. )
  607. declare -A pkg_pcre2=(
  608. ['alpine']="pcre2-dev"
  609. ['arch']="pcre2"
  610. ['centos']="pcre2-devel"
  611. ['debian']="libpcre2-dev"
  612. ['freebsd']="pcre2"
  613. ['macos']="pcre2"
  614. ['rhel']="pcre2-devel"
  615. ['suse']="pcre2-devel"
  616. ['ubuntu']="libpcre2-dev"
  617. ['default']="NOTREQUIRED"
  618. )
  619. declare -A pkg_bridge_utils=(
  620. ['gentoo']="net-misc/bridge-utils"
  621. ['clearlinux']="network-basic"
  622. ['macos']="WARNING|"
  623. ['default']="bridge-utils"
  624. )
  625. declare -A pkg_curl=(
  626. ['gentoo']="net-misc/curl"
  627. ['sabayon']="net-misc/curl"
  628. ['default']="curl"
  629. )
  630. declare -A pkg_gzip=(
  631. ['gentoo']="app-alternatives/gzip"
  632. ['macos']="NOTREQUIRED"
  633. ['default']="gzip"
  634. )
  635. declare -A pkg_tar=(
  636. ['gentoo']="app-alternatives/tar"
  637. ['clearlinux']="os-core-update"
  638. ['macos']="NOTREQUIRED"
  639. ['freebsd']="NOTREQUIRED"
  640. ['default']="tar"
  641. )
  642. declare -A pkg_git=(
  643. ['gentoo']="dev-vcs/git"
  644. ['default']="git"
  645. )
  646. declare -A pkg_gcc=(
  647. ['gentoo']="sys-devel/gcc"
  648. ['clearlinux']="c-basic"
  649. ['macos']="NOTREQUIRED"
  650. ['default']="gcc"
  651. )
  652. # g++, required for building protobuf
  653. # All three cases of this not being required are systems that implicitly
  654. # include g++ when installing gcc.
  655. declare -A pkg_gxx=(
  656. ['alpine']="g++"
  657. ['arch']="NOTREQUIRED"
  658. ['clearlinux']="c-basic"
  659. ['debian']="g++"
  660. ['gentoo']="NOTREQUIRED"
  661. ['macos']="NOTREQUIRED"
  662. ['ubuntu']="g++"
  663. ['freebsd']="NOTREQUIRED"
  664. ['default']="gcc-c++"
  665. )
  666. declare -A pkg_gdb=(
  667. ['gentoo']="sys-devel/gdb"
  668. ['macos']="NOTREQUIRED"
  669. ['default']="gdb"
  670. )
  671. declare -A pkg_iotop=(
  672. ['gentoo']="sys-process/iotop"
  673. ['macos']="WARNING|"
  674. ['default']="iotop"
  675. )
  676. declare -A pkg_iproute2=(
  677. ['alpine']="iproute2"
  678. ['debian']="iproute2"
  679. ['gentoo']="sys-apps/iproute2"
  680. ['sabayon']="sys-apps/iproute2"
  681. ['clearlinux']="iproute2"
  682. ['macos']="WARNING|"
  683. ['default']="iproute"
  684. # exceptions
  685. ['ubuntu-12.04']="iproute"
  686. )
  687. declare -A pkg_ipset=(
  688. ['gentoo']="net-firewall/ipset"
  689. ['clearlinux']="network-basic"
  690. ['macos']="WARNING|"
  691. ['default']="ipset"
  692. )
  693. declare -A pkg_jq=(
  694. ['gentoo']="app-misc/jq"
  695. ['default']="jq"
  696. )
  697. declare -A pkg_iptables=(
  698. ['gentoo']="net-firewall/iptables"
  699. ['macos']="WARNING|"
  700. ['default']="iptables"
  701. )
  702. declare -A pkg_libz_dev=(
  703. ['alpine']="zlib-dev"
  704. ['arch']="zlib"
  705. ['centos']="zlib-devel"
  706. ['debian']="zlib1g-dev"
  707. ['gentoo']="sys-libs/zlib"
  708. ['sabayon']="sys-libs/zlib"
  709. ['rhel']="zlib-devel"
  710. ['ol']="zlib-devel"
  711. ['suse']="zlib-devel"
  712. ['clearlinux']="devpkg-zlib"
  713. ['macos']="NOTREQUIRED"
  714. ['freebsd']="lzlib"
  715. ['default']=""
  716. )
  717. declare -A pkg_libuuid_dev=(
  718. ['alpine']="util-linux-dev"
  719. ['arch']="util-linux"
  720. ['centos']="libuuid-devel"
  721. ['clearlinux']="devpkg-util-linux"
  722. ['debian']="uuid-dev"
  723. ['gentoo']="sys-apps/util-linux"
  724. ['sabayon']="sys-apps/util-linux"
  725. ['rhel']="libuuid-devel"
  726. ['ol']="libuuid-devel"
  727. ['suse']="libuuid-devel"
  728. ['macos']="ossp-uuid"
  729. ['freebsd']="e2fsprogs-libuuid"
  730. ['default']=""
  731. )
  732. declare -A pkg_libcurl_dev=(
  733. ['alpine']="curl-dev"
  734. ['arch']="curl"
  735. ['clearlinux']="devpkg-curl"
  736. ['debian']="libcurl4-openssl-dev"
  737. ['gentoo']="net-misc/curl"
  738. ['ubuntu']="libcurl4-openssl-dev"
  739. ['macos']="curl"
  740. ['freebsd']="curl"
  741. ['default']="libcurl-devel"
  742. )
  743. declare -A pkg_libmnl_dev=(
  744. ['alpine']="libmnl-dev"
  745. ['arch']="libmnl"
  746. ['centos']="libmnl-devel"
  747. ['debian']="libmnl-dev"
  748. ['gentoo']="net-libs/libmnl"
  749. ['sabayon']="net-libs/libmnl"
  750. ['rhel']="libmnl-devel"
  751. ['ol']="libmnl-devel"
  752. ['suse']="libmnl-devel"
  753. ['clearlinux']="devpkg-libmnl"
  754. ['macos']="NOTREQUIRED"
  755. ['default']=""
  756. )
  757. declare -A pkg_lm_sensors=(
  758. ['alpine']="lm_sensors"
  759. ['arch']="lm_sensors"
  760. ['centos']="lm_sensors"
  761. ['debian']="lm-sensors"
  762. ['gentoo']="sys-apps/lm-sensors"
  763. ['sabayon']="sys-apps/lm_sensors"
  764. ['rhel']="lm_sensors"
  765. ['suse']="sensors"
  766. ['clearlinux']="lm-sensors"
  767. ['macos']="WARNING|"
  768. ['freebsd']="NOTREQUIRED"
  769. ['default']="lm_sensors"
  770. )
  771. declare -A pkg_logwatch=(
  772. ['gentoo']="sys-apps/logwatch"
  773. ['clearlinux']="WARNING|"
  774. ['macos']="WARNING|"
  775. ['default']="logwatch"
  776. )
  777. declare -A pkg_lxc=(
  778. ['gentoo']="app-emulation/lxc"
  779. ['clearlinux']="WARNING|"
  780. ['macos']="WARNING|"
  781. ['default']="lxc"
  782. )
  783. declare -A pkg_mailutils=(
  784. ['gentoo']="net-mail/mailutils"
  785. ['clearlinux']="WARNING|"
  786. ['macos']="WARNING|"
  787. ['default']="mailutils"
  788. )
  789. declare -A pkg_make=(
  790. ['gentoo']="sys-devel/make"
  791. ['macos']="NOTREQUIRED"
  792. ['freebsd']="gmake"
  793. ['default']="make"
  794. )
  795. declare -A pkg_nginx=(
  796. ['gentoo']="www-servers/nginx"
  797. ['default']="nginx"
  798. )
  799. declare -A pkg_postfix=(
  800. ['gentoo']="mail-mta/postfix"
  801. ['macos']="WARNING|"
  802. ['default']="postfix"
  803. )
  804. declare -A pkg_pkg_config=(
  805. ['alpine']="pkgconf"
  806. ['arch']="pkgconfig"
  807. ['centos']="pkgconfig"
  808. ['debian']="pkg-config"
  809. ['gentoo']="virtual/pkgconfig"
  810. ['sabayon']="virtual/pkgconfig"
  811. ['rhel']="pkgconfig"
  812. ['ol']="pkgconfig"
  813. ['suse']="pkg-config"
  814. ['freebsd']="pkgconf"
  815. ['clearlinux']="c-basic"
  816. ['default']="pkg-config"
  817. )
  818. declare -A pkg_python=(
  819. ['gentoo']="dev-lang/python"
  820. ['sabayon']="dev-lang/python:2.7"
  821. ['clearlinux']="python-basic"
  822. ['default']="python"
  823. # Exceptions
  824. ['macos']="WARNING|"
  825. ['centos-8']="python2"
  826. )
  827. declare -A pkg_python_pip=(
  828. ['alpine']="py-pip"
  829. ['gentoo']="dev-python/pip"
  830. ['sabayon']="dev-python/pip"
  831. ['clearlinux']="python-basic"
  832. ['macos']="WARNING|"
  833. ['default']="python-pip"
  834. )
  835. declare -A pkg_python3_pip=(
  836. ['alpine']="py3-pip"
  837. ['arch']="python-pip"
  838. ['gentoo']="dev-python/pip"
  839. ['sabayon']="dev-python/pip"
  840. ['clearlinux']="python3-basic"
  841. ['macos']="NOTREQUIRED"
  842. ['default']="python3-pip"
  843. )
  844. declare -A pkg_python_requests=(
  845. ['alpine']="py-requests"
  846. ['arch']="python2-requests"
  847. ['centos']="python-requests"
  848. ['debian']="python-requests"
  849. ['gentoo']="dev-python/requests"
  850. ['sabayon']="dev-python/requests"
  851. ['rhel']="python-requests"
  852. ['suse']="python-requests"
  853. ['clearlinux']="python-extras"
  854. ['macos']="WARNING|"
  855. ['default']="python-requests"
  856. ['alpine-3.1.4']="WARNING|"
  857. ['alpine-3.2.3']="WARNING|"
  858. )
  859. declare -A pkg_python3_requests=(
  860. ['alpine']="py3-requests"
  861. ['arch']="python-requests"
  862. ['centos']="WARNING|"
  863. ['debian']="WARNING|"
  864. ['gentoo']="dev-python/requests"
  865. ['sabayon']="dev-python/requests"
  866. ['rhel']="WARNING|"
  867. ['suse']="WARNING|"
  868. ['clearlinux']="python-extras"
  869. ['macos']="WARNING|"
  870. ['default']="WARNING|"
  871. ['centos-7']="python36-requests"
  872. ['centos-8']="python3-requests"
  873. ['rhel-7']="python36-requests"
  874. ['rhel-8']="python3-requests"
  875. ['ol-8']="python3-requests"
  876. )
  877. declare -A pkg_lz4=(
  878. ['alpine']="lz4-dev"
  879. ['debian']="liblz4-dev"
  880. ['ubuntu']="liblz4-dev"
  881. ['suse']="liblz4-devel"
  882. ['gentoo']="app-arch/lz4"
  883. ['clearlinux']="devpkg-lz4"
  884. ['arch']="lz4"
  885. ['macos']="lz4"
  886. ['freebsd']="liblz4"
  887. ['default']="lz4-devel"
  888. )
  889. declare -A pkg_zstd=(
  890. ['alpine']="zstd-dev"
  891. ['debian']="libzstd-dev"
  892. ['ubuntu']="libzstd-dev"
  893. ['gentoo']="app-arch/zstd"
  894. ['clearlinux']="zstd-devel"
  895. ['arch']="zstd"
  896. ['macos']="zstd"
  897. ['freebsd']="zstd"
  898. ['default']="libzstd-devel"
  899. )
  900. declare -A pkg_libuv=(
  901. ['alpine']="libuv-dev"
  902. ['debian']="libuv1-dev"
  903. ['ubuntu']="libuv1-dev"
  904. ['gentoo']="dev-libs/libuv"
  905. ['arch']="libuv"
  906. ['clearlinux']="devpkg-libuv"
  907. ['macos']="libuv"
  908. ['freebsd']="libuv"
  909. ['default']="libuv-devel"
  910. )
  911. declare -A pkg_openssl=(
  912. ['alpine']="openssl-dev"
  913. ['debian']="libssl-dev"
  914. ['ubuntu']="libssl-dev"
  915. ['suse']="libopenssl-devel"
  916. ['clearlinux']="devpkg-openssl"
  917. ['gentoo']="dev-libs/openssl"
  918. ['arch']="openssl"
  919. ['freebsd']="openssl"
  920. ['macos']="openssl"
  921. ['default']="openssl-devel"
  922. )
  923. declare -A pkg_python3=(
  924. ['gentoo']="dev-lang/python"
  925. ['sabayon']="dev-lang/python:3.4"
  926. ['clearlinux']="python3-basic"
  927. ['macos']="python"
  928. ['default']="python3"
  929. # exceptions
  930. ['centos-6']="WARNING|"
  931. )
  932. declare -A pkg_screen=(
  933. ['gentoo']="app-misc/screen"
  934. ['sabayon']="app-misc/screen"
  935. ['clearlinux']="sysadmin-basic"
  936. ['default']="screen"
  937. )
  938. declare -A pkg_sudo=(
  939. ['gentoo']="app-admin/sudo"
  940. ['macos']="NOTREQUIRED"
  941. ['default']="sudo"
  942. )
  943. declare -A pkg_sysstat=(
  944. ['gentoo']="app-admin/sysstat"
  945. ['macos']="WARNING|"
  946. ['default']="sysstat"
  947. )
  948. declare -A pkg_tcpdump=(
  949. ['gentoo']="net-analyzer/tcpdump"
  950. ['clearlinux']="network-basic"
  951. ['default']="tcpdump"
  952. )
  953. declare -A pkg_traceroute=(
  954. ['alpine']=" "
  955. ['gentoo']="net-analyzer/traceroute"
  956. ['clearlinux']="network-basic"
  957. ['macos']="NOTREQUIRED"
  958. ['default']="traceroute"
  959. )
  960. declare -A pkg_valgrind=(
  961. ['gentoo']="dev-util/valgrind"
  962. ['default']="valgrind"
  963. )
  964. declare -A pkg_ulogd=(
  965. ['centos']="WARNING|"
  966. ['rhel']="WARNING|"
  967. ['ol']="WARNING|"
  968. ['clearlinux']="WARNING|"
  969. ['gentoo']="app-admin/ulogd"
  970. ['arch']="ulogd"
  971. ['macos']="WARNING|"
  972. ['default']="ulogd2"
  973. )
  974. declare -A pkg_unzip=(
  975. ['gentoo']="app-arch/unzip"
  976. ['macos']="NOTREQUIRED"
  977. ['default']="unzip"
  978. )
  979. declare -A pkg_zip=(
  980. ['gentoo']="app-arch/zip"
  981. ['macos']="NOTREQUIRED"
  982. ['default']="zip"
  983. )
  984. declare -A pkg_libelf=(
  985. ['alpine']="elfutils-dev"
  986. ['arch']="libelf"
  987. ['gentoo']="virtual/libelf"
  988. ['sabayon']="virtual/libelf"
  989. ['debian']="libelf-dev"
  990. ['ubuntu']="libelf-dev"
  991. ['fedora']="elfutils-libelf-devel"
  992. ['centos']="elfutils-libelf-devel"
  993. ['rhel']="elfutils-libelf-devel"
  994. ['ol']="elfutils-libelf-devel"
  995. ['clearlinux']="devpkg-elfutils"
  996. ['suse']="libelf-devel"
  997. ['macos']="NOTREQUIRED"
  998. ['freebsd']="NOTREQUIRED"
  999. ['default']="libelf-devel"
  1000. # exceptions
  1001. ['alpine-3.5']="libelf-dev"
  1002. ['alpine-3.4']="libelf-dev"
  1003. ['alpine-3.3']="libelf-dev"
  1004. )
  1005. validate_package_trees() {
  1006. if type -t validate_tree_${tree} > /dev/null; then
  1007. validate_tree_${tree}
  1008. fi
  1009. }
  1010. validate_installed_package() {
  1011. validate_${package_installer} "${p}"
  1012. }
  1013. suitable_package() {
  1014. local package="${1//-/_}" p="" v="${version//.*/}"
  1015. echo >&2 "Searching for ${package} ..."
  1016. eval "p=\${pkg_${package}['${distribution,,}-${version,,}']}"
  1017. [ -z "${p}" ] && eval "p=\${pkg_${package}['${distribution,,}-${v,,}']}"
  1018. [ -z "${p}" ] && eval "p=\${pkg_${package}['${distribution,,}']}"
  1019. [ -z "${p}" ] && eval "p=\${pkg_${package}['${tree}-${version}']}"
  1020. [ -z "${p}" ] && eval "p=\${pkg_${package}['${tree}-${v}']}"
  1021. [ -z "${p}" ] && eval "p=\${pkg_${package}['${tree}']}"
  1022. [ -z "${p}" ] && eval "p=\${pkg_${package}['default']}"
  1023. if [[ "${p/|*/}" =~ ^(ERROR|WARNING|INFO)$ ]]; then
  1024. echo >&2 "${p/|*/}"
  1025. echo >&2 "package ${1} is not available in this system."
  1026. if [ -z "${p/*|/}" ]; then
  1027. echo >&2 "You may try to install without it."
  1028. else
  1029. echo >&2 "${p/*|/}"
  1030. fi
  1031. echo >&2
  1032. return 1
  1033. elif [ "${p}" = "NOTREQUIRED" ]; then
  1034. return 0
  1035. elif [ -z "${p}" ]; then
  1036. echo >&2 "WARNING"
  1037. echo >&2 "package ${1} is not available in this system."
  1038. echo >&2
  1039. return 1
  1040. else
  1041. if [ "${IGNORE_INSTALLED}" -eq 0 ]; then
  1042. validate_installed_package "${p}"
  1043. else
  1044. echo "${p}"
  1045. fi
  1046. return 0
  1047. fi
  1048. }
  1049. packages() {
  1050. # detect the packages we need to install on this system
  1051. # -------------------------------------------------------------------------
  1052. # basic build environment
  1053. suitable_package distro-sdk
  1054. suitable_package coreutils
  1055. suitable_package libatomic
  1056. require_cmd git || suitable_package git
  1057. require_cmd find || suitable_package find
  1058. require_cmd gcc || require_cmd clang ||
  1059. require_cmd gcc-multilib || suitable_package gcc
  1060. require_cmd g++ || require_cmd clang++ || suitable_package gxx
  1061. require_cmd pkg-config || suitable_package pkg-config
  1062. require_cmd cmake || suitable_package cmake
  1063. require_cmd make || suitable_package make
  1064. # -------------------------------------------------------------------------
  1065. # debugging tools for development
  1066. if [ "${PACKAGES_DEBUG}" -ne 0 ]; then
  1067. require_cmd traceroute || suitable_package traceroute
  1068. require_cmd tcpdump || suitable_package tcpdump
  1069. require_cmd screen || suitable_package screen
  1070. if [ "${PACKAGES_NETDATA}" -ne 0 ]; then
  1071. require_cmd gdb || suitable_package gdb
  1072. require_cmd valgrind || suitable_package valgrind
  1073. fi
  1074. fi
  1075. # -------------------------------------------------------------------------
  1076. # common command line tools
  1077. if [ "${PACKAGES_NETDATA}" -ne 0 ]; then
  1078. require_cmd tar || suitable_package tar
  1079. require_cmd curl || suitable_package curl
  1080. require_cmd gzip || suitable_package gzip
  1081. fi
  1082. # -------------------------------------------------------------------------
  1083. # firehol/fireqos/update-ipsets command line tools
  1084. if [ "${PACKAGES_FIREQOS}" -ne 0 ]; then
  1085. require_cmd ip || suitable_package iproute2
  1086. fi
  1087. if [ "${PACKAGES_FIREHOL}" -ne 0 ]; then
  1088. require_cmd iptables || suitable_package iptables
  1089. require_cmd ipset || suitable_package ipset
  1090. require_cmd ulogd ulogd2 || suitable_package ulogd
  1091. require_cmd traceroute || suitable_package traceroute
  1092. require_cmd bridge || suitable_package bridge-utils
  1093. fi
  1094. if [ "${PACKAGES_UPDATE_IPSETS}" -ne 0 ]; then
  1095. require_cmd ipset || suitable_package ipset
  1096. require_cmd zip || suitable_package zip
  1097. require_cmd funzip || suitable_package unzip
  1098. fi
  1099. # -------------------------------------------------------------------------
  1100. # netdata libraries
  1101. if [ "${PACKAGES_NETDATA}" -ne 0 ]; then
  1102. suitable_package libz-dev
  1103. suitable_package libuuid-dev
  1104. suitable_package libmnl-dev
  1105. suitable_package json-c-dev
  1106. suitable_package libyaml-dev
  1107. suitable_package libsystemd-dev
  1108. suitable_package pcre2
  1109. suitable_package libcurl-dev
  1110. fi
  1111. # -------------------------------------------------------------------------
  1112. # sensors
  1113. if [ "${PACKAGES_NETDATA_SENSORS}" -ne 0 ]; then
  1114. require_cmd sensors || suitable_package lm_sensors
  1115. fi
  1116. # -------------------------------------------------------------------------
  1117. # netdata database
  1118. if [ "${PACKAGES_NETDATA_DATABASE}" -ne 0 ]; then
  1119. suitable_package libuv
  1120. suitable_package lz4
  1121. suitable_package openssl
  1122. fi
  1123. if [ "${PACKAGES_NETDATA_STREAMING_COMPRESSION}" -ne 0 ]; then
  1124. suitable_package zstd
  1125. fi
  1126. # -------------------------------------------------------------------------
  1127. # ebpf plugin
  1128. if [ "${PACKAGES_NETDATA_EBPF}" -ne 0 ]; then
  1129. suitable_package libelf
  1130. fi
  1131. # -------------------------------------------------------------------------
  1132. # python2
  1133. if [ "${PACKAGES_NETDATA_PYTHON}" -ne 0 ]; then
  1134. require_cmd python || suitable_package python
  1135. fi
  1136. # -------------------------------------------------------------------------
  1137. # python3
  1138. if [ "${PACKAGES_NETDATA_PYTHON3}" -ne 0 ]; then
  1139. require_cmd python3 || suitable_package python3
  1140. fi
  1141. # -------------------------------------------------------------------------
  1142. # applications needed for the netdata demo sites
  1143. if [ "${PACKAGES_NETDATA_DEMO_SITE}" -ne 0 ]; then
  1144. require_cmd sudo || suitable_package sudo
  1145. require_cmd jq || suitable_package jq
  1146. require_cmd nginx || suitable_package nginx
  1147. require_cmd postconf || suitable_package postfix
  1148. require_cmd lxc-create || suitable_package lxc
  1149. require_cmd logwatch || suitable_package logwatch
  1150. require_cmd mail || suitable_package mailutils
  1151. require_cmd iostat || suitable_package sysstat
  1152. require_cmd iotop || suitable_package iotop
  1153. fi
  1154. }
  1155. DRYRUN=0
  1156. run() {
  1157. printf >&2 "%q " "${@}"
  1158. printf >&2 "\n"
  1159. if [ ! "${DRYRUN}" -eq 1 ]; then
  1160. "${@}"
  1161. return $?
  1162. fi
  1163. return 0
  1164. }
  1165. sudo=
  1166. if [ ${UID} -ne 0 ]; then
  1167. sudo="sudo"
  1168. fi
  1169. # -----------------------------------------------------------------------------
  1170. # debian / ubuntu
  1171. validate_install_apt_get() {
  1172. echo >&2 " > Checking if package '${*}' is installed..."
  1173. [ "$(dpkg-query -W --showformat='${Status}\n' "${*}")" = "install ok installed" ] || echo "${*}"
  1174. }
  1175. install_apt_get() {
  1176. local opts=""
  1177. if [ "${NON_INTERACTIVE}" -eq 1 ]; then
  1178. echo >&2 "Running in non-interactive mode"
  1179. # http://serverfault.com/questions/227190/how-do-i-ask-apt-get-to-skip-any-interactive-post-install-configuration-steps
  1180. export DEBIAN_FRONTEND="noninteractive"
  1181. opts="${opts} -yq"
  1182. fi
  1183. read -r -a apt_opts <<< "$opts"
  1184. # update apt repository caches
  1185. echo >&2 "NOTE: Running apt-get update and updating your APT caches ..."
  1186. if [ "${version}" = 8 ]; then
  1187. echo >&2 "WARNING: You seem to be on Debian 8 (jessie) which is old enough we have to disable Check-Valid-Until checks"
  1188. if ! cat /etc/apt/sources.list /etc/apt/sources.list.d/* 2> /dev/null | grep -q jessie-backports; then
  1189. echo >&2 "We also have to enable the jessie-backports repository"
  1190. if prompt "Is this okay?"; then
  1191. ${sudo} /bin/sh -c 'echo "deb http://archive.debian.org/debian/ jessie-backports main contrib non-free" >> /etc/apt/sources.list.d/99-archived.list'
  1192. fi
  1193. fi
  1194. run ${sudo} apt-get "${apt_opts[@]}" -o Acquire::Check-Valid-Until=false update
  1195. else
  1196. run ${sudo} apt-get "${apt_opts[@]}" update
  1197. fi
  1198. # install the required packages
  1199. run ${sudo} apt-get "${apt_opts[@]}" install "${@}"
  1200. }
  1201. # -----------------------------------------------------------------------------
  1202. # centos / rhel
  1203. prompt() {
  1204. if [ "${NON_INTERACTIVE}" -eq 1 ]; then
  1205. echo >&2 "Running in non-interactive mode, assuming yes (y)"
  1206. echo >&2 " > Would have prompted for ${1} ..."
  1207. return 0
  1208. fi
  1209. while true; do
  1210. read -r -p "${1} [y/n] " yn
  1211. case $yn in
  1212. [Yy]*) return 0 ;;
  1213. [Nn]*) return 1 ;;
  1214. *) echo >&2 "Please answer with yes (y) or no (n)." ;;
  1215. esac
  1216. done
  1217. }
  1218. validate_tree_freebsd() {
  1219. local opts=
  1220. if [ "${NON_INTERACTIVE}" -eq 1 ]; then
  1221. echo >&2 "Running in non-interactive mode"
  1222. opts="-y"
  1223. fi
  1224. echo >&2 " > FreeBSD Version: ${version} ..."
  1225. make="make"
  1226. echo >&2 " > Checking for gmake ..."
  1227. if ! pkg query %n-%v | grep -q gmake; then
  1228. if prompt "gmake is required to build on FreeBSD and is not installed. Shall I install it?"; then
  1229. # shellcheck disable=2086
  1230. run ${sudo} pkg install ${opts} gmake
  1231. fi
  1232. fi
  1233. }
  1234. validate_tree_ol() {
  1235. local opts=
  1236. if [ "${NON_INTERACTIVE}" -eq 1 ]; then
  1237. echo >&2 "Running in non-interactive mode"
  1238. opts="-y"
  1239. fi
  1240. if [[ "${version}" =~ ^8(\..*)?$ ]]; then
  1241. echo " > Checking for CodeReady Builder ..."
  1242. if ! run ${sudo} dnf repolist | grep -q codeready; then
  1243. if prompt "CodeReady Builder not found, shall I install it?"; then
  1244. cat > /etc/yum.repos.d/ol8_codeready.repo <<-EOF
  1245. [ol8_codeready_builder]
  1246. name=Oracle Linux \$releasever CodeReady Builder (\$basearch)
  1247. baseurl=http://yum.oracle.com/repo/OracleLinux/OL8/codeready/builder/\$basearch
  1248. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
  1249. gpgcheck=1
  1250. enabled=1
  1251. EOF
  1252. fi
  1253. fi
  1254. elif [[ "${version}" =~ ^9(\..*)?$ ]]; then
  1255. echo " > Checking for CodeReady Builder ..."
  1256. if ! run ${sudo} dnf repolist enabled | grep -q codeready; then
  1257. if prompt "CodeReady Builder not enabled, shall I enable it?"; then
  1258. run ${sudo} dnf config-manager --set-enabled ol9_codeready_builder
  1259. fi
  1260. fi
  1261. fi
  1262. }
  1263. validate_tree_centos() {
  1264. local opts=
  1265. if [ "${NON_INTERACTIVE}" -eq 1 ]; then
  1266. echo >&2 "Running in non-interactive mode"
  1267. opts="-y"
  1268. fi
  1269. echo >&2 " > CentOS Version: ${version} ..."
  1270. if [[ "${version}" =~ ^9(\..*)?$ ]]; then
  1271. echo >&2 " > Checking for config-manager ..."
  1272. if ! run ${sudo} dnf config-manager --help; then
  1273. if prompt "config-manager not found, shall I install it?"; then
  1274. # shellcheck disable=2086
  1275. run ${sudo} dnf ${opts} install 'dnf-command(config-manager)'
  1276. fi
  1277. fi
  1278. echo >&2 " > Checking for CRB ..."
  1279. # shellcheck disable=2086
  1280. if ! run dnf ${sudo} repolist | grep CRB; then
  1281. if prompt "CRB not found, shall I install it?"; then
  1282. # shellcheck disable=2086
  1283. run ${sudo} dnf ${opts} config-manager --set-enabled crb
  1284. fi
  1285. fi
  1286. elif [[ "${version}" =~ ^8(\..*)?$ ]]; then
  1287. echo >&2 " > Checking for config-manager ..."
  1288. if ! run ${sudo} yum config-manager --help; then
  1289. if prompt "config-manager not found, shall I install it?"; then
  1290. # shellcheck disable=2086
  1291. run ${sudo} yum ${opts} install 'dnf-command(config-manager)'
  1292. fi
  1293. fi
  1294. echo >&2 " > Checking for PowerTools ..."
  1295. # shellcheck disable=2086
  1296. if ! run yum ${sudo} repolist | grep PowerTools; then
  1297. if prompt "PowerTools not found, shall I install it?"; then
  1298. # shellcheck disable=2086
  1299. run ${sudo} yum ${opts} config-manager --set-enabled powertools
  1300. fi
  1301. fi
  1302. echo >&2 " > Updating libarchive ..."
  1303. # shellcheck disable=2086
  1304. run ${sudo} yum ${opts} install libarchive
  1305. elif [[ "${version}" =~ ^7(\..*)?$ ]]; then
  1306. echo >&2 " > Checking for EPEL ..."
  1307. if ! rpm -qa | grep epel-release > /dev/null; then
  1308. if prompt "EPEL not found, shall I install it?"; then
  1309. # shellcheck disable=2086
  1310. run ${sudo} yum ${opts} install epel-release
  1311. fi
  1312. fi
  1313. elif [[ "${version}" =~ ^6\..*$ ]]; then
  1314. echo >&2 " > Detected CentOS 6.x ..."
  1315. echo >&2 " > Checking for Okay ..."
  1316. if ! rpm -qa | grep okay > /dev/null; then
  1317. if prompt "okay not found, shall I install it?"; then
  1318. # shellcheck disable=2086
  1319. run ${sudo} yum ${opts} install http://repo.okay.com.mx/centos/6/x86_64/release/okay-release-1-3.el6.noarch.rpm
  1320. fi
  1321. fi
  1322. fi
  1323. }
  1324. validate_install_yum() {
  1325. echo >&2 " > Checking if package '${*}' is installed..."
  1326. yum list installed "${*}" > /dev/null 2>&1 || echo "${*}"
  1327. }
  1328. install_yum() {
  1329. # download the latest package info
  1330. if [ "${DRYRUN}" -eq 1 ]; then
  1331. echo >&2 " >> IMPORTANT << "
  1332. echo >&2 " Please make sure your system is up to date"
  1333. echo >&2 " by running: ${sudo} yum update "
  1334. echo >&2
  1335. fi
  1336. local opts=
  1337. if [ "${NON_INTERACTIVE}" -eq 1 ]; then
  1338. echo >&2 "Running in non-interactive mode"
  1339. # http://unix.stackexchange.com/questions/87822/does-yum-have-an-equivalent-to-apt-aptitudes-debian-frontend-noninteractive
  1340. opts="-y"
  1341. fi
  1342. read -r -a yum_opts <<< "${opts}"
  1343. # install the required packages
  1344. run ${sudo} yum "${yum_opts[@]}" install "${@}"
  1345. }
  1346. # -----------------------------------------------------------------------------
  1347. # fedora
  1348. validate_install_dnf() {
  1349. echo >&2 " > Checking if package '${*}' is installed..."
  1350. dnf list --installed "${*}" > /dev/null 2>&1 || echo "${*}"
  1351. }
  1352. install_dnf() {
  1353. # download the latest package info
  1354. if [ "${DRYRUN}" -eq 1 ]; then
  1355. echo >&2 " >> IMPORTANT << "
  1356. echo >&2 " Please make sure your system is up to date"
  1357. echo >&2 " by running: ${sudo} dnf update "
  1358. echo >&2
  1359. fi
  1360. local opts=
  1361. if [ "${NON_INTERACTIVE}" -eq 1 ]; then
  1362. echo >&2 "Running in non-interactive mode"
  1363. # man dnf
  1364. opts="-y"
  1365. fi
  1366. # install the required packages
  1367. # --setopt=strict=0 allows dnf to proceed
  1368. # installing whatever is available
  1369. # even if a package is not found
  1370. opts="$opts --setopt=strict=0"
  1371. read -r -a dnf_opts <<< "$opts"
  1372. run ${sudo} dnf "${dnf_opts[@]}" install "${@}"
  1373. }
  1374. # -----------------------------------------------------------------------------
  1375. # gentoo
  1376. validate_install_emerge() {
  1377. echo "${*}"
  1378. }
  1379. install_emerge() {
  1380. # download the latest package info
  1381. # we don't do this for emerge - it is very slow
  1382. # and most users are expected to do this daily
  1383. # emerge --sync
  1384. if [ "${DRYRUN}" -eq 1 ]; then
  1385. echo >&2 " >> IMPORTANT << "
  1386. echo >&2 " Please make sure your system is up to date"
  1387. echo >&2 " by running: ${sudo} emerge --sync or ${sudo} eix-sync "
  1388. echo >&2
  1389. fi
  1390. local opts="--ask"
  1391. if [ "${NON_INTERACTIVE}" -eq 1 ]; then
  1392. echo >&2 "Running in non-interactive mode"
  1393. opts=""
  1394. fi
  1395. read -r -a emerge_opts <<< "$opts"
  1396. # install the required packages
  1397. run ${sudo} emerge "${emerge_opts[@]}" -v --noreplace "${@}"
  1398. }
  1399. # -----------------------------------------------------------------------------
  1400. # alpine
  1401. validate_install_apk() {
  1402. echo "${*}"
  1403. }
  1404. install_apk() {
  1405. # download the latest package info
  1406. if [ "${DRYRUN}" -eq 1 ]; then
  1407. echo >&2 " >> IMPORTANT << "
  1408. echo >&2 " Please make sure your system is up to date"
  1409. echo >&2 " by running: ${sudo} apk update "
  1410. echo >&2
  1411. fi
  1412. local opts="--force-broken-world"
  1413. if [ "${NON_INTERACTIVE}" -eq 1 ]; then
  1414. echo >&2 "Running in non-interactive mode"
  1415. else
  1416. opts="${opts} -i"
  1417. fi
  1418. read -r -a apk_opts <<< "$opts"
  1419. # install the required packages
  1420. run ${sudo} apk add "${apk_opts[@]}" "${@}"
  1421. }
  1422. # -----------------------------------------------------------------------------
  1423. # sabayon
  1424. validate_install_equo() {
  1425. echo >&2 " > Checking if package '${*}' is installed..."
  1426. equo s --installed "${*}" > /dev/null 2>&1 || echo "${*}"
  1427. }
  1428. install_equo() {
  1429. # download the latest package info
  1430. if [ "${DRYRUN}" -eq 1 ]; then
  1431. echo >&2 " >> IMPORTANT << "
  1432. echo >&2 " Please make sure your system is up to date"
  1433. echo >&2 " by running: ${sudo} equo up "
  1434. echo >&2
  1435. fi
  1436. local opts="-av"
  1437. if [ "${NON_INTERACTIVE}" -eq 1 ]; then
  1438. echo >&2 "Running in non-interactive mode"
  1439. opts="-v"
  1440. fi
  1441. read -r -a equo_opts <<< "$opts"
  1442. # install the required packages
  1443. run ${sudo} equo i "${equo_opts[@]}" "${@}"
  1444. }
  1445. # -----------------------------------------------------------------------------
  1446. # arch
  1447. PACMAN_DB_SYNCED=0
  1448. validate_install_pacman() {
  1449. if [ "${PACMAN_DB_SYNCED}" -eq 0 ]; then
  1450. echo >&2 " > Running pacman -Sy to sync the database"
  1451. local x
  1452. x=$(pacman -Sy)
  1453. [ -z "${x}" ] && echo "${*}"
  1454. PACMAN_DB_SYNCED=1
  1455. fi
  1456. echo >&2 " > Checking if package '${*}' is installed..."
  1457. # In pacman, you can utilize alternative flags to exactly match package names,
  1458. # but is highly likely we require pattern matching too in this so we keep -s and match
  1459. # the exceptional cases like so
  1460. local x=""
  1461. case "${package}" in
  1462. "gcc")
  1463. # Temporary workaround: In archlinux, default installation includes runtime libs under package "gcc"
  1464. # These are not sufficient for netdata install, so we need to make sure that the appropriate libraries are there
  1465. # by ensuring devel libs are available
  1466. x=$(pacman -Qs "${*}" | grep "base-devel")
  1467. ;;
  1468. "tar")
  1469. x=$(pacman -Qs "${*}" | grep "local/tar")
  1470. ;;
  1471. "make")
  1472. x=$(pacman -Qs "${*}" | grep "local/make ")
  1473. ;;
  1474. *)
  1475. x=$(pacman -Qs "${*}")
  1476. ;;
  1477. esac
  1478. [ -z "${x}" ] && echo "${*}"
  1479. }
  1480. install_pacman() {
  1481. # download the latest package info
  1482. if [ "${DRYRUN}" -eq 1 ]; then
  1483. echo >&2 " >> IMPORTANT << "
  1484. echo >&2 " Please make sure your system is up to date"
  1485. echo >&2 " by running: ${sudo} pacman -Syu "
  1486. echo >&2
  1487. fi
  1488. # install the required packages
  1489. if [ "${NON_INTERACTIVE}" -eq 1 ]; then
  1490. echo >&2 "Running in non-interactive mode"
  1491. # http://unix.stackexchange.com/questions/52277/pacman-option-to-assume-yes-to-every-question/52278
  1492. # Try the noconfirm option, if that fails, go with the legacy way for non-interactive
  1493. run ${sudo} pacman --noconfirm --needed -S "${@}" || yes | run ${sudo} pacman --needed -S "${@}"
  1494. else
  1495. run ${sudo} pacman --needed -S "${@}"
  1496. fi
  1497. }
  1498. # -----------------------------------------------------------------------------
  1499. # suse / opensuse
  1500. validate_install_zypper() {
  1501. rpm -q "${*}" > /dev/null 2>&1 || echo "${*}"
  1502. }
  1503. install_zypper() {
  1504. # download the latest package info
  1505. if [ "${DRYRUN}" -eq 1 ]; then
  1506. echo >&2 " >> IMPORTANT << "
  1507. echo >&2 " Please make sure your system is up to date"
  1508. echo >&2 " by running: ${sudo} zypper update "
  1509. echo >&2
  1510. fi
  1511. local opts="--ignore-unknown"
  1512. local install_opts="--allow-downgrade"
  1513. if [ "${NON_INTERACTIVE}" -eq 1 ]; then
  1514. echo >&2 "Running in non-interactive mode"
  1515. # http://unix.stackexchange.com/questions/82016/how-to-use-zypper-in-bash-scripts-for-someone-coming-from-apt-get
  1516. opts="${opts} --non-interactive"
  1517. fi
  1518. read -r -a zypper_opts <<< "$opts"
  1519. # install the required packages
  1520. run ${sudo} zypper "${zypper_opts[@]}" install "${install_opts}" "${@}"
  1521. }
  1522. # -----------------------------------------------------------------------------
  1523. # clearlinux
  1524. validate_install_swupd() {
  1525. swupd bundle-list | grep -q "${*}" || echo "${*}"
  1526. }
  1527. install_swupd() {
  1528. # download the latest package info
  1529. if [ "${DRYRUN}" -eq 1 ]; then
  1530. echo >&2 " >> IMPORTANT << "
  1531. echo >&2 " Please make sure your system is up to date"
  1532. echo >&2 " by running: ${sudo} swupd update "
  1533. echo >&2
  1534. fi
  1535. run ${sudo} swupd bundle-add "${@}"
  1536. }
  1537. # -----------------------------------------------------------------------------
  1538. # macOS
  1539. validate_install_pkg() {
  1540. pkg query %n-%v | grep -q "${*}" || echo "${*}"
  1541. }
  1542. validate_install_brew() {
  1543. brew list | grep -q "${*}" || echo "${*}"
  1544. }
  1545. install_pkg() {
  1546. # download the latest package info
  1547. if [ "${DRYRUN}" -eq 1 ]; then
  1548. echo >&2 " >> IMPORTANT << "
  1549. echo >&2 " Please make sure your system is up to date"
  1550. echo >&2 " by running: pkg update "
  1551. echo >&2
  1552. fi
  1553. local opts=
  1554. if [ "${NON_INTERACTIVE}" -eq 1 ]; then
  1555. echo >&2 "Running in non-interactive mode"
  1556. opts="-y"
  1557. fi
  1558. read -r -a pkg_opts <<< "${opts}"
  1559. run ${sudo} pkg install "${pkg_opts[@]}" "${@}"
  1560. }
  1561. install_brew() {
  1562. # download the latest package info
  1563. if [ "${DRYRUN}" -eq 1 ]; then
  1564. echo >&2 " >> IMPORTANT << "
  1565. echo >&2 " Please make sure your system is up to date"
  1566. echo >&2 " by running: brew upgrade "
  1567. echo >&2
  1568. fi
  1569. run brew install "${@}"
  1570. }
  1571. # -----------------------------------------------------------------------------
  1572. install_failed() {
  1573. local ret="${1}"
  1574. cat << EOF
  1575. We are very sorry!
  1576. Installation of required packages failed.
  1577. What to do now:
  1578. 1. Make sure your system is updated.
  1579. Most of the times, updating your system will resolve the issue.
  1580. 2. If the error message is about a specific package, try removing
  1581. that package from the command and run it again.
  1582. Depending on the broken package, you may be able to continue.
  1583. 3. Let us know. We may be able to help.
  1584. Open a github issue with the above log, at:
  1585. https://github.com/netdata/netdata/issues
  1586. EOF
  1587. remote_log "FAILED" "${ret}"
  1588. exit 1
  1589. }
  1590. remote_log() {
  1591. # log success or failure on our system
  1592. # to help us solve installation issues
  1593. curl > /dev/null 2>&1 -Ss --max-time 3 "https://registry.my-netdata.io/log/installer?status=${1}&error=${2}&distribution=${distribution}&version=${version}&installer=${package_installer}&tree=${tree}&detection=${detection}&netdata=${PACKAGES_NETDATA}&python=${PACKAGES_NETDATA_PYTHON}&python3=${PACKAGES_NETDATA_PYTHON3}&sensors=${PACKAGES_NETDATA_SENSORS}&database=${PACKAGES_NETDATA_DATABASE}&ebpf=${PACKAGES_NETDATA_EBPF}&firehol=${PACKAGES_FIREHOL}&fireqos=${PACKAGES_FIREQOS}&iprange=${PACKAGES_IPRANGE}&update_ipsets=${PACKAGES_UPDATE_IPSETS}&demo=${PACKAGES_NETDATA_DEMO_SITE}"
  1594. }
  1595. if [ -z "${1}" ]; then
  1596. usage
  1597. exit 1
  1598. fi
  1599. pv=$(python --version 2>&1)
  1600. if [ "${tree}" = macos ]; then
  1601. pv=3
  1602. elif [[ "${pv}" =~ ^Python\ 2.* ]]; then
  1603. pv=2
  1604. elif [[ "${pv}" =~ ^Python\ 3.* ]]; then
  1605. pv=3
  1606. elif [[ "${tree}" == "centos" ]] && [ "${version}" -lt 8 ]; then
  1607. pv=2
  1608. else
  1609. pv=3
  1610. fi
  1611. # parse command line arguments
  1612. DONT_WAIT=0
  1613. NON_INTERACTIVE=0
  1614. IGNORE_INSTALLED=0
  1615. while [ -n "${1}" ]; do
  1616. case "${1}" in
  1617. distribution)
  1618. distribution="${2}"
  1619. shift
  1620. ;;
  1621. version)
  1622. version="${2}"
  1623. shift
  1624. ;;
  1625. codename)
  1626. codename="${2}"
  1627. shift
  1628. ;;
  1629. installer)
  1630. check_package_manager "${2}" || exit 1
  1631. shift
  1632. ;;
  1633. dont-wait | --dont-wait | -n)
  1634. DONT_WAIT=1
  1635. ;;
  1636. non-interactive | --non-interactive | -y)
  1637. NON_INTERACTIVE=1
  1638. ;;
  1639. ignore-installed | --ignore-installed | -i)
  1640. IGNORE_INSTALLED=1
  1641. ;;
  1642. netdata-all)
  1643. PACKAGES_NETDATA=1
  1644. if [ "${pv}" -eq 2 ]; then
  1645. PACKAGES_NETDATA_PYTHON=1
  1646. else
  1647. PACKAGES_NETDATA_PYTHON3=1
  1648. fi
  1649. PACKAGES_NETDATA_SENSORS=1
  1650. PACKAGES_NETDATA_DATABASE=1
  1651. PACKAGES_NETDATA_EBPF=1
  1652. PACKAGES_NETDATA_STREAMING_COMPRESSION=1
  1653. ;;
  1654. netdata)
  1655. PACKAGES_NETDATA=1
  1656. PACKAGES_NETDATA_PYTHON3=1
  1657. PACKAGES_NETDATA_DATABASE=1
  1658. PACKAGES_NETDATA_EBPF=1
  1659. PACKAGES_NETDATA_STREAMING_COMPRESSION=1
  1660. ;;
  1661. python | netdata-python)
  1662. PACKAGES_NETDATA_PYTHON=1
  1663. ;;
  1664. python3 | netdata-python3)
  1665. PACKAGES_NETDATA_PYTHON3=1
  1666. ;;
  1667. sensors | netdata-sensors)
  1668. PACKAGES_NETDATA=1
  1669. PACKAGES_NETDATA_PYTHON3=1
  1670. PACKAGES_NETDATA_SENSORS=1
  1671. PACKAGES_NETDATA_DATABASE=1
  1672. ;;
  1673. firehol | update-ipsets | firehol-all | fireqos)
  1674. PACKAGES_IPRANGE=1
  1675. PACKAGES_FIREHOL=1
  1676. PACKAGES_FIREQOS=1
  1677. PACKAGES_IPRANGE=1
  1678. PACKAGES_UPDATE_IPSETS=1
  1679. ;;
  1680. demo | all)
  1681. PACKAGES_NETDATA=1
  1682. if [ "${pv}" -eq 2 ]; then
  1683. PACKAGES_NETDATA_PYTHON=1
  1684. else
  1685. PACKAGES_NETDATA_PYTHON3=1
  1686. fi
  1687. PACKAGES_DEBUG=1
  1688. PACKAGES_IPRANGE=1
  1689. PACKAGES_FIREHOL=1
  1690. PACKAGES_FIREQOS=1
  1691. PACKAGES_UPDATE_IPSETS=1
  1692. PACKAGES_NETDATA_DEMO_SITE=1
  1693. PACKAGES_NETDATA_DATABASE=1
  1694. PACKAGES_NETDATA_EBPF=1
  1695. ;;
  1696. help | -h | --help)
  1697. usage
  1698. exit 1
  1699. ;;
  1700. *)
  1701. echo >&2 "ERROR: Cannot understand option '${1}'"
  1702. echo >&2
  1703. usage
  1704. exit 1
  1705. ;;
  1706. esac
  1707. shift
  1708. done
  1709. # Check for missing core commands like grep, warn the user to install it and bail out cleanly
  1710. if ! command -v grep > /dev/null 2>&1; then
  1711. echo >&2
  1712. echo >&2 "ERROR: 'grep' is required for the install to run correctly and was not found on the system."
  1713. echo >&2 "Please install grep and run the installer again."
  1714. echo >&2
  1715. exit 1
  1716. fi
  1717. if [ -z "${package_installer}" ] || [ -z "${tree}" ]; then
  1718. if [ -z "${distribution}" ]; then
  1719. # we dont know the distribution
  1720. autodetect_distribution || user_picks_distribution
  1721. fi
  1722. # When no package installer is detected, try again from distro info if any
  1723. if [ -z "${package_installer}" ]; then
  1724. detect_package_manager_from_distribution "${distribution}"
  1725. fi
  1726. # Validate package manager trees
  1727. validate_package_trees
  1728. fi
  1729. [ "${detection}" = "/etc/os-release" ] && cat << EOF
  1730. /etc/os-release information:
  1731. NAME : ${NAME}
  1732. VERSION : ${VERSION}
  1733. ID : ${ID}
  1734. ID_LIKE : ${ID_LIKE}
  1735. VERSION_ID : ${VERSION_ID}
  1736. EOF
  1737. cat << EOF
  1738. We detected these:
  1739. Distribution : ${distribution}
  1740. Version : ${version}
  1741. Codename : ${codename}
  1742. Package Manager : ${package_installer}
  1743. Packages Tree : ${tree}
  1744. Detection Method: ${detection}
  1745. Default Python v: ${pv} $([ ${pv} -eq 2 ] && [ "${PACKAGES_NETDATA_PYTHON3}" -eq 1 ] && echo "(will install python3 too)")
  1746. EOF
  1747. mapfile -t PACKAGES_TO_INSTALL < <(packages | sort -u)
  1748. if [ ${#PACKAGES_TO_INSTALL[@]} -gt 0 ]; then
  1749. echo >&2
  1750. echo >&2 "The following command will be run:"
  1751. echo >&2
  1752. DRYRUN=1
  1753. "${package_installer}" "${PACKAGES_TO_INSTALL[@]}"
  1754. DRYRUN=0
  1755. echo >&2
  1756. echo >&2
  1757. if [ "${DONT_WAIT}" -eq 0 ] && [ "${NON_INTERACTIVE}" -eq 0 ]; then
  1758. read -r -p "Press ENTER to run it > " || exit 1
  1759. fi
  1760. "${package_installer}" "${PACKAGES_TO_INSTALL[@]}" || install_failed $?
  1761. echo >&2
  1762. echo >&2 "All Done! - Now proceed to the next step."
  1763. echo >&2
  1764. else
  1765. echo >&2
  1766. echo >&2 "All required packages are already installed. Now proceed to the next step."
  1767. echo >&2
  1768. fi
  1769. remote_log "OK"
  1770. exit 0