install-required-packages.sh 55 KB

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