install-required-packages.sh 55 KB

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