install-required-packages.sh 56 KB

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