install-required-packages.sh 56 KB

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