install-required-packages.sh 56 KB

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