install-required-packages.sh 55 KB

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