install-required-packages.sh 61 KB

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