install-required-packages.sh 56 KB

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