install-required-packages.sh 56 KB

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