install-required-packages.sh 61 KB

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