install-required-packages.sh 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119
  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 "${yum}" ]] && package_installer="install_yum"
  353. [[ -n "${dnf}" ]] && package_installer="install_dnf"
  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. fedora* | redhat* | red\ hat* | rhel*)
  360. package_installer=
  361. tree="rhel"
  362. [[ -n "${yum}" ]] && package_installer="install_yum"
  363. [[ -n "${dnf}" ]] && package_installer="install_dnf"
  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. ol*)
  370. package_installer=
  371. tree="ol"
  372. [ -n "${yum}" ] && package_installer="install_yum"
  373. [ -n "${dnf}" ] && package_installer="install_dnf"
  374. if [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${package_installer}" ]; then
  375. echo >&2 "command 'yum' or 'dnf' is required to install packages on a '${distribution} ${version}' system."
  376. exit 1
  377. fi
  378. ;;
  379. suse* | opensuse* | sles*)
  380. package_installer="install_zypper"
  381. tree="suse"
  382. if [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${zypper}" ]; then
  383. echo >&2 "command 'zypper' is required to install packages on a '${distribution} ${version}' system."
  384. exit 1
  385. fi
  386. ;;
  387. clear-linux* | clearlinux*)
  388. package_installer="install_swupd"
  389. tree="clearlinux"
  390. if [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${swupd}" ]; then
  391. echo >&2 "command 'swupd' is required to install packages on a '${distribution} ${version}' system."
  392. exit 1
  393. fi
  394. ;;
  395. freebsd)
  396. package_installer="install_pkg"
  397. tree="freebsd"
  398. if [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${pkg}" ]; then
  399. echo >&2 "command 'pkg' is required to install packages on a '${distribution} ${version}' system."
  400. exit 1
  401. fi
  402. ;;
  403. macos)
  404. package_installer="install_brew"
  405. tree="macos"
  406. if [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${brew}" ]; then
  407. echo >&2 "command 'brew' is required to install packages on a '${distribution} ${version}' system."
  408. exit 1
  409. fi
  410. ;;
  411. *)
  412. # oops! unknown system
  413. user_picks_distribution
  414. ;;
  415. esac
  416. }
  417. # XXX: This is being removed in another PR.
  418. check_package_manager() {
  419. # This is called only when the user is selecting a package manager
  420. # It is used to verify the user selection is right
  421. echo >&2 "Checking package manager: ${1}"
  422. case "${1}" in
  423. apt-get)
  424. [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${apt_get}" ] && echo >&2 "${1} is not available." && return 1
  425. package_installer="install_apt_get"
  426. tree="debian"
  427. detection="user-input"
  428. return 0
  429. ;;
  430. dnf)
  431. [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${dnf}" ] && echo >&2 "${1} is not available." && return 1
  432. package_installer="install_dnf"
  433. if [ "${distribution}" = "centos" ]; then
  434. tree="centos"
  435. elif [ "${distribution}" = "ol" ]; then
  436. tree="ol"
  437. else
  438. tree="rhel"
  439. fi
  440. detection="user-input"
  441. return 0
  442. ;;
  443. apk)
  444. [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${apk}" ] && echo >&2 "${1} is not available." && return 1
  445. package_installer="install_apk"
  446. tree="alpine"
  447. detection="user-input"
  448. return 0
  449. ;;
  450. equo)
  451. [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${equo}" ] && echo >&2 "${1} is not available." && return 1
  452. package_installer="install_equo"
  453. tree="sabayon"
  454. detection="user-input"
  455. return 0
  456. ;;
  457. emerge)
  458. [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${emerge}" ] && echo >&2 "${1} is not available." && return 1
  459. package_installer="install_emerge"
  460. tree="gentoo"
  461. detection="user-input"
  462. return 0
  463. ;;
  464. pacman)
  465. [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${pacman}" ] && echo >&2 "${1} is not available." && return 1
  466. package_installer="install_pacman"
  467. tree="arch"
  468. detection="user-input"
  469. return 0
  470. ;;
  471. zypper)
  472. [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${zypper}" ] && echo >&2 "${1} is not available." && return 1
  473. package_installer="install_zypper"
  474. tree="suse"
  475. detection="user-input"
  476. return 0
  477. ;;
  478. yum)
  479. [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${yum}" ] && echo >&2 "${1} is not available." && return 1
  480. package_installer="install_yum"
  481. if [ "${distribution}" = "centos" ]; then
  482. tree="centos"
  483. elif [ "${distribution}" = "ol" ]; then
  484. tree="ol"
  485. else
  486. tree="rhel"
  487. fi
  488. detection="user-input"
  489. return 0
  490. ;;
  491. swupd)
  492. [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${swupd}" ] && echo >&2 "${1} is not available." && return 1
  493. package_installer="install_swupd"
  494. tree="clear-linux"
  495. detection="user-input"
  496. return 0
  497. ;;
  498. brew)
  499. [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${brew}" ] && echo >&2 "${1} is not available." && return 1
  500. package_installer="install_brew"
  501. tree="macos"
  502. detection="user-input"
  503. return 0
  504. ;;
  505. *)
  506. echo >&2 "Invalid package manager: '${1}'."
  507. return 1
  508. ;;
  509. esac
  510. }
  511. require_cmd() {
  512. # check if any of the commands given as argument
  513. # are present on this system
  514. # If any of them is available, it returns 0
  515. # otherwise 1
  516. [ "${IGNORE_INSTALLED}" -eq 1 ] && return 1
  517. local wanted found
  518. for wanted in "${@}"; do
  519. if command -v "${wanted}" > /dev/null 2>&1; then
  520. found="$(command -v "$wanted" 2> /dev/null)"
  521. fi
  522. [ -n "${found}" ] && [ -x "${found}" ] && return 0
  523. done
  524. return 1
  525. }
  526. declare -A pkg_find=(
  527. ['gentoo']="sys-apps/findutils"
  528. ['fedora']="findutils"
  529. ['clearlinux']="findutils"
  530. ['rhel']="findutils"
  531. ['centos']="findutils"
  532. ['macos']="NOTREQUIRED"
  533. ['freebsd']="NOTREQUIRED"
  534. ['default']="WARNING|"
  535. )
  536. declare -A pkg_distro_sdk=(
  537. ['alpine']="alpine-sdk"
  538. ['centos']="kernel-headers"
  539. ['default']="NOTREQUIRED"
  540. )
  541. declare -A pkg_coreutils=(
  542. ['alpine']="coreutils"
  543. ['default']="NOTREQUIRED"
  544. )
  545. declare -A pkg_autoconf=(
  546. ['gentoo']="sys-devel/autoconf"
  547. ['clearlinux']="c-basic"
  548. ['default']="autoconf"
  549. )
  550. # required to compile netdata with --enable-sse
  551. # https://github.com/firehol/netdata/pull/450
  552. declare -A pkg_autoconf_archive=(
  553. ['gentoo']="sys-devel/autoconf-archive"
  554. ['clearlinux']="c-basic"
  555. ['alpine']="WARNING|"
  556. ['default']="autoconf-archive"
  557. # exceptions
  558. ['centos-6']="WARNING|"
  559. ['rhel-6']="WARNING|"
  560. ['rhel-7']="WARNING|"
  561. )
  562. declare -A pkg_autogen=(
  563. ['gentoo']="sys-devel/autogen"
  564. ['clearlinux']="c-basic"
  565. ['alpine']="WARNING|"
  566. ['default']="autogen"
  567. # exceptions
  568. ['centos-6']="WARNING|"
  569. ['rhel-6']="WARNING|"
  570. ['centos-9']="NOTREQUIRED|"
  571. ['rhel-9']="NOTREQUIRED|"
  572. )
  573. declare -A pkg_automake=(
  574. ['gentoo']="sys-devel/automake"
  575. ['clearlinux']="c-basic"
  576. ['default']="automake"
  577. )
  578. # Required to build libwebsockets and libmosquitto on some systems.
  579. declare -A pkg_cmake=(
  580. ['gentoo']="dev-util/cmake"
  581. ['clearlinux']="c-basic"
  582. ['default']="cmake"
  583. )
  584. # bison and flex are required by Fluent-Bit
  585. declare -A pkg_bison=(
  586. ['default']="bison"
  587. )
  588. declare -A pkg_flex=(
  589. ['default']="flex"
  590. )
  591. # fts-dev is required by Fluent-Bit on Alpine
  592. declare -A pkg_fts_dev=(
  593. ['default']="NOTREQUIRED"
  594. ['alpine']="musl-fts-dev"
  595. ['alpine-3.16.9']="fts-dev"
  596. )
  597. # cmake3 is required by Fluent-Bit on CentOS 7
  598. declare -A pkg_cmake3=(
  599. ['default']="NOTREQUIRED"
  600. ['centos-7']="cmake3"
  601. )
  602. declare -A pkg_json_c_dev=(
  603. ['alpine']="json-c-dev"
  604. ['arch']="json-c"
  605. ['clearlinux']="devpkg-json-c"
  606. ['debian']="libjson-c-dev"
  607. ['gentoo']="dev-libs/json-c"
  608. ['sabayon']="dev-libs/json-c"
  609. ['suse']="libjson-c-devel"
  610. ['freebsd']="json-c"
  611. ['macos']="json-c"
  612. ['default']="json-c-devel"
  613. )
  614. #TODO:: clearlinux ?
  615. declare -A pkg_libyaml_dev=(
  616. ['alpine']="yaml-dev"
  617. ['arch']="libyaml"
  618. ['clearlinux']="yaml-dev"
  619. ['debian']="libyaml-dev"
  620. ['gentoo']="dev-libs/libyaml"
  621. ['sabayon']="dev-libs/libyaml"
  622. ['suse']="libyaml-devel"
  623. ['freebsd']="libyaml"
  624. ['macos']="libyaml"
  625. ['default']="libyaml-devel"
  626. )
  627. declare -A pkg_libatomic=(
  628. ['arch']="NOTREQUIRED"
  629. ['clearlinux']="NOTREQUIRED"
  630. ['debian']="libatomic1"
  631. ['freebsd']="NOTREQUIRED"
  632. ['gentoo']="NOTREQUIRED"
  633. ['macos']="NOTREQUIRED"
  634. ['sabayon']="NOTREQUIRED"
  635. ['suse']="libatomic1"
  636. ['ubuntu']="libatomic1"
  637. ['default']="libatomic"
  638. )
  639. declare -A pkg_libsystemd_dev=(
  640. ['alpine']="NOTREQUIRED"
  641. ['arch']="NOTREQUIRED" # inherently present on systems actually using systemd
  642. ['clearlinux']="system-os-dev"
  643. ['debian']="libsystemd-dev"
  644. ['freebsd']="NOTREQUIRED"
  645. ['gentoo']="NOTREQUIRED" # inherently present on systems actually using systemd
  646. ['macos']="NOTREQUIRED"
  647. ['sabayon']="NOTREQUIRED" # inherently present on systems actually using systemd
  648. ['ubuntu']="libsystemd-dev"
  649. ['default']="systemd-devel"
  650. )
  651. declare -A pkg_bridge_utils=(
  652. ['gentoo']="net-misc/bridge-utils"
  653. ['clearlinux']="network-basic"
  654. ['macos']="WARNING|"
  655. ['default']="bridge-utils"
  656. )
  657. declare -A pkg_curl=(
  658. ['gentoo']="net-misc/curl"
  659. ['sabayon']="net-misc/curl"
  660. ['default']="curl"
  661. )
  662. declare -A pkg_gzip=(
  663. ['gentoo']="app-arch/gzip"
  664. ['macos']="NOTREQUIRED"
  665. ['default']="gzip"
  666. )
  667. declare -A pkg_tar=(
  668. ['gentoo']="app-arch/tar"
  669. ['clearlinux']="os-core-update"
  670. ['macos']="NOTREQUIRED"
  671. ['freebsd']="NOTREQUIRED"
  672. ['default']="tar"
  673. )
  674. declare -A pkg_git=(
  675. ['gentoo']="dev-vcs/git"
  676. ['default']="git"
  677. )
  678. declare -A pkg_gcc=(
  679. ['gentoo']="sys-devel/gcc"
  680. ['clearlinux']="c-basic"
  681. ['macos']="NOTREQUIRED"
  682. ['default']="gcc"
  683. )
  684. # g++, required for building protobuf
  685. # All three cases of this not being required are systems that implicitly
  686. # include g++ when installing gcc.
  687. declare -A pkg_gxx=(
  688. ['alpine']="g++"
  689. ['arch']="NOTREQUIRED"
  690. ['clearlinux']="c-basic"
  691. ['debian']="g++"
  692. ['gentoo']="NOTREQUIRED"
  693. ['macos']="NOTREQUIRED"
  694. ['ubuntu']="g++"
  695. ['freebsd']="NOTREQUIRED"
  696. ['default']="gcc-c++"
  697. )
  698. declare -A pkg_gdb=(
  699. ['gentoo']="sys-devel/gdb"
  700. ['macos']="NOTREQUIRED"
  701. ['default']="gdb"
  702. )
  703. declare -A pkg_iotop=(
  704. ['gentoo']="sys-process/iotop"
  705. ['macos']="WARNING|"
  706. ['default']="iotop"
  707. )
  708. declare -A pkg_iproute2=(
  709. ['alpine']="iproute2"
  710. ['debian']="iproute2"
  711. ['gentoo']="sys-apps/iproute2"
  712. ['sabayon']="sys-apps/iproute2"
  713. ['clearlinux']="iproute2"
  714. ['macos']="WARNING|"
  715. ['default']="iproute"
  716. # exceptions
  717. ['ubuntu-12.04']="iproute"
  718. )
  719. declare -A pkg_ipset=(
  720. ['gentoo']="net-firewall/ipset"
  721. ['clearlinux']="network-basic"
  722. ['macos']="WARNING|"
  723. ['default']="ipset"
  724. )
  725. declare -A pkg_jq=(
  726. ['gentoo']="app-misc/jq"
  727. ['default']="jq"
  728. )
  729. declare -A pkg_iptables=(
  730. ['gentoo']="net-firewall/iptables"
  731. ['macos']="WARNING|"
  732. ['default']="iptables"
  733. )
  734. declare -A pkg_libz_dev=(
  735. ['alpine']="zlib-dev"
  736. ['arch']="zlib"
  737. ['centos']="zlib-devel"
  738. ['debian']="zlib1g-dev"
  739. ['gentoo']="sys-libs/zlib"
  740. ['sabayon']="sys-libs/zlib"
  741. ['rhel']="zlib-devel"
  742. ['ol']="zlib-devel"
  743. ['suse']="zlib-devel"
  744. ['clearlinux']="devpkg-zlib"
  745. ['macos']="NOTREQUIRED"
  746. ['freebsd']="lzlib"
  747. ['default']=""
  748. )
  749. declare -A pkg_libuuid_dev=(
  750. ['alpine']="util-linux-dev"
  751. ['arch']="util-linux"
  752. ['centos']="libuuid-devel"
  753. ['clearlinux']="devpkg-util-linux"
  754. ['debian']="uuid-dev"
  755. ['gentoo']="sys-apps/util-linux"
  756. ['sabayon']="sys-apps/util-linux"
  757. ['rhel']="libuuid-devel"
  758. ['ol']="libuuid-devel"
  759. ['suse']="libuuid-devel"
  760. ['macos']="ossp-uuid"
  761. ['freebsd']="e2fsprogs-libuuid"
  762. ['default']=""
  763. )
  764. declare -A pkg_libmnl_dev=(
  765. ['alpine']="libmnl-dev"
  766. ['arch']="libmnl"
  767. ['centos']="libmnl-devel"
  768. ['debian']="libmnl-dev"
  769. ['gentoo']="net-libs/libmnl"
  770. ['sabayon']="net-libs/libmnl"
  771. ['rhel']="libmnl-devel"
  772. ['ol']="libmnl-devel"
  773. ['suse']="libmnl-devel"
  774. ['clearlinux']="devpkg-libmnl"
  775. ['macos']="NOTREQUIRED"
  776. ['default']=""
  777. )
  778. declare -A pkg_lm_sensors=(
  779. ['alpine']="lm_sensors"
  780. ['arch']="lm_sensors"
  781. ['centos']="lm_sensors"
  782. ['debian']="lm-sensors"
  783. ['gentoo']="sys-apps/lm-sensors"
  784. ['sabayon']="sys-apps/lm_sensors"
  785. ['rhel']="lm_sensors"
  786. ['suse']="sensors"
  787. ['clearlinux']="lm-sensors"
  788. ['macos']="WARNING|"
  789. ['freebsd']="NOTREQUIRED"
  790. ['default']="lm_sensors"
  791. )
  792. declare -A pkg_logwatch=(
  793. ['gentoo']="sys-apps/logwatch"
  794. ['clearlinux']="WARNING|"
  795. ['macos']="WARNING|"
  796. ['default']="logwatch"
  797. )
  798. declare -A pkg_lxc=(
  799. ['gentoo']="app-emulation/lxc"
  800. ['clearlinux']="WARNING|"
  801. ['macos']="WARNING|"
  802. ['default']="lxc"
  803. )
  804. declare -A pkg_mailutils=(
  805. ['gentoo']="net-mail/mailutils"
  806. ['clearlinux']="WARNING|"
  807. ['macos']="WARNING|"
  808. ['default']="mailutils"
  809. )
  810. declare -A pkg_make=(
  811. ['gentoo']="sys-devel/make"
  812. ['macos']="NOTREQUIRED"
  813. ['freebsd']="gmake"
  814. ['default']="make"
  815. )
  816. declare -A pkg_nginx=(
  817. ['gentoo']="www-servers/nginx"
  818. ['default']="nginx"
  819. )
  820. declare -A pkg_postfix=(
  821. ['gentoo']="mail-mta/postfix"
  822. ['macos']="WARNING|"
  823. ['default']="postfix"
  824. )
  825. declare -A pkg_pkg_config=(
  826. ['alpine']="pkgconf"
  827. ['arch']="pkgconfig"
  828. ['centos']="pkgconfig"
  829. ['debian']="pkg-config"
  830. ['gentoo']="virtual/pkgconfig"
  831. ['sabayon']="virtual/pkgconfig"
  832. ['rhel']="pkgconfig"
  833. ['ol']="pkgconfig"
  834. ['suse']="pkg-config"
  835. ['freebsd']="pkgconf"
  836. ['clearlinux']="c-basic"
  837. ['default']="pkg-config"
  838. )
  839. declare -A pkg_python=(
  840. ['gentoo']="dev-lang/python"
  841. ['sabayon']="dev-lang/python:2.7"
  842. ['clearlinux']="python-basic"
  843. ['default']="python"
  844. # Exceptions
  845. ['macos']="WARNING|"
  846. ['centos-8']="python2"
  847. )
  848. declare -A pkg_python_pip=(
  849. ['alpine']="py-pip"
  850. ['gentoo']="dev-python/pip"
  851. ['sabayon']="dev-python/pip"
  852. ['clearlinux']="python-basic"
  853. ['macos']="WARNING|"
  854. ['default']="python-pip"
  855. )
  856. declare -A pkg_python3_pip=(
  857. ['alpine']="py3-pip"
  858. ['arch']="python-pip"
  859. ['gentoo']="dev-python/pip"
  860. ['sabayon']="dev-python/pip"
  861. ['clearlinux']="python3-basic"
  862. ['macos']="NOTREQUIRED"
  863. ['default']="python3-pip"
  864. )
  865. declare -A pkg_python_requests=(
  866. ['alpine']="py-requests"
  867. ['arch']="python2-requests"
  868. ['centos']="python-requests"
  869. ['debian']="python-requests"
  870. ['gentoo']="dev-python/requests"
  871. ['sabayon']="dev-python/requests"
  872. ['rhel']="python-requests"
  873. ['suse']="python-requests"
  874. ['clearlinux']="python-extras"
  875. ['macos']="WARNING|"
  876. ['default']="python-requests"
  877. ['alpine-3.1.4']="WARNING|"
  878. ['alpine-3.2.3']="WARNING|"
  879. )
  880. declare -A pkg_python3_requests=(
  881. ['alpine']="py3-requests"
  882. ['arch']="python-requests"
  883. ['centos']="WARNING|"
  884. ['debian']="WARNING|"
  885. ['gentoo']="dev-python/requests"
  886. ['sabayon']="dev-python/requests"
  887. ['rhel']="WARNING|"
  888. ['suse']="WARNING|"
  889. ['clearlinux']="python-extras"
  890. ['macos']="WARNING|"
  891. ['default']="WARNING|"
  892. ['centos-7']="python36-requests"
  893. ['centos-8']="python3-requests"
  894. ['rhel-7']="python36-requests"
  895. ['rhel-8']="python3-requests"
  896. ['ol-8']="python3-requests"
  897. )
  898. declare -A pkg_lz4=(
  899. ['alpine']="lz4-dev"
  900. ['debian']="liblz4-dev"
  901. ['ubuntu']="liblz4-dev"
  902. ['suse']="liblz4-devel"
  903. ['gentoo']="app-arch/lz4"
  904. ['clearlinux']="devpkg-lz4"
  905. ['arch']="lz4"
  906. ['macos']="lz4"
  907. ['freebsd']="liblz4"
  908. ['default']="lz4-devel"
  909. )
  910. declare -A pkg_zstd=(
  911. ['alpine']="zstd-dev"
  912. ['debian']="libzstd-dev"
  913. ['ubuntu']="libzstd-dev"
  914. ['gentoo']="app-arch/zstd"
  915. ['clearlinux']="zstd-devel"
  916. ['arch']="zstd"
  917. ['macos']="zstd"
  918. ['freebsd']="zstd"
  919. ['default']="libzstd-devel"
  920. )
  921. declare -A pkg_libuv=(
  922. ['alpine']="libuv-dev"
  923. ['debian']="libuv1-dev"
  924. ['ubuntu']="libuv1-dev"
  925. ['gentoo']="dev-libs/libuv"
  926. ['arch']="libuv"
  927. ['clearlinux']="devpkg-libuv"
  928. ['macos']="libuv"
  929. ['freebsd']="libuv"
  930. ['default']="libuv-devel"
  931. )
  932. declare -A pkg_openssl=(
  933. ['alpine']="openssl-dev"
  934. ['debian']="libssl-dev"
  935. ['ubuntu']="libssl-dev"
  936. ['suse']="libopenssl-devel"
  937. ['clearlinux']="devpkg-openssl"
  938. ['gentoo']="dev-libs/openssl"
  939. ['arch']="openssl"
  940. ['freebsd']="openssl"
  941. ['macos']="openssl"
  942. ['default']="openssl-devel"
  943. )
  944. declare -A pkg_python3=(
  945. ['gentoo']="dev-lang/python"
  946. ['sabayon']="dev-lang/python:3.4"
  947. ['clearlinux']="python3-basic"
  948. ['macos']="python"
  949. ['default']="python3"
  950. # exceptions
  951. ['centos-6']="WARNING|"
  952. )
  953. declare -A pkg_screen=(
  954. ['gentoo']="app-misc/screen"
  955. ['sabayon']="app-misc/screen"
  956. ['clearlinux']="sysadmin-basic"
  957. ['default']="screen"
  958. )
  959. declare -A pkg_sudo=(
  960. ['gentoo']="app-admin/sudo"
  961. ['macos']="NOTREQUIRED"
  962. ['default']="sudo"
  963. )
  964. declare -A pkg_sysstat=(
  965. ['gentoo']="app-admin/sysstat"
  966. ['macos']="WARNING|"
  967. ['default']="sysstat"
  968. )
  969. declare -A pkg_tcpdump=(
  970. ['gentoo']="net-analyzer/tcpdump"
  971. ['clearlinux']="network-basic"
  972. ['default']="tcpdump"
  973. )
  974. declare -A pkg_traceroute=(
  975. ['alpine']=" "
  976. ['gentoo']="net-analyzer/traceroute"
  977. ['clearlinux']="network-basic"
  978. ['macos']="NOTREQUIRED"
  979. ['default']="traceroute"
  980. )
  981. declare -A pkg_valgrind=(
  982. ['gentoo']="dev-util/valgrind"
  983. ['default']="valgrind"
  984. )
  985. declare -A pkg_ulogd=(
  986. ['centos']="WARNING|"
  987. ['rhel']="WARNING|"
  988. ['ol']="WARNING|"
  989. ['clearlinux']="WARNING|"
  990. ['gentoo']="app-admin/ulogd"
  991. ['arch']="ulogd"
  992. ['macos']="WARNING|"
  993. ['default']="ulogd2"
  994. )
  995. declare -A pkg_unzip=(
  996. ['gentoo']="app-arch/unzip"
  997. ['macos']="NOTREQUIRED"
  998. ['default']="unzip"
  999. )
  1000. declare -A pkg_zip=(
  1001. ['gentoo']="app-arch/zip"
  1002. ['macos']="NOTREQUIRED"
  1003. ['default']="zip"
  1004. )
  1005. declare -A pkg_libelf=(
  1006. ['alpine']="elfutils-dev"
  1007. ['arch']="libelf"
  1008. ['gentoo']="virtual/libelf"
  1009. ['sabayon']="virtual/libelf"
  1010. ['debian']="libelf-dev"
  1011. ['ubuntu']="libelf-dev"
  1012. ['fedora']="elfutils-libelf-devel"
  1013. ['centos']="elfutils-libelf-devel"
  1014. ['rhel']="elfutils-libelf-devel"
  1015. ['ol']="elfutils-libelf-devel"
  1016. ['clearlinux']="devpkg-elfutils"
  1017. ['suse']="libelf-devel"
  1018. ['macos']="NOTREQUIRED"
  1019. ['freebsd']="NOTREQUIRED"
  1020. ['default']="libelf-devel"
  1021. # exceptions
  1022. ['alpine-3.5']="libelf-dev"
  1023. ['alpine-3.4']="libelf-dev"
  1024. ['alpine-3.3']="libelf-dev"
  1025. )
  1026. validate_package_trees() {
  1027. if type -t validate_tree_${tree} > /dev/null; then
  1028. validate_tree_${tree}
  1029. fi
  1030. }
  1031. validate_installed_package() {
  1032. validate_${package_installer} "${p}"
  1033. }
  1034. suitable_package() {
  1035. local package="${1//-/_}" p="" v="${version//.*/}"
  1036. echo >&2 "Searching for ${package} ..."
  1037. eval "p=\${pkg_${package}['${distribution,,}-${version,,}']}"
  1038. [ -z "${p}" ] && eval "p=\${pkg_${package}['${distribution,,}-${v,,}']}"
  1039. [ -z "${p}" ] && eval "p=\${pkg_${package}['${distribution,,}']}"
  1040. [ -z "${p}" ] && eval "p=\${pkg_${package}['${tree}-${version}']}"
  1041. [ -z "${p}" ] && eval "p=\${pkg_${package}['${tree}-${v}']}"
  1042. [ -z "${p}" ] && eval "p=\${pkg_${package}['${tree}']}"
  1043. [ -z "${p}" ] && eval "p=\${pkg_${package}['default']}"
  1044. if [[ "${p/|*/}" =~ ^(ERROR|WARNING|INFO)$ ]]; then
  1045. echo >&2 "${p/|*/}"
  1046. echo >&2 "package ${1} is not available in this system."
  1047. if [ -z "${p/*|/}" ]; then
  1048. echo >&2 "You may try to install without it."
  1049. else
  1050. echo >&2 "${p/*|/}"
  1051. fi
  1052. echo >&2
  1053. return 1
  1054. elif [ "${p}" = "NOTREQUIRED" ]; then
  1055. return 0
  1056. elif [ -z "${p}" ]; then
  1057. echo >&2 "WARNING"
  1058. echo >&2 "package ${1} is not available in this system."
  1059. echo >&2
  1060. return 1
  1061. else
  1062. if [ "${IGNORE_INSTALLED}" -eq 0 ]; then
  1063. validate_installed_package "${p}"
  1064. else
  1065. echo "${p}"
  1066. fi
  1067. return 0
  1068. fi
  1069. }
  1070. packages() {
  1071. # detect the packages we need to install on this system
  1072. # -------------------------------------------------------------------------
  1073. # basic build environment
  1074. suitable_package distro-sdk
  1075. suitable_package coreutils
  1076. suitable_package libatomic
  1077. require_cmd git || suitable_package git
  1078. require_cmd find || suitable_package find
  1079. require_cmd gcc || require_cmd clang ||
  1080. require_cmd gcc-multilib || suitable_package gcc
  1081. require_cmd g++ || require_cmd clang++ || suitable_package gxx
  1082. require_cmd make || suitable_package make
  1083. require_cmd autoconf || suitable_package autoconf
  1084. suitable_package autoconf-archive
  1085. require_cmd autogen || suitable_package autogen
  1086. require_cmd automake || suitable_package automake
  1087. require_cmd pkg-config || suitable_package pkg-config
  1088. require_cmd cmake || suitable_package cmake
  1089. require_cmd cmake3 || suitable_package cmake3
  1090. # -------------------------------------------------------------------------
  1091. # debugging tools for development
  1092. if [ "${PACKAGES_DEBUG}" -ne 0 ]; then
  1093. require_cmd traceroute || suitable_package traceroute
  1094. require_cmd tcpdump || suitable_package tcpdump
  1095. require_cmd screen || suitable_package screen
  1096. if [ "${PACKAGES_NETDATA}" -ne 0 ]; then
  1097. require_cmd gdb || suitable_package gdb
  1098. require_cmd valgrind || suitable_package valgrind
  1099. fi
  1100. fi
  1101. # -------------------------------------------------------------------------
  1102. # common command line tools
  1103. if [ "${PACKAGES_NETDATA}" -ne 0 ]; then
  1104. require_cmd tar || suitable_package tar
  1105. require_cmd curl || suitable_package curl
  1106. require_cmd gzip || suitable_package gzip
  1107. require_cmd bison || suitable_package bison
  1108. require_cmd flex || suitable_package flex
  1109. fi
  1110. # -------------------------------------------------------------------------
  1111. # firehol/fireqos/update-ipsets command line tools
  1112. if [ "${PACKAGES_FIREQOS}" -ne 0 ]; then
  1113. require_cmd ip || suitable_package iproute2
  1114. fi
  1115. if [ "${PACKAGES_FIREHOL}" -ne 0 ]; then
  1116. require_cmd iptables || suitable_package iptables
  1117. require_cmd ipset || suitable_package ipset
  1118. require_cmd ulogd ulogd2 || suitable_package ulogd
  1119. require_cmd traceroute || suitable_package traceroute
  1120. require_cmd bridge || suitable_package bridge-utils
  1121. fi
  1122. if [ "${PACKAGES_UPDATE_IPSETS}" -ne 0 ]; then
  1123. require_cmd ipset || suitable_package ipset
  1124. require_cmd zip || suitable_package zip
  1125. require_cmd funzip || suitable_package unzip
  1126. fi
  1127. # -------------------------------------------------------------------------
  1128. # netdata libraries
  1129. if [ "${PACKAGES_NETDATA}" -ne 0 ]; then
  1130. suitable_package libz-dev
  1131. suitable_package libuuid-dev
  1132. suitable_package libmnl-dev
  1133. suitable_package json-c-dev
  1134. suitable_package fts-dev
  1135. suitable_package libyaml-dev
  1136. suitable_package libsystemd-dev
  1137. fi
  1138. # -------------------------------------------------------------------------
  1139. # sensors
  1140. if [ "${PACKAGES_NETDATA_SENSORS}" -ne 0 ]; then
  1141. require_cmd sensors || suitable_package lm_sensors
  1142. fi
  1143. # -------------------------------------------------------------------------
  1144. # netdata database
  1145. if [ "${PACKAGES_NETDATA_DATABASE}" -ne 0 ]; then
  1146. suitable_package libuv
  1147. suitable_package lz4
  1148. suitable_package openssl
  1149. fi
  1150. if [ "${PACKAGES_NETDATA_STREAMING_COMPRESSION}" -ne 0 ]; then
  1151. suitable_package zstd
  1152. fi
  1153. # -------------------------------------------------------------------------
  1154. # ebpf plugin
  1155. if [ "${PACKAGES_NETDATA_EBPF}" -ne 0 ]; then
  1156. suitable_package libelf
  1157. fi
  1158. # -------------------------------------------------------------------------
  1159. # python2
  1160. if [ "${PACKAGES_NETDATA_PYTHON}" -ne 0 ]; then
  1161. require_cmd python || suitable_package python
  1162. # suitable_package python-requests
  1163. # suitable_package python-pip
  1164. fi
  1165. # -------------------------------------------------------------------------
  1166. # python3
  1167. if [ "${PACKAGES_NETDATA_PYTHON3}" -ne 0 ]; then
  1168. require_cmd python3 || suitable_package python3
  1169. # suitable_package python3-requests
  1170. # suitable_package python3-pip
  1171. fi
  1172. # -------------------------------------------------------------------------
  1173. # applications needed for the netdata demo sites
  1174. if [ "${PACKAGES_NETDATA_DEMO_SITE}" -ne 0 ]; then
  1175. require_cmd sudo || suitable_package sudo
  1176. require_cmd jq || suitable_package jq
  1177. require_cmd nginx || suitable_package nginx
  1178. require_cmd postconf || suitable_package postfix
  1179. require_cmd lxc-create || suitable_package lxc
  1180. require_cmd logwatch || suitable_package logwatch
  1181. require_cmd mail || suitable_package mailutils
  1182. require_cmd iostat || suitable_package sysstat
  1183. require_cmd iotop || suitable_package iotop
  1184. fi
  1185. }
  1186. DRYRUN=0
  1187. run() {
  1188. printf >&2 "%q " "${@}"
  1189. printf >&2 "\n"
  1190. if [ ! "${DRYRUN}" -eq 1 ]; then
  1191. "${@}"
  1192. return $?
  1193. fi
  1194. return 0
  1195. }
  1196. sudo=
  1197. if [ ${UID} -ne 0 ]; then
  1198. sudo="sudo"
  1199. fi
  1200. # -----------------------------------------------------------------------------
  1201. # debian / ubuntu
  1202. validate_install_apt_get() {
  1203. echo >&2 " > Checking if package '${*}' is installed..."
  1204. [ "$(dpkg-query -W --showformat='${Status}\n' "${*}")" = "install ok installed" ] || echo "${*}"
  1205. }
  1206. install_apt_get() {
  1207. local opts=""
  1208. if [ "${NON_INTERACTIVE}" -eq 1 ]; then
  1209. echo >&2 "Running in non-interactive mode"
  1210. # http://serverfault.com/questions/227190/how-do-i-ask-apt-get-to-skip-any-interactive-post-install-configuration-steps
  1211. export DEBIAN_FRONTEND="noninteractive"
  1212. opts="${opts} -yq"
  1213. fi
  1214. read -r -a apt_opts <<< "$opts"
  1215. # update apt repository caches
  1216. echo >&2 "NOTE: Running apt-get update and updating your APT caches ..."
  1217. if [ "${version}" = 8 ]; then
  1218. echo >&2 "WARNING: You seem to be on Debian 8 (jessie) which is old enough we have to disable Check-Valid-Until checks"
  1219. if ! cat /etc/apt/sources.list /etc/apt/sources.list.d/* 2> /dev/null | grep -q jessie-backports; then
  1220. echo >&2 "We also have to enable the jessie-backports repository"
  1221. if prompt "Is this okay?"; then
  1222. ${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'
  1223. fi
  1224. fi
  1225. run ${sudo} apt-get "${apt_opts[@]}" -o Acquire::Check-Valid-Until=false update
  1226. else
  1227. run ${sudo} apt-get "${apt_opts[@]}" update
  1228. fi
  1229. # install the required packages
  1230. run ${sudo} apt-get "${apt_opts[@]}" install "${@}"
  1231. }
  1232. # -----------------------------------------------------------------------------
  1233. # centos / rhel
  1234. prompt() {
  1235. if [ "${NON_INTERACTIVE}" -eq 1 ]; then
  1236. echo >&2 "Running in non-interactive mode, assuming yes (y)"
  1237. echo >&2 " > Would have prompted for ${1} ..."
  1238. return 0
  1239. fi
  1240. while true; do
  1241. read -r -p "${1} [y/n] " yn
  1242. case $yn in
  1243. [Yy]*) return 0 ;;
  1244. [Nn]*) return 1 ;;
  1245. *) echo >&2 "Please answer with yes (y) or no (n)." ;;
  1246. esac
  1247. done
  1248. }
  1249. validate_tree_freebsd() {
  1250. local opts=
  1251. if [ "${NON_INTERACTIVE}" -eq 1 ]; then
  1252. echo >&2 "Running in non-interactive mode"
  1253. opts="-y"
  1254. fi
  1255. echo >&2 " > FreeBSD Version: ${version} ..."
  1256. make="make"
  1257. echo >&2 " > Checking for gmake ..."
  1258. if ! pkg query %n-%v | grep -q gmake; then
  1259. if prompt "gmake is required to build on FreeBSD and is not installed. Shall I install it?"; then
  1260. # shellcheck disable=2086
  1261. run ${sudo} pkg install ${opts} gmake
  1262. fi
  1263. fi
  1264. }
  1265. validate_tree_ol() {
  1266. local opts=
  1267. if [ "${NON_INTERACTIVE}" -eq 1 ]; then
  1268. echo >&2 "Running in non-interactive mode"
  1269. opts="-y"
  1270. fi
  1271. if [[ "${version}" =~ ^8(\..*)?$ ]]; then
  1272. echo " > Checking for CodeReady Builder ..."
  1273. if ! run ${sudo} dnf repolist | grep -q codeready; then
  1274. if prompt "CodeReady Builder not found, shall I install it?"; then
  1275. cat > /etc/yum.repos.d/ol8_codeready.repo <<-EOF
  1276. [ol8_codeready_builder]
  1277. name=Oracle Linux \$releasever CodeReady Builder (\$basearch)
  1278. baseurl=http://yum.oracle.com/repo/OracleLinux/OL8/codeready/builder/\$basearch
  1279. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
  1280. gpgcheck=1
  1281. enabled=1
  1282. EOF
  1283. fi
  1284. fi
  1285. elif [[ "${version}" =~ ^9(\..*)?$ ]]; then
  1286. echo " > Checking for CodeReady Builder ..."
  1287. if ! run ${sudo} dnf repolist enabled | grep -q codeready; then
  1288. if prompt "CodeReady Builder not enabled, shall I enable it?"; then
  1289. run ${sudo} dnf config-manager --set-enabled ol9_codeready_builder
  1290. fi
  1291. fi
  1292. fi
  1293. }
  1294. validate_tree_centos() {
  1295. local opts=
  1296. if [ "${NON_INTERACTIVE}" -eq 1 ]; then
  1297. echo >&2 "Running in non-interactive mode"
  1298. opts="-y"
  1299. fi
  1300. echo >&2 " > CentOS Version: ${version} ..."
  1301. if [[ "${version}" =~ ^9(\..*)?$ ]]; then
  1302. echo >&2 " > Checking for config-manager ..."
  1303. if ! run ${sudo} dnf config-manager --help; then
  1304. if prompt "config-manager not found, shall I install it?"; then
  1305. # shellcheck disable=2086
  1306. run ${sudo} dnf ${opts} install 'dnf-command(config-manager)'
  1307. fi
  1308. fi
  1309. echo >&2 " > Checking for CRB ..."
  1310. # shellcheck disable=2086
  1311. if ! run dnf ${sudo} repolist | grep CRB; then
  1312. if prompt "CRB not found, shall I install it?"; then
  1313. # shellcheck disable=2086
  1314. run ${sudo} dnf ${opts} config-manager --set-enabled crb
  1315. fi
  1316. fi
  1317. elif [[ "${version}" =~ ^8(\..*)?$ ]]; then
  1318. echo >&2 " > Checking for config-manager ..."
  1319. if ! run ${sudo} yum config-manager --help; then
  1320. if prompt "config-manager not found, shall I install it?"; then
  1321. # shellcheck disable=2086
  1322. run ${sudo} yum ${opts} install 'dnf-command(config-manager)'
  1323. fi
  1324. fi
  1325. echo >&2 " > Checking for PowerTools ..."
  1326. # shellcheck disable=2086
  1327. if ! run yum ${sudo} repolist | grep PowerTools; then
  1328. if prompt "PowerTools not found, shall I install it?"; then
  1329. # shellcheck disable=2086
  1330. run ${sudo} yum ${opts} config-manager --set-enabled powertools
  1331. fi
  1332. fi
  1333. echo >&2 " > Updating libarchive ..."
  1334. # shellcheck disable=2086
  1335. run ${sudo} yum ${opts} install libarchive
  1336. elif [[ "${version}" =~ ^7(\..*)?$ ]]; then
  1337. echo >&2 " > Checking for EPEL ..."
  1338. if ! rpm -qa | grep epel-release > /dev/null; then
  1339. if prompt "EPEL not found, shall I install it?"; then
  1340. # shellcheck disable=2086
  1341. run ${sudo} yum ${opts} install epel-release
  1342. fi
  1343. fi
  1344. elif [[ "${version}" =~ ^6\..*$ ]]; then
  1345. echo >&2 " > Detected CentOS 6.x ..."
  1346. echo >&2 " > Checking for Okay ..."
  1347. if ! rpm -qa | grep okay > /dev/null; then
  1348. if prompt "okay not found, shall I install it?"; then
  1349. # shellcheck disable=2086
  1350. run ${sudo} yum ${opts} install http://repo.okay.com.mx/centos/6/x86_64/release/okay-release-1-3.el6.noarch.rpm
  1351. fi
  1352. fi
  1353. fi
  1354. }
  1355. validate_install_yum() {
  1356. echo >&2 " > Checking if package '${*}' is installed..."
  1357. yum list installed "${*}" > /dev/null 2>&1 || echo "${*}"
  1358. }
  1359. install_yum() {
  1360. # download the latest package info
  1361. if [ "${DRYRUN}" -eq 1 ]; then
  1362. echo >&2 " >> IMPORTANT << "
  1363. echo >&2 " Please make sure your system is up to date"
  1364. echo >&2 " by running: ${sudo} yum update "
  1365. echo >&2
  1366. fi
  1367. local opts=
  1368. if [ "${NON_INTERACTIVE}" -eq 1 ]; then
  1369. echo >&2 "Running in non-interactive mode"
  1370. # http://unix.stackexchange.com/questions/87822/does-yum-have-an-equivalent-to-apt-aptitudes-debian-frontend-noninteractive
  1371. opts="-y"
  1372. fi
  1373. read -r -a yum_opts <<< "${opts}"
  1374. # install the required packages
  1375. run ${sudo} yum "${yum_opts[@]}" install "${@}"
  1376. }
  1377. # -----------------------------------------------------------------------------
  1378. # fedora
  1379. validate_install_dnf() {
  1380. echo >&2 " > Checking if package '${*}' is installed..."
  1381. dnf list installed "${*}" > /dev/null 2>&1 || echo "${*}"
  1382. }
  1383. install_dnf() {
  1384. # download the latest package info
  1385. if [ "${DRYRUN}" -eq 1 ]; then
  1386. echo >&2 " >> IMPORTANT << "
  1387. echo >&2 " Please make sure your system is up to date"
  1388. echo >&2 " by running: ${sudo} dnf update "
  1389. echo >&2
  1390. fi
  1391. local opts=
  1392. if [ "${NON_INTERACTIVE}" -eq 1 ]; then
  1393. echo >&2 "Running in non-interactive mode"
  1394. # man dnf
  1395. opts="-y"
  1396. fi
  1397. # install the required packages
  1398. # --setopt=strict=0 allows dnf to proceed
  1399. # installing whatever is available
  1400. # even if a package is not found
  1401. opts="$opts --setopt=strict=0"
  1402. read -r -a dnf_opts <<< "$opts"
  1403. run ${sudo} dnf "${dnf_opts[@]}" install "${@}"
  1404. }
  1405. # -----------------------------------------------------------------------------
  1406. # gentoo
  1407. validate_install_emerge() {
  1408. echo "${*}"
  1409. }
  1410. install_emerge() {
  1411. # download the latest package info
  1412. # we don't do this for emerge - it is very slow
  1413. # and most users are expected to do this daily
  1414. # emerge --sync
  1415. if [ "${DRYRUN}" -eq 1 ]; then
  1416. echo >&2 " >> IMPORTANT << "
  1417. echo >&2 " Please make sure your system is up to date"
  1418. echo >&2 " by running: ${sudo} emerge --sync or ${sudo} eix-sync "
  1419. echo >&2
  1420. fi
  1421. local opts="--ask"
  1422. if [ "${NON_INTERACTIVE}" -eq 1 ]; then
  1423. echo >&2 "Running in non-interactive mode"
  1424. opts=""
  1425. fi
  1426. read -r -a emerge_opts <<< "$opts"
  1427. # install the required packages
  1428. run ${sudo} emerge "${emerge_opts[@]}" -v --noreplace "${@}"
  1429. }
  1430. # -----------------------------------------------------------------------------
  1431. # alpine
  1432. validate_install_apk() {
  1433. echo "${*}"
  1434. }
  1435. install_apk() {
  1436. # download the latest package info
  1437. if [ "${DRYRUN}" -eq 1 ]; then
  1438. echo >&2 " >> IMPORTANT << "
  1439. echo >&2 " Please make sure your system is up to date"
  1440. echo >&2 " by running: ${sudo} apk update "
  1441. echo >&2
  1442. fi
  1443. local opts="--force-broken-world"
  1444. if [ "${NON_INTERACTIVE}" -eq 1 ]; then
  1445. echo >&2 "Running in non-interactive mode"
  1446. else
  1447. opts="${opts} -i"
  1448. fi
  1449. read -r -a apk_opts <<< "$opts"
  1450. # install the required packages
  1451. run ${sudo} apk add "${apk_opts[@]}" "${@}"
  1452. }
  1453. # -----------------------------------------------------------------------------
  1454. # sabayon
  1455. validate_install_equo() {
  1456. echo >&2 " > Checking if package '${*}' is installed..."
  1457. equo s --installed "${*}" > /dev/null 2>&1 || echo "${*}"
  1458. }
  1459. install_equo() {
  1460. # download the latest package info
  1461. if [ "${DRYRUN}" -eq 1 ]; then
  1462. echo >&2 " >> IMPORTANT << "
  1463. echo >&2 " Please make sure your system is up to date"
  1464. echo >&2 " by running: ${sudo} equo up "
  1465. echo >&2
  1466. fi
  1467. local opts="-av"
  1468. if [ "${NON_INTERACTIVE}" -eq 1 ]; then
  1469. echo >&2 "Running in non-interactive mode"
  1470. opts="-v"
  1471. fi
  1472. read -r -a equo_opts <<< "$opts"
  1473. # install the required packages
  1474. run ${sudo} equo i "${equo_opts[@]}" "${@}"
  1475. }
  1476. # -----------------------------------------------------------------------------
  1477. # arch
  1478. PACMAN_DB_SYNCED=0
  1479. validate_install_pacman() {
  1480. if [ "${PACMAN_DB_SYNCED}" -eq 0 ]; then
  1481. echo >&2 " > Running pacman -Sy to sync the database"
  1482. local x
  1483. x=$(pacman -Sy)
  1484. [ -z "${x}" ] && echo "${*}"
  1485. PACMAN_DB_SYNCED=1
  1486. fi
  1487. echo >&2 " > Checking if package '${*}' is installed..."
  1488. # In pacman, you can utilize alternative flags to exactly match package names,
  1489. # but is highly likely we require pattern matching too in this so we keep -s and match
  1490. # the exceptional cases like so
  1491. local x=""
  1492. case "${package}" in
  1493. "gcc")
  1494. # Temporary workaround: In archlinux, default installation includes runtime libs under package "gcc"
  1495. # These are not sufficient for netdata install, so we need to make sure that the appropriate libraries are there
  1496. # by ensuring devel libs are available
  1497. x=$(pacman -Qs "${*}" | grep "base-devel")
  1498. ;;
  1499. "tar")
  1500. x=$(pacman -Qs "${*}" | grep "local/tar")
  1501. ;;
  1502. "make")
  1503. x=$(pacman -Qs "${*}" | grep "local/make ")
  1504. ;;
  1505. *)
  1506. x=$(pacman -Qs "${*}")
  1507. ;;
  1508. esac
  1509. [ -z "${x}" ] && echo "${*}"
  1510. }
  1511. install_pacman() {
  1512. # download the latest package info
  1513. if [ "${DRYRUN}" -eq 1 ]; then
  1514. echo >&2 " >> IMPORTANT << "
  1515. echo >&2 " Please make sure your system is up to date"
  1516. echo >&2 " by running: ${sudo} pacman -Syu "
  1517. echo >&2
  1518. fi
  1519. # install the required packages
  1520. if [ "${NON_INTERACTIVE}" -eq 1 ]; then
  1521. echo >&2 "Running in non-interactive mode"
  1522. # http://unix.stackexchange.com/questions/52277/pacman-option-to-assume-yes-to-every-question/52278
  1523. # Try the noconfirm option, if that fails, go with the legacy way for non-interactive
  1524. run ${sudo} pacman --noconfirm --needed -S "${@}" || yes | run ${sudo} pacman --needed -S "${@}"
  1525. else
  1526. run ${sudo} pacman --needed -S "${@}"
  1527. fi
  1528. }
  1529. # -----------------------------------------------------------------------------
  1530. # suse / opensuse
  1531. validate_install_zypper() {
  1532. rpm -q "${*}" > /dev/null 2>&1 || echo "${*}"
  1533. }
  1534. install_zypper() {
  1535. # download the latest package info
  1536. if [ "${DRYRUN}" -eq 1 ]; then
  1537. echo >&2 " >> IMPORTANT << "
  1538. echo >&2 " Please make sure your system is up to date"
  1539. echo >&2 " by running: ${sudo} zypper update "
  1540. echo >&2
  1541. fi
  1542. local opts="--ignore-unknown"
  1543. local install_opts="--allow-downgrade"
  1544. if [ "${NON_INTERACTIVE}" -eq 1 ]; then
  1545. echo >&2 "Running in non-interactive mode"
  1546. # http://unix.stackexchange.com/questions/82016/how-to-use-zypper-in-bash-scripts-for-someone-coming-from-apt-get
  1547. opts="${opts} --non-interactive"
  1548. fi
  1549. read -r -a zypper_opts <<< "$opts"
  1550. # install the required packages
  1551. run ${sudo} zypper "${zypper_opts[@]}" install "${install_opts}" "${@}"
  1552. }
  1553. # -----------------------------------------------------------------------------
  1554. # clearlinux
  1555. validate_install_swupd() {
  1556. swupd bundle-list | grep -q "${*}" || echo "${*}"
  1557. }
  1558. install_swupd() {
  1559. # download the latest package info
  1560. if [ "${DRYRUN}" -eq 1 ]; then
  1561. echo >&2 " >> IMPORTANT << "
  1562. echo >&2 " Please make sure your system is up to date"
  1563. echo >&2 " by running: ${sudo} swupd update "
  1564. echo >&2
  1565. fi
  1566. run ${sudo} swupd bundle-add "${@}"
  1567. }
  1568. # -----------------------------------------------------------------------------
  1569. # macOS
  1570. validate_install_pkg() {
  1571. pkg query %n-%v | grep -q "${*}" || echo "${*}"
  1572. }
  1573. validate_install_brew() {
  1574. brew list | grep -q "${*}" || echo "${*}"
  1575. }
  1576. install_pkg() {
  1577. # download the latest package info
  1578. if [ "${DRYRUN}" -eq 1 ]; then
  1579. echo >&2 " >> IMPORTANT << "
  1580. echo >&2 " Please make sure your system is up to date"
  1581. echo >&2 " by running: pkg update "
  1582. echo >&2
  1583. fi
  1584. local opts=
  1585. if [ "${NON_INTERACTIVE}" -eq 1 ]; then
  1586. echo >&2 "Running in non-interactive mode"
  1587. opts="-y"
  1588. fi
  1589. read -r -a pkg_opts <<< "${opts}"
  1590. run ${sudo} pkg install "${pkg_opts[@]}" "${@}"
  1591. }
  1592. install_brew() {
  1593. # download the latest package info
  1594. if [ "${DRYRUN}" -eq 1 ]; then
  1595. echo >&2 " >> IMPORTANT << "
  1596. echo >&2 " Please make sure your system is up to date"
  1597. echo >&2 " by running: brew upgrade "
  1598. echo >&2
  1599. fi
  1600. run brew install "${@}"
  1601. }
  1602. # -----------------------------------------------------------------------------
  1603. install_failed() {
  1604. local ret="${1}"
  1605. cat << EOF
  1606. We are very sorry!
  1607. Installation of required packages failed.
  1608. What to do now:
  1609. 1. Make sure your system is updated.
  1610. Most of the times, updating your system will resolve the issue.
  1611. 2. If the error message is about a specific package, try removing
  1612. that package from the command and run it again.
  1613. Depending on the broken package, you may be able to continue.
  1614. 3. Let us know. We may be able to help.
  1615. Open a github issue with the above log, at:
  1616. https://github.com/netdata/netdata/issues
  1617. EOF
  1618. remote_log "FAILED" "${ret}"
  1619. exit 1
  1620. }
  1621. remote_log() {
  1622. # log success or failure on our system
  1623. # to help us solve installation issues
  1624. 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}"
  1625. }
  1626. if [ -z "${1}" ]; then
  1627. usage
  1628. exit 1
  1629. fi
  1630. pv=$(python --version 2>&1)
  1631. if [ "${tree}" = macos ]; then
  1632. pv=3
  1633. elif [[ "${pv}" =~ ^Python\ 2.* ]]; then
  1634. pv=2
  1635. elif [[ "${pv}" =~ ^Python\ 3.* ]]; then
  1636. pv=3
  1637. elif [[ "${tree}" == "centos" ]] && [ "${version}" -lt 8 ]; then
  1638. pv=2
  1639. else
  1640. pv=3
  1641. fi
  1642. # parse command line arguments
  1643. DONT_WAIT=0
  1644. NON_INTERACTIVE=0
  1645. IGNORE_INSTALLED=0
  1646. while [ -n "${1}" ]; do
  1647. case "${1}" in
  1648. distribution)
  1649. distribution="${2}"
  1650. shift
  1651. ;;
  1652. version)
  1653. version="${2}"
  1654. shift
  1655. ;;
  1656. codename)
  1657. codename="${2}"
  1658. shift
  1659. ;;
  1660. installer)
  1661. check_package_manager "${2}" || exit 1
  1662. shift
  1663. ;;
  1664. dont-wait | --dont-wait | -n)
  1665. DONT_WAIT=1
  1666. ;;
  1667. non-interactive | --non-interactive | -y)
  1668. NON_INTERACTIVE=1
  1669. ;;
  1670. ignore-installed | --ignore-installed | -i)
  1671. IGNORE_INSTALLED=1
  1672. ;;
  1673. netdata-all)
  1674. PACKAGES_NETDATA=1
  1675. if [ "${pv}" -eq 2 ]; then
  1676. PACKAGES_NETDATA_PYTHON=1
  1677. else
  1678. PACKAGES_NETDATA_PYTHON3=1
  1679. fi
  1680. PACKAGES_NETDATA_SENSORS=1
  1681. PACKAGES_NETDATA_DATABASE=1
  1682. PACKAGES_NETDATA_EBPF=1
  1683. PACKAGES_NETDATA_STREAMING_COMPRESSION=1
  1684. ;;
  1685. netdata)
  1686. PACKAGES_NETDATA=1
  1687. PACKAGES_NETDATA_PYTHON3=1
  1688. PACKAGES_NETDATA_DATABASE=1
  1689. PACKAGES_NETDATA_EBPF=1
  1690. PACKAGES_NETDATA_STREAMING_COMPRESSION=1
  1691. ;;
  1692. python | netdata-python)
  1693. PACKAGES_NETDATA_PYTHON=1
  1694. ;;
  1695. python3 | netdata-python3)
  1696. PACKAGES_NETDATA_PYTHON3=1
  1697. ;;
  1698. sensors | netdata-sensors)
  1699. PACKAGES_NETDATA=1
  1700. PACKAGES_NETDATA_PYTHON3=1
  1701. PACKAGES_NETDATA_SENSORS=1
  1702. PACKAGES_NETDATA_DATABASE=1
  1703. ;;
  1704. firehol | update-ipsets | firehol-all | fireqos)
  1705. PACKAGES_IPRANGE=1
  1706. PACKAGES_FIREHOL=1
  1707. PACKAGES_FIREQOS=1
  1708. PACKAGES_IPRANGE=1
  1709. PACKAGES_UPDATE_IPSETS=1
  1710. ;;
  1711. demo | all)
  1712. PACKAGES_NETDATA=1
  1713. if [ "${pv}" -eq 2 ]; then
  1714. PACKAGES_NETDATA_PYTHON=1
  1715. else
  1716. PACKAGES_NETDATA_PYTHON3=1
  1717. fi
  1718. PACKAGES_DEBUG=1
  1719. PACKAGES_IPRANGE=1
  1720. PACKAGES_FIREHOL=1
  1721. PACKAGES_FIREQOS=1
  1722. PACKAGES_UPDATE_IPSETS=1
  1723. PACKAGES_NETDATA_DEMO_SITE=1
  1724. PACKAGES_NETDATA_DATABASE=1
  1725. PACKAGES_NETDATA_EBPF=1
  1726. ;;
  1727. help | -h | --help)
  1728. usage
  1729. exit 1
  1730. ;;
  1731. *)
  1732. echo >&2 "ERROR: Cannot understand option '${1}'"
  1733. echo >&2
  1734. usage
  1735. exit 1
  1736. ;;
  1737. esac
  1738. shift
  1739. done
  1740. # Check for missing core commands like grep, warn the user to install it and bail out cleanly
  1741. if ! command -v grep > /dev/null 2>&1; then
  1742. echo >&2
  1743. echo >&2 "ERROR: 'grep' is required for the install to run correctly and was not found on the system."
  1744. echo >&2 "Please install grep and run the installer again."
  1745. echo >&2
  1746. exit 1
  1747. fi
  1748. if [ -z "${package_installer}" ] || [ -z "${tree}" ]; then
  1749. if [ -z "${distribution}" ]; then
  1750. # we dont know the distribution
  1751. autodetect_distribution || user_picks_distribution
  1752. fi
  1753. # When no package installer is detected, try again from distro info if any
  1754. if [ -z "${package_installer}" ]; then
  1755. detect_package_manager_from_distribution "${distribution}"
  1756. fi
  1757. # Validate package manager trees
  1758. validate_package_trees
  1759. fi
  1760. [ "${detection}" = "/etc/os-release" ] && cat << EOF
  1761. /etc/os-release information:
  1762. NAME : ${NAME}
  1763. VERSION : ${VERSION}
  1764. ID : ${ID}
  1765. ID_LIKE : ${ID_LIKE}
  1766. VERSION_ID : ${VERSION_ID}
  1767. EOF
  1768. cat << EOF
  1769. We detected these:
  1770. Distribution : ${distribution}
  1771. Version : ${version}
  1772. Codename : ${codename}
  1773. Package Manager : ${package_installer}
  1774. Packages Tree : ${tree}
  1775. Detection Method: ${detection}
  1776. Default Python v: ${pv} $([ ${pv} -eq 2 ] && [ "${PACKAGES_NETDATA_PYTHON3}" -eq 1 ] && echo "(will install python3 too)")
  1777. EOF
  1778. mapfile -t PACKAGES_TO_INSTALL < <(packages | sort -u)
  1779. if [ ${#PACKAGES_TO_INSTALL[@]} -gt 0 ]; then
  1780. echo >&2
  1781. echo >&2 "The following command will be run:"
  1782. echo >&2
  1783. DRYRUN=1
  1784. "${package_installer}" "${PACKAGES_TO_INSTALL[@]}"
  1785. DRYRUN=0
  1786. echo >&2
  1787. echo >&2
  1788. if [ "${DONT_WAIT}" -eq 0 ] && [ "${NON_INTERACTIVE}" -eq 0 ]; then
  1789. read -r -p "Press ENTER to run it > " || exit 1
  1790. fi
  1791. "${package_installer}" "${PACKAGES_TO_INSTALL[@]}" || install_failed $?
  1792. echo >&2
  1793. echo >&2 "All Done! - Now proceed to the next step."
  1794. echo >&2
  1795. else
  1796. echo >&2
  1797. echo >&2 "All required packages are already installed. Now proceed to the next step."
  1798. echo >&2
  1799. fi
  1800. remote_log "OK"
  1801. exit 0