install-required-packages.sh 54 KB

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