install-required-packages.sh 57 KB

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