install-required-packages.sh 59 KB

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