install-required-packages.sh 61 KB

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