diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2019-02-28 21:16:49 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2019-02-28 21:16:49 +0000 |
commit | c7191c291b318c93b4db058b7ff820cb7dc44cc7 (patch) | |
tree | 8caa842f47708dac599794745b87212e4d71df7b /packaging/installer/netdata-updater.sh | |
parent | Releasing debian version 1.12.1-2. (diff) | |
download | netdata-c7191c291b318c93b4db058b7ff820cb7dc44cc7.tar.xz netdata-c7191c291b318c93b4db058b7ff820cb7dc44cc7.zip |
Merging upstream version 1.12.2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'packaging/installer/netdata-updater.sh')
-rw-r--r-- | packaging/installer/netdata-updater.sh | 47 |
1 files changed, 31 insertions, 16 deletions
diff --git a/packaging/installer/netdata-updater.sh b/packaging/installer/netdata-updater.sh index 7846ce8b..2dce5efc 100644 --- a/packaging/installer/netdata-updater.sh +++ b/packaging/installer/netdata-updater.sh @@ -21,7 +21,7 @@ error() { } # this is what we will do if it fails (head-less only) -failed() { +fatal() { error "FAILED TO UPDATE NETDATA : ${1}" if [ -n "${logfile}" ]; then @@ -31,30 +31,47 @@ failed() { exit 1 } +create_tmp_directory() { + # Check if tmp is mounted as noexec + if grep -Eq '^[^ ]+ /tmp [^ ]+ ([^ ]*,)?noexec[, ]' /proc/mounts; then + pattern="$(pwd)/netdata-updater-XXXXXX" + else + pattern="/tmp/netdata-updater-XXXXXX" + fi + + mktemp -d "$pattern" +} + download() { url="${1}" dest="${2}" if command -v curl >/dev/null 2>&1; then - curl -L --connect-timeout 5 --retry 3 "${url}" >"${dest}" || fatal "Cannot download ${url}" + curl -sSL --connect-timeout 10 --retry 3 "${url}" >"${dest}" || fatal "Cannot download ${url}" elif command -v wget >/dev/null 2>&1; then wget -T 15 -O - "${url}" >"${dest}" || fatal "Cannot download ${url}" else - failed "I need curl or wget to proceed, but neither is available on this system." + fatal "I need curl or wget to proceed, but neither is available on this system." fi } -update() { - [ -z "${logfile}" ] && info "Running on a terminal - (this script also supports running headless from crontab)" - - # Check if tmp is mounted as noexec - if grep -Eq '^[^ ]+ /tmp [^ ]+ ([^ ]*,)?noexec[, ]' /proc/mounts; then - pattern="$(pwd)/netdata-updater-XXXXXX" +set_tarball_urls() { + if [ "$1" == "stable" ]; then + local latest + # Simple version + # latest="$(curl -sSL https://api.github.com/repos/netdata/netdata/releases/latest | grep tag_name | cut -d'"' -f4)" + latest="$(download "https://api.github.com/repos/netdata/netdata/releases/latest" /dev/stdout | grep tag_name | cut -d'"' -f4)" + export NETDATA_TARBALL_URL="https://github.com/netdata/netdata/releases/download/$latest/netdata-$latest.tar.gz" + export NETDATA_TARBALL_CHECKSUM_URL="https://github.com/netdata/netdata/releases/download/$latest/sha256sums.txt" else - pattern="/tmp/netdata-updater-XXXXXX" + export NETDATA_TARBALL_URL="https://storage.googleapis.com/netdata-nightlies/netdata-latest.tar.gz" + export NETDATA_TARBALL_CHECKSUM_URL="https://storage.googleapis.com/netdata-nightlies/sha256sums.txt" fi +} - dir=$(mktemp -d "$pattern") +update() { + [ -z "${logfile}" ] && info "Running on a terminal - (this script also supports running headless from crontab)" + dir=$(create_tmp_directory) cd "$dir" download "${NETDATA_TARBALL_CHECKSUM_URL}" "${dir}/sha256sum.txt" >&3 2>&3 @@ -85,11 +102,9 @@ update() { fi info "Re-installing netdata..." - eval "${REINSTALL_COMMAND} --dont-wait ${do_not_start}" >&3 2>&3 || failed "FAILED TO COMPILE/INSTALL NETDATA" + eval "${REINSTALL_COMMAND} --dont-wait ${do_not_start}" >&3 2>&3 || fatal "FAILED TO COMPILE/INSTALL NETDATA" sed -i '/NETDATA_TARBALL/d' "${ENVIRONMENT_FILE}" cat <<EOF >>"${ENVIRONMENT_FILE}" -NETDATA_TARBALL_URL="$NETDATA_TARBALL_URL" -NETDATA_TARBALL_CHECKSUM_URL="$NETDATA_TARBALL_CHECKSUM_URL" NETDATA_TARBALL_CHECKSUM="$NEW_CHECKSUM" EOF @@ -105,8 +120,7 @@ EOF source "${ENVIRONMENT_FILE}" || exit 1 if [ "${INSTALL_UID}" != "$(id -u)" ]; then - echo >&2 "You are running this script as user with uid $(id -u). We recommend to run this script as root (user with uid 0)" - exit 1 + fatal "You are running this script as user with uid $(id -u). We recommend to run this script as root (user with uid 0)" fi logfile= @@ -122,6 +136,7 @@ else exec 3>"${logfile}" fi +set_tarball_urls "${RELEASE_CHANNEL}" # the installer updates this script - so we run and exit in a single line update && exit 0 |