install-required-packages.sh 59 KB

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