install-required-packages.sh 58 KB

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