@cryptotaxi247 / netdata-1 / commits / b333c6ffd

Use curl from static builds if no system-wide copy exists. (#14403)

Instead of immediately falling back to wget, try using curl from a static build if it is installed. This provides better behavior in a number of cases and also makes the static builds more self-contained (and makes the static builds a bit more self-contained).

Austin S. Hemmelgarn committed Feb 15, 2023 at 07:20 UTC b333c6ffdee2ff9f9ee835e36dbe99e83605e8da
3 files changed +44 -18
packaging/installer/functions.sh
+19 -6
@@ -95,10 +95,19 @@ progress() {
95 echo >&2 " --- ${TPUT_DIM}${TPUT_BOLD}${*}${TPUT_RESET} --- "
96 }
97
98 +check_for_curl() {
99 + if [ -z "${curl}" ]; then
100 + curl="$(PATH="${PATH}:/opt/netdata/bin" command -v curl 2>/dev/null && true)"
101 + fi
102 +}
103 +
104 get() {
105 url="${1}"
100 - if command -v curl > /dev/null 2>&1; then
101 - curl -q -o - -sSL --connect-timeout 10 --retry 3 "${url}"
106 +
107 + check_for_curl
108 +
109 + if [ -n "${curl}" ]; then
110 + "${curl}" -q -o - -sSL --connect-timeout 10 --retry 3 "${url}"
111 elif command -v wget > /dev/null 2>&1; then
112 wget -T 15 -O - "${url}"
113 else
@@ -112,8 +121,10 @@ download_file() {
121 name="${3}"
122 opt="${4}"
123
115 - if command -v curl > /dev/null 2>&1; then
116 - run curl -q -sSL --connect-timeout 10 --retry 3 --output "${dest}" "${url}"
124 + check_for_curl
125 +
126 + if [ -n "${curl}" ]; then
127 + run "${curl}" -q -sSL --connect-timeout 10 --retry 3 --output "${dest}" "${url}"
128 elif command -v wget > /dev/null 2>&1; then
129 run wget -T 15 -O "${dest}" "${url}"
130 else
@@ -873,8 +884,10 @@ create_netdata_conf() {
884 export http_proxy=
885 export https_proxy=
886
876 - if command -v curl 1> /dev/null 2>&1; then
877 - run curl -sSL --connect-timeout 10 --retry 3 "${url}" > "${path}.new"
887 + check_for_curl
888 +
889 + if [ -n "${curl}" ]; then
890 + run "${curl}" -sSL --connect-timeout 10 --retry 3 "${url}" > "${path}.new"
891 elif command -v wget 1> /dev/null 2>&1; then
892 run wget -T 15 -O - "${url}" > "${path}.new"
893 fi
packaging/installer/kickstart.sh
+10 -8
@@ -78,6 +78,8 @@ else
78 INTERACTIVE=1
79 fi
80
81 +CURL="$(PATH="${PATH}:/opt/netdata/bin" command -v curl 2>/dev/null && true)"
82 +
83 # ======================================================================
84 # Shared messages used in multiple places throughout the script.
85
@@ -299,8 +301,8 @@ telemetry_event() {
301 EOF
302 )"
303
302 - if command -v curl > /dev/null 2>&1; then
303 - curl --silent -o /dev/null -X POST --max-time 2 --header "Content-Type: application/json" -d "${REQ_BODY}" "${TELEMETRY_URL}" > /dev/null
304 + if [ -n "${CURL}" ]; then
305 + "${CURL}" --silent -o /dev/null -X POST --max-time 2 --header "Content-Type: application/json" -d "${REQ_BODY}" "${TELEMETRY_URL}" > /dev/null
306 elif command -v wget > /dev/null 2>&1; then
307 if wget --help 2>&1 | grep BusyBox > /dev/null 2>&1; then
308 # BusyBox-compatible version of wget, there is no --no-check-certificate option
@@ -581,8 +583,8 @@ check_for_remote_file() {
583
584 if echo "${url}" | grep -Eq "^file:///"; then
585 [ -e "${url#file://}" ] || return 1
584 - elif command -v curl > /dev/null 2>&1; then
585 - curl --output /dev/null --silent --head --fail "${url}" || return 1
586 + elif [ -n "${CURL}" ]; then
587 + "${CURL}" --output /dev/null --silent --head --fail "${url}" || return 1
588 elif command -v wget > /dev/null 2>&1; then
589 wget -S --spider "${url}" 2>&1 | grep -q 'HTTP/1.1 200 OK' || return 1
590 else
@@ -596,8 +598,8 @@ download() {
598
599 if echo "${url}" | grep -Eq "^file:///"; then
600 run cp "${url#file://}" "${dest}" || return 1
599 - elif command -v curl > /dev/null 2>&1; then
600 - run curl --fail -q -sSL --connect-timeout 10 --retry 3 --output "${dest}" "${url}" || return 1
601 + elif [ -n "${CURL}" ]; then
602 + run "${CURL}" --fail -q -sSL --connect-timeout 10 --retry 3 --output "${dest}" "${url}" || return 1
603 elif command -v wget > /dev/null 2>&1; then
604 run wget -T 15 -O "${dest}" "${url}" || return 1
605 else
@@ -608,8 +610,8 @@ download() {
610 get_redirect() {
611 url="${1}"
612
611 - if command -v curl > /dev/null 2>&1; then
612 - run sh -c "curl ${url} -s -L -I -o /dev/null -w '%{url_effective}' | grep -o '[^/]*$'" || return 1
613 + if [ -n "${CURL}" ]; then
614 + run sh -c "${CURL} ${url} -s -L -I -o /dev/null -w '%{url_effective}' | grep -o '[^/]*$'" || return 1
615 elif command -v wget > /dev/null 2>&1; then
616 run sh -c "wget -S -O /dev/null ${url} 2>&1 | grep -m 1 Location | grep -o '[^/]*$'" || return 1
617 else
packaging/installer/netdata-updater.sh
+15 -4
@@ -341,11 +341,20 @@ create_tmp_directory() {
341 fi
342 }
343
344 +check_for_curl() {
345 + if [ -z "${curl}" ]; then
346 + curl="$(PATH="${PATH}:/opt/netdata/bin" command -v curl 2>/dev/null && true)"
347 + fi
348 +}
349 +
350 _safe_download() {
351 url="${1}"
352 dest="${2}"
347 - if command -v curl > /dev/null 2>&1; then
348 - curl -sSL --connect-timeout 10 --retry 3 "${url}" > "${dest}"
353 +
354 + check_for_curl
355 +
356 + if [ -n "${curl}" ]; then
357 + "${curl}" -sSL --connect-timeout 10 --retry 3 "${url}" > "${dest}"
358 return $?
359 elif command -v wget > /dev/null 2>&1; then
360 wget -T 15 -O - "${url}" > "${dest}"
@@ -375,8 +384,10 @@ get_netdata_latest_tag() {
384 url="${1}/latest"
385 dest="${2}"
386
378 - if command -v curl >/dev/null 2>&1; then
379 - tag=$(curl "${url}" -s -L -I -o /dev/null -w '%{url_effective}' | grep -m 1 -o '[^/]*$')
387 + check_for_curl
388 +
389 + if [ -n "${curl}" ]; then
390 + tag=$("${curl}" "${url}" -s -L -I -o /dev/null -w '%{url_effective}' | grep -m 1 -o '[^/]*$')
391 elif command -v wget >/dev/null 2>&1; then
392 tag=$(wget -S -O /dev/null "${url}" 2>&1 | grep -m 1 Location | grep -o '[^/]*$')
393 else