install-required-packages.sh 59 KB

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