install-required-packages.sh 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174
  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 normaly 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 " - Redhat/Fedora/Centos based (installer is: yum)" && opts="yum ${opts}"
  269. [ -n "${dnf}" ] && echo >&2 " - Redhat/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']="dev-util/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']="dev-libs/libelf"
  1051. ['debian']="libelf-dev"
  1052. ['ubuntu']="libelf-dev"
  1053. ['fedora']="elfutils-libelf-devel"
  1054. ['centos']="elfutils-libelf-devel"
  1055. ['rhel']="elfutils-libelf-devel"
  1056. ['clearlinux']="devpkg-elfutils"
  1057. ['suse']="libelf-devel"
  1058. ['macos']="NOTREQUIRED"
  1059. ['freebsd']="NOTREQUIRED"
  1060. ['default']="libelf-devel"
  1061. # exceptions
  1062. ['alpine-3.5']="libelf-dev"
  1063. ['alpine-3.4']="libelf-dev"
  1064. ['alpine-3.3']="libelf-dev"
  1065. )
  1066. validate_package_trees() {
  1067. if type -t validate_tree_${tree} > /dev/null; then
  1068. validate_tree_${tree}
  1069. fi
  1070. }
  1071. validate_installed_package() {
  1072. validate_${package_installer} "${p}"
  1073. }
  1074. suitable_package() {
  1075. local package="${1//-/_}" p="" v="${version//.*/}"
  1076. echo >&2 "Searching for ${package} ..."
  1077. eval "p=\${pkg_${package}['${distribution,,}-${version,,}']}"
  1078. [ -z "${p}" ] && eval "p=\${pkg_${package}['${distribution,,}-${v,,}']}"
  1079. [ -z "${p}" ] && eval "p=\${pkg_${package}['${distribution,,}']}"
  1080. [ -z "${p}" ] && eval "p=\${pkg_${package}['${tree}-${version}']}"
  1081. [ -z "${p}" ] && eval "p=\${pkg_${package}['${tree}-${v}']}"
  1082. [ -z "${p}" ] && eval "p=\${pkg_${package}['${tree}']}"
  1083. [ -z "${p}" ] && eval "p=\${pkg_${package}['default']}"
  1084. if [[ "${p/|*/}" =~ ^(ERROR|WARNING|INFO)$ ]]; then
  1085. echo >&2 "${p/|*/}"
  1086. echo >&2 "package ${1} is not available in this system."
  1087. if [ -z "${p/*|/}" ]; then
  1088. echo >&2 "You may try to install without it."
  1089. else
  1090. echo >&2 "${p/*|/}"
  1091. fi
  1092. echo >&2
  1093. return 1
  1094. elif [ "${p}" = "NOTREQUIRED" ]; then
  1095. return 0
  1096. elif [ -z "${p}" ]; then
  1097. echo >&2 "WARNING"
  1098. echo >&2 "package ${1} is not availabe in this system."
  1099. echo >&2
  1100. return 1
  1101. else
  1102. if [ "${IGNORE_INSTALLED}" -eq 0 ]; then
  1103. validate_installed_package "${p}"
  1104. else
  1105. echo "${p}"
  1106. fi
  1107. return 0
  1108. fi
  1109. }
  1110. packages() {
  1111. # detect the packages we need to install on this system
  1112. # -------------------------------------------------------------------------
  1113. # basic build environment
  1114. suitable_package distro-sdk
  1115. require_cmd git || suitable_package git
  1116. require_cmd find || suitable_package find
  1117. require_cmd gcc ||
  1118. require_cmd gcc-multilib || suitable_package gcc
  1119. require_cmd make || suitable_package make
  1120. require_cmd autoconf || suitable_package autoconf
  1121. suitable_package autoconf-archive
  1122. require_cmd autogen || suitable_package autogen
  1123. require_cmd automake || suitable_package automake
  1124. require_cmd libtoolize || suitable_package libtool
  1125. require_cmd pkg-config || suitable_package pkg-config
  1126. require_cmd cmake || suitable_package cmake
  1127. # -------------------------------------------------------------------------
  1128. # debugging tools for development
  1129. if [ "${PACKAGES_DEBUG}" -ne 0 ]; then
  1130. require_cmd traceroute || suitable_package traceroute
  1131. require_cmd tcpdump || suitable_package tcpdump
  1132. require_cmd screen || suitable_package screen
  1133. if [ "${PACKAGES_NETDATA}" -ne 0 ]; then
  1134. require_cmd gdb || suitable_package gdb
  1135. require_cmd valgrind || suitable_package valgrind
  1136. fi
  1137. fi
  1138. # -------------------------------------------------------------------------
  1139. # common command line tools
  1140. if [ "${PACKAGES_NETDATA}" -ne 0 ]; then
  1141. require_cmd tar || suitable_package tar
  1142. require_cmd curl || suitable_package curl
  1143. require_cmd gzip || suitable_package gzip
  1144. require_cmd nc || suitable_package netcat
  1145. fi
  1146. # -------------------------------------------------------------------------
  1147. # firehol/fireqos/update-ipsets command line tools
  1148. if [ "${PACKAGES_FIREQOS}" -ne 0 ]; then
  1149. require_cmd ip || suitable_package iproute2
  1150. fi
  1151. if [ "${PACKAGES_FIREHOL}" -ne 0 ]; then
  1152. require_cmd iptables || suitable_package iptables
  1153. require_cmd ipset || suitable_package ipset
  1154. require_cmd ulogd ulogd2 || suitable_package ulogd
  1155. require_cmd traceroute || suitable_package traceroute
  1156. require_cmd bridge || suitable_package bridge-utils
  1157. fi
  1158. if [ "${PACKAGES_UPDATE_IPSETS}" -ne 0 ]; then
  1159. require_cmd ipset || suitable_package ipset
  1160. require_cmd zip || suitable_package zip
  1161. require_cmd funzip || suitable_package unzip
  1162. fi
  1163. # -------------------------------------------------------------------------
  1164. # netdata libraries
  1165. if [ "${PACKAGES_NETDATA}" -ne 0 ]; then
  1166. suitable_package libz-dev
  1167. suitable_package libuuid-dev
  1168. suitable_package libmnl-dev
  1169. suitable_package json-c-dev
  1170. fi
  1171. # -------------------------------------------------------------------------
  1172. # sensors
  1173. if [ "${PACKAGES_NETDATA_SENSORS}" -ne 0 ]; then
  1174. require_cmd sensors || suitable_package lm_sensors
  1175. fi
  1176. # -------------------------------------------------------------------------
  1177. # netdata database
  1178. if [ "${PACKAGES_NETDATA_DATABASE}" -ne 0 ]; then
  1179. suitable_package libuv
  1180. suitable_package lz4
  1181. suitable_package openssl
  1182. suitable_package judy
  1183. fi
  1184. # -------------------------------------------------------------------------
  1185. # ebpf plugin
  1186. if [ "${PACKAGES_NETDATA_EBPF}" -ne 0 ]; then
  1187. suitable_package libelf
  1188. fi
  1189. # -------------------------------------------------------------------------
  1190. # scripting interpreters for netdata plugins
  1191. if [ "${PACKAGES_NETDATA_NODEJS}" -ne 0 ]; then
  1192. require_cmd nodejs node js || suitable_package nodejs
  1193. fi
  1194. # -------------------------------------------------------------------------
  1195. # python2
  1196. if [ "${PACKAGES_NETDATA_PYTHON}" -ne 0 ]; then
  1197. require_cmd python || suitable_package python
  1198. [ "${PACKAGES_NETDATA_PYTHON_MONGO}" -ne 0 ] && suitable_package python-pymongo
  1199. # suitable_package python-requests
  1200. # suitable_package python-pip
  1201. [ "${PACKAGES_NETDATA_PYTHON_MYSQL}" -ne 0 ] && suitable_package python-mysqldb
  1202. [ "${PACKAGES_NETDATA_PYTHON_POSTGRES}" -ne 0 ] && suitable_package python-psycopg2
  1203. fi
  1204. # -------------------------------------------------------------------------
  1205. # python3
  1206. if [ "${PACKAGES_NETDATA_PYTHON3}" -ne 0 ]; then
  1207. require_cmd python3 || suitable_package python3
  1208. [ "${PACKAGES_NETDATA_PYTHON_MONGO}" -ne 0 ] && suitable_package python3-pymongo
  1209. # suitable_package python3-requests
  1210. # suitable_package python3-pip
  1211. [ "${PACKAGES_NETDATA_PYTHON_MYSQL}" -ne 0 ] && suitable_package python3-mysqldb
  1212. [ "${PACKAGES_NETDATA_PYTHON_POSTGRES}" -ne 0 ] && suitable_package python3-psycopg2
  1213. fi
  1214. # -------------------------------------------------------------------------
  1215. # applications needed for the netdata demo sites
  1216. if [ "${PACKAGES_NETDATA_DEMO_SITE}" -ne 0 ]; then
  1217. require_cmd sudo || suitable_package sudo
  1218. require_cmd jq || suitable_package jq
  1219. require_cmd nginx || suitable_package nginx
  1220. require_cmd postconf || suitable_package postfix
  1221. require_cmd lxc-create || suitable_package lxc
  1222. require_cmd logwatch || suitable_package logwatch
  1223. require_cmd mail || suitable_package mailutils
  1224. require_cmd iostat || suitable_package sysstat
  1225. require_cmd iotop || suitable_package iotop
  1226. fi
  1227. }
  1228. DRYRUN=0
  1229. run() {
  1230. printf >&2 "%q " "${@}"
  1231. printf >&2 "\n"
  1232. if [ ! "${DRYRUN}" -eq 1 ]; then
  1233. "${@}"
  1234. return $?
  1235. fi
  1236. return 0
  1237. }
  1238. sudo=
  1239. if [ ${UID} -ne 0 ]; then
  1240. sudo="sudo"
  1241. fi
  1242. # -----------------------------------------------------------------------------
  1243. # debian / ubuntu
  1244. validate_install_apt_get() {
  1245. echo >&2 " > Checking if package '${*}' is installed..."
  1246. [ "$(dpkg-query -W --showformat='${Status}\n' "${*}")" = "install ok installed" ] || echo "${*}"
  1247. }
  1248. install_apt_get() {
  1249. local opts=""
  1250. if [ "${NON_INTERACTIVE}" -eq 1 ]; then
  1251. echo >&2 "Running in non-interactive mode"
  1252. # http://serverfault.com/questions/227190/how-do-i-ask-apt-get-to-skip-any-interactive-post-install-configuration-steps
  1253. export DEBIAN_FRONTEND="noninteractive"
  1254. opts="${opts} -yq"
  1255. fi
  1256. read -r -a apt_opts <<< "$opts"
  1257. # update apt repository caches
  1258. echo >&2 "NOTE: Running apt-get update and updating your APT caches ..."
  1259. if [ "${version}" = 8 ]; then
  1260. echo >&2 "WARNING: You seem to be on Debian 8 (jessie) which is old enough we have to disable Check-Valid-Until checks"
  1261. if ! cat /etc/apt/sources.list /etc/apt/sources.list.d/* 2> /dev/null | grep -q jessie-backports; then
  1262. echo >&2 "We also have to enable the jessie-backports repository"
  1263. if prompt "Is this okay?"; then
  1264. ${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'
  1265. fi
  1266. fi
  1267. run ${sudo} apt-get "${apt_opts[@]}" -o Acquire::Check-Valid-Until=false update
  1268. else
  1269. run ${sudo} apt-get "${apt_opts[@]}" update
  1270. fi
  1271. # install the required packages
  1272. run ${sudo} apt-get "${apt_opts[@]}" install "${@}"
  1273. }
  1274. # -----------------------------------------------------------------------------
  1275. # centos / rhel
  1276. prompt() {
  1277. if [ "${NON_INTERACTIVE}" -eq 1 ]; then
  1278. echo >&2 "Running in non-interactive mode, assuming yes (y)"
  1279. echo >&2 " > Would have promptedfor ${1} ..."
  1280. return 0
  1281. fi
  1282. while true; do
  1283. read -r -p "${1} [y/n] " yn
  1284. case $yn in
  1285. [Yy]*) return 0 ;;
  1286. [Nn]*) return 1 ;;
  1287. *) echo >&2 "Please answer with yes (y) or no (n)." ;;
  1288. esac
  1289. done
  1290. }
  1291. validate_tree_freebsd() {
  1292. local opts=
  1293. if [ "${NON_INTERACTIVE}" -eq 1 ]; then
  1294. echo >&2 "Running in non-interactive mode"
  1295. opts="-y"
  1296. fi
  1297. echo >&2 " > FreeBSD Version: ${version} ..."
  1298. make="make"
  1299. echo >&2 " > Checking for gmake ..."
  1300. if ! pkg query %n-%v | grep -q gmake; then
  1301. if prompt "gmake is required to build on FreeBSD and is not installed. Shall I install it?"; then
  1302. run ${sudo} pkg install ${opts} gmake
  1303. fi
  1304. fi
  1305. }
  1306. validate_tree_centos() {
  1307. local opts=
  1308. if [ "${NON_INTERACTIVE}" -eq 1 ]; then
  1309. echo >&2 "Running in non-interactive mode"
  1310. opts="-y"
  1311. fi
  1312. echo >&2 " > CentOS Version: ${version} ..."
  1313. echo >&2 " > Checking for epel ..."
  1314. if ! rpm -qa | grep epel > /dev/null; then
  1315. if prompt "epel not found, shall I install it?"; then
  1316. run ${sudo} yum ${opts} install epel-release
  1317. fi
  1318. fi
  1319. if [[ "${version}" =~ ^8(\..*)?$ ]]; then
  1320. echo >&2 " > Checking for config-manager ..."
  1321. if ! run yum ${sudo} config-manager; then
  1322. if prompt "config-manager not found, shall I install it?"; then
  1323. run ${sudo} yum ${opts} install 'dnf-command(config-manager)'
  1324. fi
  1325. fi
  1326. echo >&2 " > Checking for PowerTools ..."
  1327. if ! run yum ${sudo} repolist | grep PowerTools; then
  1328. if prompt "PowerTools not found, shall I install it?"; then
  1329. run ${sudo} yum ${opts} config-manager --set-enabled PowerTools
  1330. fi
  1331. fi
  1332. echo >&2 " > Checking for Okay ..."
  1333. if ! rpm -qa | grep okay > /dev/null; then
  1334. if prompt "okay not found, shall I install it?"; then
  1335. run ${sudo} yum ${opts} install http://repo.okay.com.mx/centos/8/x86_64/release/okay-release-1-3.el8.noarch.rpm
  1336. fi
  1337. fi
  1338. echo >&2 " > Installing Judy-devel directly ..."
  1339. 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
  1340. elif [[ "${version}" =~ ^6\..*$ ]]; then
  1341. echo >&2 " > Detected CentOS 6.x ..."
  1342. echo >&2 " > Checking for Okay ..."
  1343. if ! rpm -qa | grep okay > /dev/null; then
  1344. if prompt "okay not found, shall I install it?"; then
  1345. run ${sudo} yum ${opts} install http://repo.okay.com.mx/centos/6/x86_64/release/okay-release-1-3.el6.noarch.rpm
  1346. fi
  1347. fi
  1348. fi
  1349. }
  1350. validate_install_yum() {
  1351. echo >&2 " > Checking if package '${*}' is installed..."
  1352. yum list installed "${*}" > /dev/null 2>&1 || echo "${*}"
  1353. }
  1354. install_yum() {
  1355. # download the latest package info
  1356. if [ "${DRYRUN}" -eq 1 ]; then
  1357. echo >&2 " >> IMPORTANT << "
  1358. echo >&2 " Please make sure your system is up to date"
  1359. echo >&2 " by running: ${sudo} yum update "
  1360. echo >&2
  1361. fi
  1362. local opts=
  1363. if [ "${NON_INTERACTIVE}" -eq 1 ]; then
  1364. echo >&2 "Running in non-interactive mode"
  1365. # http://unix.stackexchange.com/questions/87822/does-yum-have-an-equivalent-to-apt-aptitudes-debian-frontend-noninteractive
  1366. opts="-y"
  1367. fi
  1368. read -r -a yum_opts <<< "${opts}"
  1369. # install the required packages
  1370. run ${sudo} yum "${yum_opts[@]}" install "${@}" # --enablerepo=epel-testing
  1371. }
  1372. # -----------------------------------------------------------------------------
  1373. # fedora
  1374. validate_install_dnf() {
  1375. echo >&2 " > Checking if package '${*}' is installed..."
  1376. dnf list installed "${*}" > /dev/null 2>&1 || echo "${*}"
  1377. }
  1378. install_dnf() {
  1379. # download the latest package info
  1380. if [ "${DRYRUN}" -eq 1 ]; then
  1381. echo >&2 " >> IMPORTANT << "
  1382. echo >&2 " Please make sure your system is up to date"
  1383. echo >&2 " by running: ${sudo} dnf update "
  1384. echo >&2
  1385. fi
  1386. local opts=
  1387. if [ "${NON_INTERACTIVE}" -eq 1 ]; then
  1388. echo >&2 "Running in non-interactive mode"
  1389. # man dnf
  1390. opts="-y"
  1391. fi
  1392. # install the required packages
  1393. # --setopt=strict=0 allows dnf to proceed
  1394. # installing whatever is available
  1395. # even if a package is not found
  1396. opts="$opts --setopt=strict=0"
  1397. read -r -a dnf_opts <<< "$opts"
  1398. run ${sudo} dnf "${dnf_opts[@]}" install "${@}"
  1399. }
  1400. # -----------------------------------------------------------------------------
  1401. # gentoo
  1402. validate_install_emerge() {
  1403. echo "${*}"
  1404. }
  1405. install_emerge() {
  1406. # download the latest package info
  1407. # we don't do this for emerge - it is very slow
  1408. # and most users are expected to do this daily
  1409. # emerge --sync
  1410. if [ "${DRYRUN}" -eq 1 ]; then
  1411. echo >&2 " >> IMPORTANT << "
  1412. echo >&2 " Please make sure your system is up to date"
  1413. echo >&2 " by running: ${sudo} emerge --sync or ${sudo} eix-sync "
  1414. echo >&2
  1415. fi
  1416. local opts="--ask"
  1417. if [ "${NON_INTERACTIVE}" -eq 1 ]; then
  1418. echo >&2 "Running in non-interactive mode"
  1419. opts=""
  1420. fi
  1421. read -r -a emerge_opts <<< "$opts"
  1422. # install the required packages
  1423. run ${sudo} emerge "${emerge_opts[@]}" -v --noreplace "${@}"
  1424. }
  1425. # -----------------------------------------------------------------------------
  1426. # alpine
  1427. validate_install_apk() {
  1428. echo "${*}"
  1429. }
  1430. install_apk() {
  1431. # download the latest package info
  1432. if [ "${DRYRUN}" -eq 1 ]; then
  1433. echo >&2 " >> IMPORTANT << "
  1434. echo >&2 " Please make sure your system is up to date"
  1435. echo >&2 " by running: ${sudo} apk update "
  1436. echo >&2
  1437. fi
  1438. local opts="--force-broken-world"
  1439. if [ "${NON_INTERACTIVE}" -eq 1 ]; then
  1440. echo >&2 "Running in non-interactive mode"
  1441. else
  1442. opts="${opts} -i"
  1443. fi
  1444. read -r -a apk_opts <<< "$opts"
  1445. # install the required packages
  1446. run ${sudo} apk add "${apk_opts[@]}" "${@}"
  1447. }
  1448. # -----------------------------------------------------------------------------
  1449. # sabayon
  1450. validate_install_equo() {
  1451. echo >&2 " > Checking if package '${*}' is installed..."
  1452. equo s --installed "${*}" > /dev/null 2>&1 || echo "${*}"
  1453. }
  1454. install_equo() {
  1455. # download the latest package info
  1456. if [ "${DRYRUN}" -eq 1 ]; then
  1457. echo >&2 " >> IMPORTANT << "
  1458. echo >&2 " Please make sure your system is up to date"
  1459. echo >&2 " by running: ${sudo} equo up "
  1460. echo >&2
  1461. fi
  1462. local opts="-av"
  1463. if [ "${NON_INTERACTIVE}" -eq 1 ]; then
  1464. echo >&2 "Running in non-interactive mode"
  1465. opts="-v"
  1466. fi
  1467. read -r -a equo_opts <<< "$opts"
  1468. # install the required packages
  1469. run ${sudo} equo i "${equo_opts[@]}" "${@}"
  1470. }
  1471. # -----------------------------------------------------------------------------
  1472. # arch
  1473. PACMAN_DB_SYNCED=0
  1474. validate_install_pacman() {
  1475. if [ ${PACMAN_DB_SYNCED} -eq 0 ]; then
  1476. echo >&2 " > Running pacman -Sy to sync the database"
  1477. local x
  1478. x=$(pacman -Sy)
  1479. [ -z "${x}" ] && echo "${*}"
  1480. PACMAN_DB_SYNCED=1
  1481. fi
  1482. echo >&2 " > Checking if package '${*}' is installed..."
  1483. # In pacman, you can utilize alternative flags to exactly match package names,
  1484. # but is highly likely we require pattern matching too in this so we keep -s and match
  1485. # the exceptional cases like so
  1486. local x=""
  1487. case "${package}" in
  1488. "gcc")
  1489. # Temporary workaround: In archlinux, default installation includes runtime libs under package "gcc"
  1490. # These are not sufficient for netdata install, so we need to make sure that the appropriate libraries are there
  1491. # by ensuring devel libs are available
  1492. x=$(pacman -Qs "${*}" | grep "base-devel")
  1493. ;;
  1494. "tar")
  1495. x=$(pacman -Qs "${*}" | grep "local/tar")
  1496. ;;
  1497. "make")
  1498. x=$(pacman -Qs "${*}" | grep "local/make ")
  1499. ;;
  1500. *)
  1501. x=$(pacman -Qs "${*}")
  1502. ;;
  1503. esac
  1504. [ -z "${x}" ] && echo "${*}"
  1505. }
  1506. install_pacman() {
  1507. # download the latest package info
  1508. if [ "${DRYRUN}" -eq 1 ]; then
  1509. echo >&2 " >> IMPORTANT << "
  1510. echo >&2 " Please make sure your system is up to date"
  1511. echo >&2 " by running: ${sudo} pacman -Syu "
  1512. echo >&2
  1513. fi
  1514. # install the required packages
  1515. if [ "${NON_INTERACTIVE}" -eq 1 ]; then
  1516. echo >&2 "Running in non-interactive mode"
  1517. # http://unix.stackexchange.com/questions/52277/pacman-option-to-assume-yes-to-every-question/52278
  1518. # Try the noconfirm option, if that fails, go with the legacy way for non-interactive
  1519. run ${sudo} pacman --noconfirm --needed -S "${@}" || yes | run ${sudo} pacman --needed -S "${@}"
  1520. else
  1521. run ${sudo} pacman --needed -S "${@}"
  1522. fi
  1523. }
  1524. # -----------------------------------------------------------------------------
  1525. # suse / opensuse
  1526. validate_install_zypper() {
  1527. rpm -q "${*}" > /dev/null 2>&1 || echo "${*}"
  1528. }
  1529. install_zypper() {
  1530. # download the latest package info
  1531. if [ "${DRYRUN}" -eq 1 ]; then
  1532. echo >&2 " >> IMPORTANT << "
  1533. echo >&2 " Please make sure your system is up to date"
  1534. echo >&2 " by running: ${sudo} zypper update "
  1535. echo >&2
  1536. fi
  1537. local opts="--ignore-unknown"
  1538. if [ "${NON_INTERACTIVE}" -eq 1 ]; then
  1539. echo >&2 "Running in non-interactive mode"
  1540. # http://unix.stackexchange.com/questions/82016/how-to-use-zypper-in-bash-scripts-for-someone-coming-from-apt-get
  1541. opts="${opts} --non-interactive"
  1542. fi
  1543. read -r -a zypper_opts <<< "$opts"
  1544. # install the required packages
  1545. run ${sudo} zypper "${zypper_opts[@]}" install "${@}"
  1546. }
  1547. # -----------------------------------------------------------------------------
  1548. # clearlinux
  1549. validate_install_swupd() {
  1550. swupd bundle-list | grep -q "${*}" || echo "${*}"
  1551. }
  1552. install_swupd() {
  1553. # download the latest package info
  1554. if [ "${DRYRUN}" -eq 1 ]; then
  1555. echo >&2 " >> IMPORTANT << "
  1556. echo >&2 " Please make sure your system is up to date"
  1557. echo >&2 " by running: ${sudo} swupd update "
  1558. echo >&2
  1559. fi
  1560. run ${sudo} swupd bundle-add "${@}"
  1561. }
  1562. # -----------------------------------------------------------------------------
  1563. # macOS
  1564. validate_install_pkg() {
  1565. pkg query %n-%v | grep -q "${*}" || echo "${*}"
  1566. }
  1567. validate_install_brew() {
  1568. brew list | grep -q "${*}" || echo "${*}"
  1569. }
  1570. install_pkg() {
  1571. # download the latest package info
  1572. if [ "${DRYRUN}" -eq 1 ]; then
  1573. echo >&2 " >> IMPORTANT << "
  1574. echo >&2 " Please make sure your system is up to date"
  1575. echo >&2 " by running: pkg update "
  1576. echo >&2
  1577. fi
  1578. local opts=
  1579. if [ "${NON_INTERACTIVE}" -eq 1 ]; then
  1580. echo >&2 "Running in non-interactive mode"
  1581. opts="-y"
  1582. fi
  1583. read -r -a pkg_opts <<< "${opts}"
  1584. run ${sudo} pkg install "${pkg_opts[@]}" "${@}"
  1585. }
  1586. install_brew() {
  1587. # download the latest package info
  1588. if [ "${DRYRUN}" -eq 1 ]; then
  1589. echo >&2 " >> IMPORTANT << "
  1590. echo >&2 " Please make sure your system is up to date"
  1591. echo >&2 " by running: brew upgrade "
  1592. echo >&2
  1593. fi
  1594. run brew install "${@}"
  1595. }
  1596. # -----------------------------------------------------------------------------
  1597. install_failed() {
  1598. local ret="${1}"
  1599. cat << EOF
  1600. We are very sorry!
  1601. Installation of required packages failed.
  1602. What to do now:
  1603. 1. Make sure your system is updated.
  1604. Most of the times, updating your system will resolve the issue.
  1605. 2. If the error message is about a specific package, try removing
  1606. that package from the command and run it again.
  1607. Depending on the broken package, you may be able to continue.
  1608. 3. Let us know. We may be able to help.
  1609. Open a github issue with the above log, at:
  1610. https://github.com/netdata/netdata/issues
  1611. EOF
  1612. remote_log "FAILED" "${ret}"
  1613. exit 1
  1614. }
  1615. remote_log() {
  1616. # log success or failure on our system
  1617. # to help us solve installation issues
  1618. curl > /dev/null 2>&1 -Ss --max-time 3 "https://registry.my-netdata.io/log/installer?status=${1}&error=${2}&distribution=${distribution}&version=${version}&installer=${package_installer}&tree=${tree}&detection=${detection}&netdata=${PACKAGES_NETDATA}&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}"
  1619. }
  1620. if [ -z "${1}" ]; then
  1621. usage
  1622. exit 1
  1623. fi
  1624. pv=$(python --version 2>&1)
  1625. if [ "${tree}" = macos ]; then
  1626. pv=3
  1627. elif [[ "${pv}" =~ ^Python\ 2.* ]]; then
  1628. pv=2
  1629. elif [[ "${pv}" =~ ^Python\ 3.* ]]; then
  1630. pv=3
  1631. elif [[ "${tree}" == "centos" ]] && [ "${version}" -lt 8 ]; then
  1632. pv=2
  1633. else
  1634. pv=3
  1635. fi
  1636. # parse command line arguments
  1637. DONT_WAIT=0
  1638. NON_INTERACTIVE=0
  1639. IGNORE_INSTALLED=0
  1640. while [ -n "${1}" ]; do
  1641. case "${1}" in
  1642. distribution)
  1643. distribution="${2}"
  1644. shift
  1645. ;;
  1646. version)
  1647. version="${2}"
  1648. shift
  1649. ;;
  1650. codename)
  1651. codename="${2}"
  1652. shift
  1653. ;;
  1654. installer)
  1655. check_package_manager "${2}" || exit 1
  1656. shift
  1657. ;;
  1658. dont-wait | --dont-wait | -n)
  1659. DONT_WAIT=1
  1660. ;;
  1661. non-interactive | --non-interactive | -y)
  1662. NON_INTERACTIVE=1
  1663. ;;
  1664. ignore-installed | --ignore-installed | -i)
  1665. IGNORE_INSTALLED=1
  1666. ;;
  1667. netdata-all)
  1668. PACKAGES_NETDATA=1
  1669. PACKAGES_NETDATA_NODEJS=1
  1670. if [ "${pv}" -eq 2 ]; then
  1671. PACKAGES_NETDATA_PYTHON=1
  1672. PACKAGES_NETDATA_PYTHON_MYSQL=1
  1673. PACKAGES_NETDATA_PYTHON_POSTGRES=1
  1674. PACKAGES_NETDATA_PYTHON_MONGO=1
  1675. else
  1676. PACKAGES_NETDATA_PYTHON3=1
  1677. PACKAGES_NETDATA_PYTHON3_MYSQL=1
  1678. PACKAGES_NETDATA_PYTHON3_POSTGRES=1
  1679. PACKAGES_NETDATA_PYTHON3_MONGO=1
  1680. fi
  1681. PACKAGES_NETDATA_SENSORS=1
  1682. PACKAGES_NETDATA_DATABASE=1
  1683. PACKAGES_NETDATA_EBPF=1
  1684. ;;
  1685. netdata)
  1686. PACKAGES_NETDATA=1
  1687. PACKAGES_NETDATA_PYTHON3=1
  1688. PACKAGES_NETDATA_DATABASE=1
  1689. PACKAGES_NETDATA_EBPF=1
  1690. ;;
  1691. python | netdata-python)
  1692. PACKAGES_NETDATA_PYTHON=1
  1693. ;;
  1694. python3 | netdata-python3)
  1695. PACKAGES_NETDATA_PYTHON3=1
  1696. ;;
  1697. python-mysql | mysql-python | mysqldb | netdata-mysql)
  1698. if [ "${pv}" -eq 2 ]; then
  1699. PACKAGES_NETDATA_PYTHON=1
  1700. PACKAGES_NETDATA_PYTHON_MYSQL=1
  1701. else
  1702. PACKAGES_NETDATA_PYTHON3=1
  1703. PACKAGES_NETDATA_PYTHON3_MYSQL=1
  1704. fi
  1705. ;;
  1706. python-postgres | postgres-python | psycopg2 | netdata-postgres)
  1707. if [ "${pv}" -eq 2 ]; then
  1708. PACKAGES_NETDATA_PYTHON=1
  1709. PACKAGES_NETDATA_PYTHON_POSTGRES=1
  1710. else
  1711. PACKAGES_NETDATA_PYTHON3=1
  1712. PACKAGES_NETDATA_PYTHON3_POSTGRES=1
  1713. fi
  1714. ;;
  1715. python-pymongo)
  1716. if [ "${pv}" -eq 2 ]; then
  1717. PACKAGES_NETDATA_PYTHON=1
  1718. PACKAGES_NETDATA_PYTHON_MONGO=1
  1719. else
  1720. PACKAGES_NETDATA_PYTHON3=1
  1721. PACKAGES_NETDATA_PYTHON3_MONGO=1
  1722. fi
  1723. ;;
  1724. nodejs | netdata-nodejs)
  1725. PACKAGES_NETDATA=1
  1726. PACKAGES_NETDATA_NODEJS=1
  1727. PACKAGES_NETDATA_DATABASE=1
  1728. ;;
  1729. sensors | netdata-sensors)
  1730. PACKAGES_NETDATA=1
  1731. PACKAGES_NETDATA_PYTHON3=1
  1732. PACKAGES_NETDATA_SENSORS=1
  1733. PACKAGES_NETDATA_DATABASE=1
  1734. ;;
  1735. firehol | update-ipsets | firehol-all | fireqos)
  1736. PACKAGES_IPRANGE=1
  1737. PACKAGES_FIREHOL=1
  1738. PACKAGES_FIREQOS=1
  1739. PACKAGES_IPRANGE=1
  1740. PACKAGES_UPDATE_IPSETS=1
  1741. ;;
  1742. demo | all)
  1743. PACKAGES_NETDATA=1
  1744. PACKAGES_NETDATA_NODEJS=1
  1745. if [ "${pv}" -eq 2 ]; then
  1746. PACKAGES_NETDATA_PYTHON=1
  1747. PACKAGES_NETDATA_PYTHON_MYSQL=1
  1748. PACKAGES_NETDATA_PYTHON_POSTGRES=1
  1749. PACKAGES_NETDATA_PYTHON_MONGO=1
  1750. else
  1751. PACKAGES_NETDATA_PYTHON3=1
  1752. PACKAGES_NETDATA_PYTHON3_MYSQL=1
  1753. PACKAGES_NETDATA_PYTHON3_POSTGRES=1
  1754. PACKAGES_NETDATA_PYTHON3_MONGO=1
  1755. fi
  1756. PACKAGES_DEBUG=1
  1757. PACKAGES_IPRANGE=1
  1758. PACKAGES_FIREHOL=1
  1759. PACKAGES_FIREQOS=1
  1760. PACKAGES_UPDATE_IPSETS=1
  1761. PACKAGES_NETDATA_DEMO_SITE=1
  1762. PACKAGES_NETDATA_DATABASE=1
  1763. PACKAGES_NETDATA_EBPF=1
  1764. ;;
  1765. help | -h | --help)
  1766. usage
  1767. exit 1
  1768. ;;
  1769. *)
  1770. echo >&2 "ERROR: Cannot understand option '${1}'"
  1771. echo >&2
  1772. usage
  1773. exit 1
  1774. ;;
  1775. esac
  1776. shift
  1777. done
  1778. # Check for missing core commands like grep, warn the user to install it and bail out cleanly
  1779. if ! command -v grep > /dev/null 2>&1; then
  1780. echo >&2
  1781. echo >&2 "ERROR: 'grep' is required for the install to run correctly and was not found on the system."
  1782. echo >&2 "Please install grep and run the installer again."
  1783. echo >&2
  1784. exit 1
  1785. fi
  1786. if [ -z "${package_installer}" ] || [ -z "${tree}" ]; then
  1787. if [ -z "${distribution}" ]; then
  1788. # we dont know the distribution
  1789. autodetect_distribution || user_picks_distribution
  1790. fi
  1791. # When no package installer is detected, try again from distro info if any
  1792. if [ -z "${package_installer}" ]; then
  1793. detect_package_manager_from_distribution "${distribution}"
  1794. fi
  1795. # Validate package manager trees
  1796. validate_package_trees
  1797. fi
  1798. [ "${detection}" = "/etc/os-release" ] && cat << EOF
  1799. /etc/os-release information:
  1800. NAME : ${NAME}
  1801. VERSION : ${VERSION}
  1802. ID : ${ID}
  1803. ID_LIKE : ${ID_LIKE}
  1804. VERSION_ID : ${VERSION_ID}
  1805. EOF
  1806. cat << EOF
  1807. We detected these:
  1808. Distribution : ${distribution}
  1809. Version : ${version}
  1810. Codename : ${codename}
  1811. Package Manager : ${package_installer}
  1812. Packages Tree : ${tree}
  1813. Detection Method: ${detection}
  1814. Default Python v: ${pv} $([ ${pv} -eq 2 ] && [ "${PACKAGES_NETDATA_PYTHON3}" -eq 1 ] && echo "(will install python3 too)")
  1815. EOF
  1816. mapfile -t PACKAGES_TO_INSTALL < <(packages | sort -u)
  1817. if [ ${#PACKAGES_TO_INSTALL[@]} -gt 0 ]; then
  1818. echo >&2
  1819. echo >&2 "The following command will be run:"
  1820. echo >&2
  1821. DRYRUN=1
  1822. "${package_installer}" "${PACKAGES_TO_INSTALL[@]}"
  1823. DRYRUN=0
  1824. echo >&2
  1825. echo >&2
  1826. if [ "${DONT_WAIT}" -eq 0 ] && [ "${NON_INTERACTIVE}" -eq 0 ]; then
  1827. read -r -p "Press ENTER to run it > " || exit 1
  1828. fi
  1829. "${package_installer}" "${PACKAGES_TO_INSTALL[@]}" || install_failed $?
  1830. echo >&2
  1831. echo >&2 "All Done! - Now proceed to the next step."
  1832. echo >&2
  1833. else
  1834. echo >&2
  1835. echo >&2 "All required packages are already installed. Now proceed to the next step."
  1836. echo >&2
  1837. fi
  1838. remote_log "OK"
  1839. exit 0