|
|
@@ -1,50 +1,49 @@
|
|
|
#!/bin/sh
|
|
|
# =============================================================================
|
|
|
-# NetPulse Agent — one-liner installer (OpenWrt, vía SSH desde esta máquina)
|
|
|
+# NetPulse Agent - one-liner installer (OpenWrt, over SSH from this machine)
|
|
|
#
|
|
|
-# Instala el agente nativo netpulse-agent en un router/AP OpenWrt: copia el
|
|
|
-# binario (arm64/armv7/mipsle/mips), escribe /etc/netpulse-agent.env (chmod
|
|
|
-# 600) e instala el servicio procd (respawn) habilitado y arrancado. Añade
|
|
|
-# binario, init y env a /etc/sysupgrade.conf para que sobrevivan a una
|
|
|
-# actualización de firmware (#1476).
|
|
|
+# Installs the native netpulse-agent on an OpenWrt router/AP: copies the
|
|
|
+# binary (arm64/armv7/mipsle/mips), writes /etc/netpulse-agent.env (chmod
|
|
|
+# 600) and installs the procd service (respawn), enabled and started. Adds
|
|
|
+# the binary, the init script and the env file to /etc/sysupgrade.conf so
|
|
|
+# they survive a firmware upgrade (#1476).
|
|
|
#
|
|
|
-# Uso (el token lo genera POST /api/agents y se muestra UNA sola vez):
|
|
|
+# Usage (the token is generated by POST /api/agents and shown ONCE):
|
|
|
# sh install-agent.sh --host 192.168.8.3 \
|
|
|
# --server http://192.168.8.1:3000 --slug patio --token <64-hex>
|
|
|
# sh install-agent.sh --host 192.168.8.3 --server ... --slug ... --token ... \
|
|
|
-# --binary ./netpulse-agent # binario local (sin descarga)
|
|
|
+# --binary ./netpulse-agent # local binary (no download)
|
|
|
# sh install-agent.sh --host 192.168.8.3 --uninstall
|
|
|
#
|
|
|
-# Opciones:
|
|
|
-# --host X IP/host del router (obligatorio)
|
|
|
-# --server X URL del servidor NetPulse (obligatoria salvo --uninstall)
|
|
|
-# --slug X slug del equipo en NetPulse (obligatorio salvo --uninstall)
|
|
|
-# --token X token del equipo (obligatorio salvo --uninstall y --pairing-token)
|
|
|
-# --pairing-token X token de pairing (bootstrap: el agente contacta al servidor
|
|
|
-# y obtiene el token real automáticamente; Fase 9 R3)
|
|
|
-# --server-fp X SHA-256 SPKI del servidor en hex (https). Opcional: si no
|
|
|
-# se pasa, el script lo deriva del propio certificado (#851)
|
|
|
-# --ca-file X PEM de la CA del server (https con CA propia): se usa como
|
|
|
-# --cacert en la descarga del binario desde el server (#1367)
|
|
|
-# --ssh-user X usuario SSH del router (default: root)
|
|
|
-# --ssh-key X ruta a la identidad privada SSH (opción -i). OBLIGATORIA en
|
|
|
-# el server para routers que solo autorizan la llave del
|
|
|
-# NetPulse (la que muestra Settings); se pasa a ssh/scp.
|
|
|
-# --binary X binario local a copiar (default: descarga de la release)
|
|
|
-# --version X.Y.Z versión a descargar (default: latest)
|
|
|
-# --tmp instala el binario en /tmp (RAM) en vez de /usr/sbin:
|
|
|
-# para equipos con flash justa. OJO: /tmp se pierde al
|
|
|
-# reiniciar — tras un reboot hay que reejecutar este script
|
|
|
-# (variante documentada del SPEC; el .ipk llega en el incr. 2)
|
|
|
-# --uninstall detiene y elimina servicio, binario y config del router
|
|
|
-# --update-netgrip si se detecta NetGrip en el router: actualizar el panel
|
|
|
-# NetGrip a su última release (apk/ipk de GitHub) en vez de
|
|
|
-# limitarse a entregarle la config (--force permite bajar de
|
|
|
-# versión)
|
|
|
+# Options:
|
|
|
+# --host X router IP/host (required)
|
|
|
+# --server X NetPulse server URL (required unless --uninstall)
|
|
|
+# --slug X unit slug in NetPulse (required unless --uninstall)
|
|
|
+# --token X unit token (required unless --uninstall and --pairing-token)
|
|
|
+# --pairing-token X pairing token (bootstrap: the agent contacts the server
|
|
|
+# and gets the real token by itself, phase 9 R3)
|
|
|
+# --server-fp X server SPKI SHA-256 in hex (https). Optional: without it
|
|
|
+# the script derives it from the certificate (#851)
|
|
|
+# --ca-file X PEM of the server CA (https with a private CA): used as
|
|
|
+# --cacert when downloading the binary from the server (#1367)
|
|
|
+# --ssh-user X router SSH user (default: root)
|
|
|
+# --ssh-key X path to the SSH private identity (-i). REQUIRED on the
|
|
|
+# server for routers that only authorize the NetPulse key
|
|
|
+# (the one Settings shows), it is passed to ssh/scp.
|
|
|
+# --binary X local binary to copy (default: download the release)
|
|
|
+# --version X.Y.Z version to download (default: latest)
|
|
|
+# --tmp installs the binary in /tmp (RAM) instead of /usr/sbin,
|
|
|
+# for units with little flash. NOTE: /tmp is lost on reboot,
|
|
|
+# so the script has to run again after one (documented
|
|
|
+# variant of the SPEC, the .ipk lands in increment 2)
|
|
|
+# --uninstall stops and removes the service, binary and config
|
|
|
+# --update-netgrip if NetGrip is found on the router, update the NetGrip
|
|
|
+# panel to its latest release (apk/ipk from GitHub) instead
|
|
|
+# of only handing over the config (--force allows downgrades)
|
|
|
#
|
|
|
-# Nota: todas las opciones admiten `--opt value` y `--opt=value` (#571).
|
|
|
+# Note: every option accepts `--opt value` and `--opt=value` (#571).
|
|
|
#
|
|
|
-# Requisitos: ssh/scp al router (OpenWrt con dropbear), curl o wget local.
|
|
|
+# Requirements: ssh/scp to the router (OpenWrt with dropbear), curl or wget.
|
|
|
# =============================================================================
|
|
|
set -eu
|
|
|
|
|
|
@@ -64,7 +63,7 @@ ok() { printf '%s✓%s %s\n' "$C_G" "$C_0" "$*"; }
|
|
|
warn() { printf '%s!%s %s\n' "$C_Y" "$C_0" "$*" >&2; }
|
|
|
fatal() { _c=$1; shift; printf '%s✗ %s%s\n' "$C_R" "$*" "$C_0" >&2; exit "$_c"; }
|
|
|
|
|
|
-usage() { sed -n '2,/^# Requisitos/p' "$0" | sed '$d'; exit 0; }
|
|
|
+usage() { sed -n '2,/^# Requirements/p' "$0" | sed '$d'; exit 0; }
|
|
|
|
|
|
# #571: acepta tanto `--opt value` como `--opt=value` (el copy-command de la app
|
|
|
# y la cabecera de ayuda usan la forma con espacio).
|
|
|
@@ -97,22 +96,22 @@ while [ "$#" -gt 0 ]; do
|
|
|
--update-netgrip) UPDATE_NETGRIP=1; shift ;;
|
|
|
--force) NETGRIP_FORCE=1; shift ;;
|
|
|
-h|--help) usage ;;
|
|
|
- *) fatal 10 "opción desconocida: $1 (prueba --help)" ;;
|
|
|
+ *) fatal 10 "unknown option: $1 (try --help)" ;;
|
|
|
esac
|
|
|
done
|
|
|
|
|
|
-[ -n "$HOST" ] || fatal 11 "falta --host (IP del router)"
|
|
|
+[ -n "$HOST" ] || fatal 11 "missing --host (router IP)"
|
|
|
SSH="$SSH_USER@$HOST"
|
|
|
# #572: identidad SSH explícita (p. ej. la llave de routers del server). Si no
|
|
|
# se pasa, el cliente usa la default (~/.ssh/id_*) como antes.
|
|
|
SSH_IDENT_ARGS=""
|
|
|
if [ -n "$SSH_KEY" ]; then SSH_IDENT_ARGS="-i $SSH_KEY"; fi
|
|
|
-command -v ssh >/dev/null 2>&1 || fatal 12 "necesito ssh"
|
|
|
-command -v scp >/dev/null 2>&1 || fatal 12 "necesito scp"
|
|
|
+command -v ssh >/dev/null 2>&1 || fatal 12 "ssh is required"
|
|
|
+command -v scp >/dev/null 2>&1 || fatal 12 "scp is required"
|
|
|
|
|
|
# --------------------------------------------------------------- uninstall --
|
|
|
if [ "$UNINSTALL" -eq 1 ]; then
|
|
|
- info "desinstalando $BIN_NAME de $SSH"
|
|
|
+ info "uninstalling $BIN_NAME from $SSH"
|
|
|
ssh $SSH_IDENT_ARGS "$SSH" "
|
|
|
$INIT_DST stop 2>/dev/null || true
|
|
|
$INIT_DST disable 2>/dev/null || true
|
|
|
@@ -129,15 +128,15 @@ if [ "$UNINSTALL" -eq 1 ]; then
|
|
|
mv /tmp/np-sysupgrade.conf /etc/sysupgrade.conf
|
|
|
fi
|
|
|
"
|
|
|
- ok "$BIN_NAME desinstalado de $HOST"
|
|
|
+ ok "$BIN_NAME uninstalled from $HOST"
|
|
|
exit 0
|
|
|
fi
|
|
|
|
|
|
-[ -n "$SERVER" ] || fatal 11 "falta --server (URL de NetPulse)"
|
|
|
-[ -n "$SLUG" ] || fatal 11 "falta --slug"
|
|
|
+[ -n "$SERVER" ] || fatal 11 "missing --server (NetPulse URL)"
|
|
|
+[ -n "$SLUG" ] || fatal 11 "missing --slug"
|
|
|
# Token: obligatorio --token o --pairing-token (no ambos)
|
|
|
if [ -z "$TOKEN" ] && [ -z "$PAIRING_TOKEN" ]; then
|
|
|
- fatal 11 "falta --token (o --pairing-token para bootstrap)"
|
|
|
+ fatal 11 "missing --token (or --pairing-token for bootstrap)"
|
|
|
fi
|
|
|
SERVER="${SERVER%/}"
|
|
|
|
|
|
@@ -154,7 +153,7 @@ case "$SERVER" in
|
|
|
HOSTPORT=${HOSTPORT%%/*}
|
|
|
SNI=${HOSTPORT%%:*}
|
|
|
case "$HOSTPORT" in *:*) : ;; *) HOSTPORT="$HOSTPORT:443" ;; esac
|
|
|
- info "derivando NETPULSE_SERVER_FP del certificado de $SERVER"
|
|
|
+ info "deriving NETPULSE_SERVER_FP from the certificate of $SERVER"
|
|
|
if command -v openssl >/dev/null 2>&1; then
|
|
|
SERVER_FP=$(echo | openssl s_client -connect "$HOSTPORT" -servername "$SNI" 2>/dev/null \
|
|
|
| openssl x509 -pubkey -noout 2>/dev/null \
|
|
|
@@ -162,7 +161,7 @@ case "$SERVER" in
|
|
|
| { command -v sha256sum >/dev/null 2>&1 && sha256sum || shasum -a 256; } \
|
|
|
| cut -d' ' -f1)
|
|
|
fi
|
|
|
- [ -n "$SERVER_FP" ] || fatal 14 "servidor HTTPS sin --server-fp y no pude derivarlo (¿openssl disponible? ¿SNI correcto?). Obtén el SPKI sha256 del cert y repite con --server-fp X"
|
|
|
+ [ -n "$SERVER_FP" ] || fatal 14 "HTTPS server without --server-fp and could not derive it (is openssl available? is the SNI right?). Get the sha256 SPKI of the certificate and retry with --server-fp X"
|
|
|
ok "NETPULSE_SERVER_FP=$SERVER_FP"
|
|
|
fi
|
|
|
;;
|
|
|
@@ -175,7 +174,7 @@ esac
|
|
|
# pública en el router (dropbear: /etc/dropbear/authorized_keys).
|
|
|
ssh $SSH_IDENT_ARGS -o ConnectTimeout=8 -o BatchMode=yes "$SSH" true || {
|
|
|
PUB="${SSH_KEY:-~/.ssh/id_ed25519.pub}"
|
|
|
- fatal 13 "sin SSH por clave a $SSH (el instalador es no interactivo: la contraseña no vale). Autoriza la clave pública en el router y repite: ssh-copy-id -i $PUB $SSH"
|
|
|
+ fatal 13 "no key-based SSH to $SSH (the installer is not interactive, a password is no use). Authorize the public key on the router and retry: ssh-copy-id -i $PUB $SSH"
|
|
|
}
|
|
|
|
|
|
# Preflight del canal (#1654): el router tiene que alcanzar el MISMO $SERVER
|
|
|
@@ -184,9 +183,9 @@ ssh $SSH_IDENT_ARGS -o ConnectTimeout=8 -o BatchMode=yes "$SSH" true || {
|
|
|
# al final, con el agente ya instalado y sin poder conectar. Se comprueba sin
|
|
|
# validar el certificado a propósito: de la identidad del servidor se encarga
|
|
|
# el pinning SPKI (NETPULSE_SERVER_FP).
|
|
|
-info "comprobando que $HOST alcanza $SERVER"
|
|
|
+info "checking that $HOST reaches $SERVER"
|
|
|
ssh $SSH_IDENT_ARGS "$SSH" "if command -v curl >/dev/null 2>&1; then curl -fsSk --connect-timeout 5 -m 10 -o /dev/null '$SERVER/api/health'; elif command -v wget >/dev/null 2>&1; then wget -q --no-check-certificate -T 10 -O /dev/null '$SERVER/api/health'; else exit 3; fi" || {
|
|
|
- fatal 15 "el router no alcanza $SERVER/api/health. Comprueba que ese host y puerto son accesibles desde la red del router. Si el servidor tiene TLS activado la URL es https, y el router debe llegar a ese puerto. Para usar otra URL en los agentes, define NETPULSE_AGENT_URL en el servidor (por ejemplo la de la LAN)"
|
|
|
+ fatal 15 "the router cannot reach $SERVER/api/health. Check that the host and the port are reachable from the router network. With TLS on the server the URL is https and the router must reach that port. To use another URL in the agents, set NETPULSE_AGENT_URL on the server (the LAN one, for instance)"
|
|
|
}
|
|
|
|
|
|
# ----------------------------------------------------- netgrip handoff --
|
|
|
@@ -194,7 +193,7 @@ ssh $SSH_IDENT_ARGS "$SSH" "if command -v curl >/dev/null 2>&1; then curl -fsSk
|
|
|
# instala el standalone. Se le entrega la config (sin pisar la existente) y
|
|
|
# opcionalmente se actualiza el propio NetGrip (--update-netgrip).
|
|
|
if ssh $SSH_IDENT_ARGS "$SSH" '[ -x /usr/sbin/netgrip ] || [ -f /etc/init.d/netgrip ]'; then
|
|
|
- info "NetGrip detectado en $HOST: el agente embebido ya cubre este router"
|
|
|
+ info "NetGrip found on $HOST, its embedded agent already covers this router"
|
|
|
# Token line igual que el flujo normal
|
|
|
if [ -n "$PAIRING_TOKEN" ]; then
|
|
|
HANDOFF_TOKEN="NETPULSE_PAIRING_TOKEN=$PAIRING_TOKEN"
|
|
|
@@ -216,9 +215,9 @@ if [ ! -f "\$NG_ENV" ]; then
|
|
|
echo "NETPULSE_ENABLED=1"
|
|
|
} > "\$NG_ENV"
|
|
|
chmod 600 "\$NG_ENV"
|
|
|
- echo "config-escrita"
|
|
|
+ echo "config-written"
|
|
|
else
|
|
|
- echo "config-existente-conservada"
|
|
|
+ echo "existing-config-kept"
|
|
|
fi
|
|
|
HANDOFF
|
|
|
|
|
|
@@ -227,14 +226,14 @@ HANDOFF
|
|
|
CUR=$(ssh $SSH_IDENT_ARGS "$SSH" "(apk info netgrip 2>/dev/null || opkg status netgrip 2>/dev/null | sed -n 's/^Version: //p') | head -1")
|
|
|
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-"
|
|
|
- else fatal 21 "necesito curl o wget"; fi
|
|
|
+ else fatal 21 "curl or wget is required"; fi
|
|
|
NG_TAG=$($FETCH "https://api.github.com/repos/gnacho/netgrip/releases/latest" \
|
|
|
- | grep -oE '"tag_name"[[:space:]]*:[[:space:]]*"[^"]*"' | 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 "could not resolve the latest NetGrip release"
|
|
|
NG_VER=$(echo "$NG_TAG" | sed 's/^v//')
|
|
|
ARCH=$(ssh $SSH_IDENT_ARGS "$SSH" uname -m)
|
|
|
case "$ARCH" in
|
|
|
aarch64|arm64) NG_ARCH=arm64 ;;
|
|
|
- *) fatal 20 "NetGrip solo publica builds arm64 (router: $ARCH)" ;;
|
|
|
+ *) fatal 20 "NetGrip only publishes arm64 builds (router: $ARCH)" ;;
|
|
|
esac
|
|
|
if ssh $SSH_IDENT_ARGS "$SSH" command -v apk >/dev/null 2>&1; then
|
|
|
NG_ASSET="netgrip-${NG_VER}-r1-${NG_ARCH}.apk"; NG_INST="apk add --allow-untrusted /tmp/netgrip-update.pkg"
|
|
|
@@ -242,30 +241,30 @@ HANDOFF
|
|
|
NG_ASSET="netgrip_${NG_VER}-1_aarch64_cortex-a53.ipk"; NG_INST="opkg install /tmp/netgrip-update.pkg"
|
|
|
fi
|
|
|
NG_URL="https://github.com/gnacho/netgrip/releases/download/${NG_TAG}/${NG_ASSET}"
|
|
|
- info "actualizando NetGrip a $NG_TAG (instalado: ${CUR:-desconocido})"
|
|
|
+ info "updating NetGrip to $NG_TAG (installed: ${CUR:-unknown})"
|
|
|
if [ -n "$CUR" ] && [ "$NETGRIP_FORCE" -ne 1 ]; then
|
|
|
CUR_V=$(echo "$CUR" | sed 's/^netgrip-//; s/ description:.*//; s/-r[0-9]*$//')
|
|
|
if [ "$CUR_V" = "$NG_VER" ]; then
|
|
|
- ok "NetGrip ya está en $NG_VER; nada que hacer (usa --force para reinstalar)"
|
|
|
+ ok "NetGrip is already on $NG_VER, nothing to do (use --force to reinstall)"
|
|
|
ssh $SSH_IDENT_ARGS "$SSH" "/etc/init.d/netgrip restart >/dev/null 2>&1 || true"
|
|
|
- ok "agente embebido rearmado (slug $SLUG)"
|
|
|
+ ok "embedded agent rearmed (slug $SLUG)"
|
|
|
exit 0
|
|
|
fi
|
|
|
OLDEST=$(printf '%s\n%s\n' "$CUR_V" "$NG_VER" | sort -V | head -1)
|
|
|
if [ "$OLDEST" = "$NG_VER" ]; then
|
|
|
- warn "la release $NG_TAG es MÁS VIEJA que la instalada ($CUR_V): router con build no liberada"
|
|
|
- fatal 43 "downgrade rechazado (usa --force si de verdad lo quieres)"
|
|
|
+ warn "release $NG_TAG is OLDER than the installed one ($CUR_V), the router runs an unreleased build"
|
|
|
+ fatal 43 "downgrade refused (use --force if you really want it)"
|
|
|
fi
|
|
|
fi
|
|
|
- $FETCH "$NG_URL" -o "$TMP/netgrip-update.pkg" || fatal 42 "descarga falló: $NG_URL"
|
|
|
+ $FETCH "$NG_URL" -o "$TMP/netgrip-update.pkg" || fatal 42 "download failed: $NG_URL"
|
|
|
scp -Oq $SSH_IDENT_ARGS "$TMP/netgrip-update.pkg" "$SSH:/tmp/netgrip-update.pkg"
|
|
|
ssh $SSH_IDENT_ARGS "$SSH" "$NG_INST && rm -f /tmp/netgrip-update.pkg"
|
|
|
- ok "NetGrip actualizado a $NG_TAG"
|
|
|
+ ok "NetGrip updated to $NG_TAG"
|
|
|
fi
|
|
|
|
|
|
ssh $SSH_IDENT_ARGS "$SSH" "/etc/init.d/netgrip restart >/dev/null 2>&1 || true"
|
|
|
- ok "agente embebido de NetGrip rearmado (server $SERVER, slug $SLUG)"
|
|
|
- info "el agente standalone NO se instala en routers con NetGrip"
|
|
|
+ ok "NetGrip embedded agent rearmed (server $SERVER, slug $SLUG)"
|
|
|
+ info "the standalone agent is NOT installed on routers running NetGrip"
|
|
|
exit 0
|
|
|
fi
|
|
|
|
|
|
@@ -273,16 +272,16 @@ fi
|
|
|
BIN_DST="/usr/sbin/$BIN_NAME"
|
|
|
[ "$USE_TMP" -eq 1 ] && BIN_DST="/tmp/$BIN_NAME"
|
|
|
|
|
|
-TMP=$(mktemp -d) || fatal 34 "mktemp falló"
|
|
|
+TMP=$(mktemp -d) || fatal 34 "mktemp failed"
|
|
|
cleanup() { rm -rf "$TMP"; }
|
|
|
trap cleanup EXIT INT TERM
|
|
|
|
|
|
if [ -n "$BINARY" ]; then
|
|
|
- [ -f "$BINARY" ] || fatal 30 "binario local no encontrado: $BINARY"
|
|
|
+ [ -f "$BINARY" ] || fatal 30 "local binary not found: $BINARY"
|
|
|
cp "$BINARY" "$TMP/$BIN_NAME"
|
|
|
- info "usando binario local: $BINARY"
|
|
|
+ info "using the local binary: $BINARY"
|
|
|
else
|
|
|
- ARCH=$(ssh $SSH_IDENT_ARGS "$SSH" uname -m) || fatal 31 "no pude detectar la arquitectura de $HOST"
|
|
|
+ ARCH=$(ssh $SSH_IDENT_ARGS "$SSH" uname -m) || fatal 31 "could not detect the architecture of $HOST"
|
|
|
case "$ARCH" in
|
|
|
aarch64|arm64) GOARCH=arm64 ;;
|
|
|
armv7l|armv7) GOARCH=armv7 ;;
|
|
|
@@ -295,15 +294,15 @@ else
|
|
|
case "$END" in
|
|
|
1) GOARCH=mipsle ;;
|
|
|
2) GOARCH=mips ;;
|
|
|
- *) fatal 20 "no pude detectar el endianness MIPS de $HOST" ;;
|
|
|
+ *) fatal 20 "could not detect the MIPS endianness of $HOST" ;;
|
|
|
esac ;;
|
|
|
- *) fatal 20 "arquitectura no soportada: $ARCH (release: arm64, armv7, mipsle, mips)" ;;
|
|
|
+ *) fatal 20 "unsupported architecture: $ARCH (releases: arm64, armv7, mipsle, mips)" ;;
|
|
|
esac
|
|
|
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-"
|
|
|
- else fatal 21 "necesito curl o wget"; fi
|
|
|
+ else fatal 21 "curl or wget is required"; fi
|
|
|
fetch_to() { $FETCH "$1" > "$2"; }
|
|
|
- command -v sha256sum >/dev/null 2>&1 || fatal 21 "falta sha256sum"
|
|
|
+ command -v sha256sum >/dev/null 2>&1 || fatal 21 "sha256sum is missing"
|
|
|
# ------------------------------------------------------------- server --
|
|
|
# #1367: el binario sale del PROPIO server con la arch detectada arriba.
|
|
|
# Antes el one-liner pre-descargaba sin ?arch= y el handler defaulteaba
|
|
|
@@ -315,7 +314,7 @@ else
|
|
|
if [ -z "$NETPULSE_VERSION" ] && [ -n "$TOKEN" ] && command -v curl >/dev/null 2>&1; then
|
|
|
CA_ARGS=""
|
|
|
[ -n "$CA_FILE" ] && CA_ARGS="--cacert $CA_FILE"
|
|
|
- info "descargando netpulse-agent ($GOARCH) de $SERVER"
|
|
|
+ info "downloading netpulse-agent ($GOARCH) from $SERVER"
|
|
|
if curl -fsSL $CA_ARGS --connect-timeout 10 --retry 3 \
|
|
|
-H "Authorization: Bearer $TOKEN" -D "$TMP/headers" \
|
|
|
"$SERVER/api/agents/$SLUG/binary?arch=$GOARCH" -o "$TMP/$BIN_NAME" \
|
|
|
@@ -323,23 +322,23 @@ else
|
|
|
SUM_REF=$(grep -i '^x-checksum-sha256:' "$TMP/headers" | tr -d '\r' | awk '{print $2}')
|
|
|
if [ -n "$SUM_REF" ]; then
|
|
|
SUM_FILE=$(sha256sum "$TMP/$BIN_NAME" | awk '{print $1}')
|
|
|
- [ "$SUM_FILE" = "$SUM_REF" ] || fatal 33 "sha256 NO COINCIDE (server, arch $GOARCH)"
|
|
|
- ok "sha256 verificado (server)"
|
|
|
+ [ "$SUM_FILE" = "$SUM_REF" ] || fatal 33 "sha256 MISMATCH (server, arch $GOARCH)"
|
|
|
+ ok "sha256 verified (server)"
|
|
|
else
|
|
|
- warn "el server no envió X-Checksum-Sha256; sin verificación de suma"
|
|
|
+ warn "the server sent no X-Checksum-Sha256, no checksum verification"
|
|
|
fi
|
|
|
else
|
|
|
- warn "descarga del server falló; pruebo con la release de GitHub"
|
|
|
+ warn "download from the server failed, trying the GitHub release"
|
|
|
rm -f "$TMP/$BIN_NAME"
|
|
|
fi
|
|
|
fi
|
|
|
|
|
|
if [ ! -s "$TMP/$BIN_NAME" ]; then
|
|
|
if [ -z "$NETPULSE_VERSION" ]; then
|
|
|
- info "resolviendo última release"
|
|
|
+ info "resolving the latest release"
|
|
|
NETPULSE_VERSION=$($FETCH "https://api.github.com/repos/$GH_REPO/releases/latest" \
|
|
|
| grep -oE '"tag_name"[[:space:]]*:[[:space:]]*"[^"]*"' | head -1 | cut -d'"' -f4) \
|
|
|
- || fatal 31 "no pude resolver la última release; usa --version=X.Y.Z"
|
|
|
+ || fatal 31 "could not resolve the latest release, use --version=X.Y.Z"
|
|
|
fi
|
|
|
VERSION_NORM=$(echo "$NETPULSE_VERSION" | sed 's/^v//')
|
|
|
case "$NETPULSE_VERSION" in
|
|
|
@@ -349,20 +348,20 @@ else
|
|
|
ASSET="${BIN_NAME}_${VERSION_NORM}_linux_${GOARCH}.tar.gz"
|
|
|
BASE_URL="https://github.com/$GH_REPO/releases/download/$NETPULSE_TAG"
|
|
|
info "descargando $ASSET"
|
|
|
- fetch_to "$BASE_URL/$ASSET" "$TMP/$ASSET" || fatal 32 "descarga falló: $BASE_URL/$ASSET"
|
|
|
- fetch_to "$BASE_URL/checksums.txt" "$TMP/checksums.txt" || fatal 32 "checksums.txt no está en $NETPULSE_VERSION"
|
|
|
+ fetch_to "$BASE_URL/$ASSET" "$TMP/$ASSET" || fatal 32 "download failed: $BASE_URL/$ASSET"
|
|
|
+ fetch_to "$BASE_URL/checksums.txt" "$TMP/checksums.txt" || fatal 32 "checksums.txt is not in $NETPULSE_VERSION"
|
|
|
SUM_FILE=$(sha256sum "$TMP/$ASSET" | awk '{print $1}')
|
|
|
SUM_REF=$(grep " $ASSET\$" "$TMP/checksums.txt" | awk '{print $1}')
|
|
|
- [ -n "$SUM_REF" ] || fatal 33 "$ASSET no está en checksums.txt"
|
|
|
- [ "$SUM_FILE" = "$SUM_REF" ] || fatal 33 "sha256 NO COINCIDE para $ASSET"
|
|
|
- ok "sha256 verificado"
|
|
|
+ [ -n "$SUM_REF" ] || fatal 33 "$ASSET is not in checksums.txt"
|
|
|
+ [ "$SUM_FILE" = "$SUM_REF" ] || fatal 33 "sha256 MISMATCH for $ASSET"
|
|
|
+ ok "sha256 verified"
|
|
|
tar -xzf "$TMP/$ASSET" -C "$TMP"
|
|
|
fi
|
|
|
fi
|
|
|
-[ -s "$TMP/$BIN_NAME" ] || fatal 34 "no hay binario que instalar"
|
|
|
+[ -s "$TMP/$BIN_NAME" ] || fatal 34 "no binary to install"
|
|
|
|
|
|
# ------------------------------------------------------------------ install --
|
|
|
-info "copiando binario → $SSH:$BIN_DST"
|
|
|
+info "copying the binary to $SSH:$BIN_DST"
|
|
|
# Reinstalación: si hay una versión previa en marcha, parar el servicio ANTES
|
|
|
# del scp — el proceso vivo tiene el binario abierto y la copia falla con
|
|
|
# "Text file busy". El servicio se reactiva al final (enable + restart).
|
|
|
@@ -376,13 +375,13 @@ ssh $SSH_IDENT_ARGS "$SSH" "/etc/init.d/$INIT_NAME stop >/dev/null 2>&1 || true"
|
|
|
# salida. Aquí cualquier fallo aborta con el código y el motivo a la vista.
|
|
|
BIN_TMP="$BIN_DST.new"
|
|
|
scp -Oq $SSH_IDENT_ARGS "$TMP/$BIN_NAME" "$SSH:$BIN_TMP" \
|
|
|
- || fatal 35 "no pude copiar el binario a $BIN_TMP en el router (revisa espacio libre con 'df -h /' y que $BIN_DST sea escribible)"
|
|
|
+ || fatal 35 "could not copy the binary to $BIN_TMP on the router (check free space with 'df -h /' and that $BIN_DST is writable)"
|
|
|
ssh $SSH_IDENT_ARGS "$SSH" "chmod 0755 $BIN_TMP && mv -f $BIN_TMP $BIN_DST" \
|
|
|
- || { ssh $SSH_IDENT_ARGS "$SSH" "rm -f $BIN_TMP" || true; fatal 36 "copié $BIN_TMP pero no pude moverlo a $BIN_DST en el router"; }
|
|
|
-ok "binario en $BIN_DST"
|
|
|
+ || { ssh $SSH_IDENT_ARGS "$SSH" "rm -f $BIN_TMP" || true; fatal 36 "copied $BIN_TMP but could not move it to $BIN_DST on the router"; }
|
|
|
+ok "binary at $BIN_DST"
|
|
|
|
|
|
# Config (chmod 600: el token solo lo lee root)
|
|
|
-info "escribiendo $ENV_FILE (chmod 600)"
|
|
|
+info "writing $ENV_FILE (chmod 600)"
|
|
|
# Construir la línea de token: PAIRING_TOKEN (bootstrap) o TOKEN (normal)
|
|
|
if [ -n "$PAIRING_TOKEN" ]; then
|
|
|
TOKEN_LINE="NETPULSE_PAIRING_TOKEN=$PAIRING_TOKEN"
|
|
|
@@ -423,10 +422,10 @@ EOF
|
|
|
if [ -n "$USER_VARS" ]; then
|
|
|
printf '%s\n' "$USER_VARS" | ssh $SSH_IDENT_ARGS "$SSH" "cat >> $ENV_FILE"
|
|
|
fi
|
|
|
-ok "config escrita"
|
|
|
+ok "config written"
|
|
|
|
|
|
# Servicio procd (respawn + self-heal del binario tras sysupgrade)
|
|
|
-info "instalando servicio procd"
|
|
|
+info "installing the procd service"
|
|
|
SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
|
|
if [ -f "$SCRIPT_DIR/agent/deploy/$INIT_NAME.init" ]; then
|
|
|
scp -Oq $SSH_IDENT_ARGS "$SCRIPT_DIR/agent/deploy/$INIT_NAME.init" "$SSH:$INIT_DST"
|
|
|
@@ -458,7 +457,7 @@ selfheal_binary() {
|
|
|
https|HTTPS) ;;
|
|
|
*)
|
|
|
[ "${NETPULSE_ALLOW_INSECURE_COMMANDS:-}" = "1" ] || {
|
|
|
- logger -t netpulse-agent "self-heal: HTTP sin NETPULSE_ALLOW_INSECURE_COMMANDS=1, binario no descargado"
|
|
|
+ logger -t netpulse-agent "self-heal: HTTP without NETPULSE_ALLOW_INSECURE_COMMANDS=1, binary not downloaded"
|
|
|
return 1
|
|
|
}
|
|
|
;;
|
|
|
@@ -477,7 +476,7 @@ selfheal_binary() {
|
|
|
esac
|
|
|
local url tmp hdr digest sum
|
|
|
url="${NETPULSE_SERVER%/}/api/agents/${NETPULSE_SLUG}/binary?arch=${ARCH}"
|
|
|
- logger -t netpulse-agent "self-heal: binario ausente, descargando de $NETPULSE_SERVER"
|
|
|
+ logger -t netpulse-agent "self-heal: binary missing, downloading from $NETPULSE_SERVER"
|
|
|
tmp=/tmp/netpulse-agent.$$
|
|
|
hdr=/tmp/netpulse-agent.hdr.$$
|
|
|
if command -v curl >/dev/null 2>&1; then
|
|
|
@@ -489,19 +488,19 @@ selfheal_binary() {
|
|
|
rm -f "$hdr"
|
|
|
case "$digest" in
|
|
|
""|*[!0123456789abcdefABCDEF]*)
|
|
|
- logger -t netpulse-agent "self-heal: sin X-Checksum-Sha256 válido, binario descartado"
|
|
|
+ logger -t netpulse-agent "self-heal: no valid X-Checksum-Sha256, binary discarded"
|
|
|
rm -f "$tmp"
|
|
|
return 1 ;;
|
|
|
esac
|
|
|
- [ "${#digest}" -eq 64 ] || { logger -t netpulse-agent "self-heal: digest con longitud inválida, binario descartado"; rm -f "$tmp"; return 1; }
|
|
|
+ [ "${#digest}" -eq 64 ] || { logger -t netpulse-agent "self-heal: digest with invalid length, binary discarded"; rm -f "$tmp"; return 1; }
|
|
|
sum=$(sha256sum "$tmp" 2>/dev/null | awk '{print $1}')
|
|
|
if [ -z "$sum" ] || [ "$(printf '%s' "$sum" | tr 'A-F' 'a-f')" != "$(printf '%s' "$digest" | tr 'A-F' 'a-f')" ]; then
|
|
|
- logger -t netpulse-agent "self-heal: SHA-256 no coincide, binario descartado"
|
|
|
+ logger -t netpulse-agent "self-heal: SHA-256 mismatch, binary discarded"
|
|
|
rm -f "$tmp"
|
|
|
return 1
|
|
|
fi
|
|
|
chmod 0755 "$tmp" && mv "$tmp" /usr/sbin/netpulse-agent || { rm -f "$tmp"; return 1; }
|
|
|
- logger -t netpulse-agent "self-heal: binario restaurado"
|
|
|
+ logger -t netpulse-agent "self-heal: binary restored"
|
|
|
BIN=/usr/sbin/netpulse-agent
|
|
|
return 0
|
|
|
}
|
|
|
@@ -514,12 +513,12 @@ cleanup_stale_watchdog_cron() {
|
|
|
[ -f /usr/sbin/netpulse-watchdog ] && return 0
|
|
|
crontab -l 2>/dev/null | grep -q netpulse-watchdog || return 0
|
|
|
( crontab -l 2>/dev/null | grep -v netpulse-watchdog ) | crontab - 2>/dev/null || true
|
|
|
- logger -t netpulse-agent "watchdog cron huérfano retirado (#879)"
|
|
|
+ logger -t netpulse-agent "orphan watchdog cron entry removed (#879)"
|
|
|
}
|
|
|
|
|
|
start_service() {
|
|
|
cleanup_stale_watchdog_cron
|
|
|
- selfheal_binary || logger -t netpulse-agent "self-heal: no se pudo restaurar el binario"
|
|
|
+ selfheal_binary || logger -t netpulse-agent "self-heal: could not restore the binary"
|
|
|
procd_open_instance netpulse-agent
|
|
|
procd_set_param command "$BIN"
|
|
|
procd_set_param respawn "${respawn_threshold:-3600}" "${respawn_timeout:-5}" "${respawn_retry:-5}"
|
|
|
@@ -531,7 +530,7 @@ start_service() {
|
|
|
INITEOF
|
|
|
fi
|
|
|
ssh $SSH_IDENT_ARGS "$SSH" "chmod 0755 $INIT_DST && $INIT_DST enable && $INIT_DST restart"
|
|
|
-ok "servicio $INIT_NAME habilitado y arrancado"
|
|
|
+ok "service $INIT_NAME enabled and started"
|
|
|
|
|
|
# ------------------------------------------------------- sysupgrade (#1476) --
|
|
|
# OpenWrt solo conserva en una actualización de imagen los conffiles de los
|
|
|
@@ -540,9 +539,9 @@ ok "servicio $INIT_NAME habilitado y arrancado"
|
|
|
# ficheros sueltos: sin esta lista desaparecen al actualizar y el self-heal del
|
|
|
# init nunca llega a correr, porque lo que se pierde es el punto de entrada.
|
|
|
# Mismo gesto que el flujo owut (firmware.EnsureStackPreserved), idempotente.
|
|
|
-info "preservando el agente en /etc/sysupgrade.conf (#1476)"
|
|
|
+info "preserving the agent in /etc/sysupgrade.conf (#1476)"
|
|
|
ssh $SSH_IDENT_ARGS "$SSH" "P=/etc/sysupgrade.conf; touch \$P; ensure() { grep -qxF \"\$1\" \$P 2>/dev/null || echo \"\$1\" >> \$P; }; ensure /usr/sbin/$BIN_NAME; ensure $ENV_FILE; ensure $INIT_DST; for f in /etc/rc.d/*$INIT_NAME*; do [ -e \"\$f\" ] && ensure \"\$f\"; done; true" \
|
|
|
- || warn "no pude actualizar /etc/sysupgrade.conf: el agente no sobrevivirá a una actualización de firmware"
|
|
|
+ || warn "could not update /etc/sysupgrade.conf, the agent will not survive a firmware upgrade"
|
|
|
|
|
|
# ------------------------------------------------- lldpd en puertos físicos (#1369) --
|
|
|
# lldpd bound al bridge (br-lan) no recibe vecinos en varios targets
|
|
|
@@ -556,14 +555,14 @@ ssh $SSH_IDENT_ARGS "$SSH" "P=/etc/sysupgrade.conf; touch \$P; ensure() { grep -
|
|
|
if ssh $SSH_IDENT_ARGS "$SSH" "command -v lldpcli >/dev/null 2>&1"; then
|
|
|
LLDP_IF=$(ssh $SSH_IDENT_ARGS "$SSH" "uci -q get lldpd.config.interface 2>/dev/null")
|
|
|
if printf '%s' "$LLDP_IF" | grep -qE '(^|,)[[:space:]]*(lan|wan|eth)'; then
|
|
|
- ok "lldpd ya escucha en puertos físicos (${LLDP_IF:-auto})"
|
|
|
+ ok "lldpd already listens on physical ports (${LLDP_IF:-auto})"
|
|
|
else
|
|
|
ssh $SSH_IDENT_ARGS "$SSH" "uci set lldpd.config.interface='lan*,wan' && uci commit lldpd && /etc/init.d/lldpd restart >/dev/null 2>&1" \
|
|
|
- && ok "lldpd reconfigurado: escucha en puertos físicos (lan*,wan)${LLDP_IF:+ - antes: $LLDP_IF}" \
|
|
|
- || warn "no se pudo reconfigurar lldpd; a mano: uci set lldpd.config.interface='lan*,wan' && uci commit lldpd && /etc/init.d/lldpd restart"
|
|
|
+ && ok "lldpd reconfigured, listening on physical ports (lan*,wan)${LLDP_IF:+ - before: $LLDP_IF}" \
|
|
|
+ || warn "could not reconfigure lldpd, by hand: uci set lldpd.config.interface='lan*,wan' && uci commit lldpd && /etc/init.d/lldpd restart"
|
|
|
fi
|
|
|
else
|
|
|
- info "lldpd no instalado: sin evidencia LLDP directa (con 'opkg install lldpd' la activas; reejecuta este instalador y lo deja en puertos físicos)"
|
|
|
+ info "lldpd not installed, no direct LLDP evidence (with 'opkg install lldpd' you enable it, then run this installer again and it moves it to the physical ports)"
|
|
|
fi
|
|
|
|
|
|
# Watchdog cron: NO se instala (#851). Si el agente crashea en bucle, un
|
|
|
@@ -577,19 +576,19 @@ ssh $SSH_IDENT_ARGS "$SSH" "
|
|
|
sed -i '/netpulse-watchdog/d' /etc/crontabs/root
|
|
|
fi
|
|
|
"
|
|
|
-ok "watchdog cron no instalado (legacy limpiado)"
|
|
|
+ok "watchdog cron not installed (legacy entry removed)"
|
|
|
|
|
|
sleep 2
|
|
|
if ssh $SSH_IDENT_ARGS "$SSH" "logread -e $INIT_NAME" 2>/dev/null | tail -2 | grep -q .; then
|
|
|
- info "últimas líneas de syslog:"
|
|
|
+ info "last syslog lines:"
|
|
|
ssh $SSH_IDENT_ARGS "$SSH" "logread -e $INIT_NAME | tail -2" || true
|
|
|
fi
|
|
|
|
|
|
-printf '\n%s================ %s instalado ================%s\n' "$C_G" "$BIN_NAME" "$C_0"
|
|
|
+printf '\n%s================ %s installed ================%s\n' "$C_G" "$BIN_NAME" "$C_0"
|
|
|
printf 'Router: %s (slug: %s)\n' "$HOST" "$SLUG"
|
|
|
-printf 'Binario: %s%s\n' "$BIN_DST" "$( [ "$USE_TMP" -eq 1 ] && echo ' (variante /tmp: se pierde al reiniciar — reejecuta el instalador tras un reboot)' || true)"
|
|
|
-printf 'Config: %s (chmod 600; edítalo y haz /etc/init.d/%s restart)\n' "$ENV_FILE" "$INIT_NAME"
|
|
|
-printf 'Servidor: %s\n' "$SERVER"
|
|
|
+printf 'Binary: %s%s\n' "$BIN_DST" "$( [ "$USE_TMP" -eq 1 ] && echo ' (/tmp variant: lost on reboot, run the installer again after one)' || true)"
|
|
|
+printf 'Config: %s (chmod 600, edit it and run /etc/init.d/%s restart)\n' "$ENV_FILE" "$INIT_NAME"
|
|
|
+printf 'Server: %s\n' "$SERVER"
|
|
|
printf 'Logs: ssh %s logread -e %s\n' "$SSH" "$INIT_NAME"
|
|
|
-printf 'Verifica: GET %s/api/agents (last_seen + versión en unos 15 s)\n' "$SERVER"
|
|
|
+printf 'Check: GET %s/api/agents (last_seen + version within 15 s)\n' "$SERVER"
|
|
|
printf '%s================================================%s\n\n' "$C_G" "$C_0"
|