Просмотр исходного кода

fix(install): parse the release tag by name instead of field position (#578)

The installers resolved the latest release with
  grep '"tag_name"' | head -1 | cut -d'"' -f4
which is positional. When GitHub returns the payload minified on a single
line the 4th quoted field is the release URL, not the tag, so the version
resolved to https://api.github.com/repos/.../releases/<id> and the
download path became invalid (install.sh, install-agent.sh and
install-collector.sh). Extract the tag_name value by name with
grep -oE. Also add a version echo so the running install.sh can be told
apart.

Co-authored-by: gnacho <hnacho@proton.me>
Nacho 2 месяцев назад
Родитель
Сommit
2913a741ed
3 измененных файлов с 9 добавлено и 4 удалено
  1. 2 2
      install-agent.sh
  2. 1 1
      install-collector.sh
  3. 6 1
      install.sh

+ 2 - 2
install-agent.sh

@@ -171,7 +171,7 @@ HANDOFF
         elif command -v wget >/dev/null 2>&1; then FETCH="wget -q -O-"
         else fatal 21 "necesito curl o wget"; fi
         NG_TAG=$($FETCH "https://api.github.com/repos/gnacho/netgrip/releases/latest" \
-            | grep '"tag_name"' | head -1 | cut -d'"' -f4) || fatal 41 "no pude resolver la última release de NetGrip"
+            | grep -oE '"tag_name"[[:space:]]*:[[:space:]]*"[^"]*"' | head -1 | cut -d'"' -f4) || fatal 41 "no pude resolver la última release de NetGrip"
         NG_VER=$(echo "$NG_TAG" | sed 's/^v//')
         ARCH=$(ssh $SSH_IDENT_ARGS "$SSH" uname -m)
         case "$ARCH" in
@@ -249,7 +249,7 @@ else
     if [ -z "$NETPULSE_VERSION" ]; then
         info "resolviendo última release"
         NETPULSE_VERSION=$($FETCH "https://api.github.com/repos/$GH_REPO/releases/latest" \
-            | grep '"tag_name"' | head -1 | cut -d'"' -f4) \
+            | grep -oE '"tag_name"[[:space:]]*:[[:space:]]*"[^"]*"' | head -1 | cut -d'"' -f4) \
             || fatal 31 "no pude resolver la última release; usa --version=X.Y.Z"
     fi
     VERSION_NORM=$(echo "$NETPULSE_VERSION" | sed 's/^v//')

+ 1 - 1
install-collector.sh

@@ -200,7 +200,7 @@ fi
 if [ -z "$NETPULSE_VERSION" ]; then
     info "resolving latest stable version"
     NETPULSE_VERSION=$($FETCH "https://api.github.com/repos/$GH_REPO/releases/latest" \
-        | grep '"tag_name"' | head -1 | cut -d'"' -f4) \
+        | grep -oE '"tag_name"[[:space:]]*:[[:space:]]*"[^"]*"' | head -1 | cut -d'"' -f4) \
         || fatal 31 "could not resolve the latest version. Use --version=X.Y.Z"
     [ -n "$NETPULSE_VERSION" ] || fatal 31 "no stable release found yet. Use --version=X.Y.Z"
 fi

+ 6 - 1
install.sh

@@ -30,6 +30,10 @@ INSTALL_DIR="/usr/local/bin"
 STATE_DIR="/var/lib/$APP_NAME"
 SERVICE_NAME="$APP_NAME"
 
+# Versión de ESTE instalador (bumpear en cada release junto a httpapi.Version,
+# para poder saber qué install.sh se está ejecutando; ver CHANGELOG).
+INSTALLER_VERSION="2.28.5"
+
 NETPULSE_VERSION=""; UNATTENDED=0; DRY_RUN=0; UNINSTALL=0; PURGE=0; DEMO=0
 
 # ---------------------------------------------------------------- logging ---
@@ -169,6 +173,7 @@ if [ ! -d /run/systemd/system ] || ! command -v systemctl >/dev/null 2>&1; then
     fatal 23 "NetPulse needs systemd (this machine doesn't run it). See https://github.com/$GH_REPO for manual setup"
 fi
 info "detected: $OS_PRETTY · linux/$GOARCH · systemd"
+info "install.sh version: $INSTALLER_VERSION"
 
 if command -v curl >/dev/null 2>&1; then FETCH="curl -fsSL --retry 3 --connect-timeout 10"
 elif command -v wget >/dev/null 2>&1; then FETCH="wget -q -O-"
@@ -256,7 +261,7 @@ fi
 if [ -z "$NETPULSE_VERSION" ]; then
     info "resolving latest stable version"
     NETPULSE_VERSION=$($FETCH "https://api.github.com/repos/$GH_REPO/releases/latest" \
-        | grep '"tag_name"' | head -1 | cut -d'"' -f4) \
+        | grep -oE '"tag_name"[[:space:]]*:[[:space:]]*"[^"]*"' | head -1 | cut -d'"' -f4) \
         || fatal 31 "could not resolve the latest version (GitHub rate-limit?). Use --version=X.Y.Z"
     [ -n "$NETPULSE_VERSION" ] || fatal 31 "no stable release found yet. Use --version=X.Y.Z"
 fi