install-required-packages.sh 57 KB

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