install-required-packages.sh 56 KB

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