Răsfoiți Sursa

fix(integrations): install the asuswrt pusher the merlin way (/jffs plus services-start) (#1705)

Nacho 1 lună în urmă
părinte
comite
124d3abd9a

+ 241 - 26
server-go/internal/httpapi/integrations.go

@@ -767,23 +767,42 @@ func (s *server) handleIntegrationDelete(w http.ResponseWriter, r *http.Request)
 // Scripts POSIX de instalación/gestión por SSH (modo ssh, p. ej. asuswrt)
 // ---------------------------------------------------------------------------
 
-func sshInstallScript(v rintegration.Vendor, env map[string]string, assetURL, sha256 string) string {
-	bin := "/usr/sbin/" + v.Binary
-	init := "/etc/init.d/" + v.Binary
-	envFile := "/etc/" + v.Binary + ".env"
-
+// envFileBody renders the sorted KEY=value body of an env file, with values
+// escaped by EscapeEnvValue for a lossless round-trip through ParseEnv.
+func envFileBody(env map[string]string) string {
 	keys := make([]string, 0, len(env))
 	for k := range env {
 		keys = append(keys, k)
 	}
 	sort.Strings(keys)
-	var envBlock strings.Builder
+	var b strings.Builder
 	for _, k := range keys {
-		envBlock.WriteString(k)
-		envBlock.WriteString("=")
-		envBlock.WriteString(rintegration.EscapeEnvValue(env[k]))
-		envBlock.WriteString("\n")
+		b.WriteString(k)
+		b.WriteString("=")
+		b.WriteString(rintegration.EscapeEnvValue(env[k]))
+		b.WriteString("\n")
+	}
+	return b.String()
+}
+
+// sshInstallScript genera el instalador on-router de un vendor en modo ssh.
+// Ramifica por el sistema de init del vendor (#1681): procd (layout OpenWrt,
+// salida intacta) o merlin (/jffs + bloque gestionado en services-start).
+func sshInstallScript(v rintegration.Vendor, env map[string]string, assetURL, sha256 string) string {
+	if v.InitSystem() == "merlin" {
+		return sshMerlinInstallScript(v, env, assetURL, sha256)
 	}
+	return sshProcdInstallScript(v, env, assetURL, sha256)
+}
+
+// sshProcdInstallScript instala el pusher en un vendor OpenWrt: binario en
+// /usr/sbin, init procd en /etc/init.d y env en /etc.
+func sshProcdInstallScript(v rintegration.Vendor, env map[string]string, assetURL, sha256 string) string {
+	bin := "/usr/sbin/" + v.Binary
+	init := "/etc/init.d/" + v.Binary
+	envFile := "/etc/" + v.Binary + ".env"
+
+	envBlock := envFileBody(env)
 
 	return `#!/bin/sh
 set -e
@@ -829,7 +848,7 @@ rm -rf /tmp/` + v.Binary + `.extract /tmp/` + v.Binary + `.tar.gz
 # fichero existente (la contraseña y el token solo viven ahí).
 if [ ! -f "$ENV_FILE" ]; then
 cat > "$ENV_FILE" <<'ENVEOF'
-` + envBlock.String() + `ENVEOF
+` + envBlock + `ENVEOF
 chmod 600 "$ENV_FILE"
 fi
 
@@ -858,10 +877,165 @@ chmod 0755 "$INIT"
 `
 }
 
+// sshMerlinInstallScript instala el pusher en un vendor Asuswrt-Merlin
+// (#1681): sin procd, todo bajo /jffs/netpulse (binario, env, script de
+// control con pidfile y log) y un bloque gestionado en
+// /jffs/scripts/services-start para el arranque al boot. Re-ejecutarlo es
+// idempotente: el env solo se escribe si falta y el bloque solo se añade una
+// vez; el resto del hook no se toca.
+func sshMerlinInstallScript(v rintegration.Vendor, env map[string]string, assetURL, sha256 string) string {
+	dir := "/jffs/netpulse"
+	bin := dir + "/" + v.Binary
+	ctrl := bin + ".sh"
+	envFile := bin + ".env"
+	pidFile := bin + ".pid"
+	logFile := bin + ".log"
+	blockStart := "# >>> netpulse " + v.Binary + " >>>"
+	blockEnd := "# <<< netpulse " + v.Binary + " <<<"
+
+	return `#!/bin/sh
+set -e
+BIN="` + bin + `"
+CTRL="` + ctrl + `"
+ENV_FILE="` + envFile + `"
+PID_FILE="` + pidFile + `"
+LOG_FILE="` + logFile + `"
+HOOK="/jffs/scripts/services-start"
+SERVER="` + env["NETPULSE_SERVER"] + `"
+ASSET_URL="` + assetURL + `"
+SHA256="` + sha256 + `"
+
+# Preflight: el router debe alcanzar el server.
+if command -v curl >/dev/null 2>&1; then
+	curl -fsSL -m 10 "$SERVER/api/health" >/dev/null 2>&1 || { echo "preflight: cannot reach $SERVER/api/health"; exit 10; }
+else
+	wget -q -T 10 -O /dev/null "$SERVER/api/health" || { echo "preflight: cannot reach $SERVER/api/health"; exit 10; }
+fi
+
+# Parar el pusher previo (el proceso vivo mantiene el binario abierto).
+[ -x "$CTRL" ] && "$CTRL" stop >/dev/null 2>&1 || true
+
+# Descargar el asset desde la URL ya verificada en el server.
+if command -v curl >/dev/null 2>&1; then
+	curl -fsSL -m 600 -o /tmp/` + v.Binary + `.tar.gz "$ASSET_URL"
+else
+	wget -q -T 60 -O /tmp/` + v.Binary + `.tar.gz "$ASSET_URL"
+fi
+
+# Verificar sha256 antes de instalar.
+GOT=$(sha256sum /tmp/` + v.Binary + `.tar.gz | awk '{print $1}')
+[ "$GOT" = "$SHA256" ] || { echo "sha256 mismatch (want $SHA256, got $GOT)"; exit 21; }
+
+# Extraer y mover de forma atómica (.new -> rename).
+mkdir -p /tmp/` + v.Binary + `.extract
+tar -xzf /tmp/` + v.Binary + `.tar.gz -C /tmp/` + v.Binary + `.extract
+SRC=$(find /tmp/` + v.Binary + `.extract -type f -name "` + v.Binary + `" | head -n1)
+[ -n "$SRC" ] || { echo "binary not found in archive"; exit 22; }
+mkdir -p "$DIR"
+cp "$SRC" "$BIN.new"
+chmod 0755 "$BIN.new"
+mv -f "$BIN.new" "$BIN"
+rm -rf /tmp/` + v.Binary + `.extract /tmp/` + v.Binary + `.tar.gz
+
+# Env (chmod 600): solo se escribe si aún no existe; los updates preservan
+# el fichero (la contraseña y el token solo viven ahí).
+if [ ! -f "$ENV_FILE" ]; then
+cat > "$ENV_FILE" <<'ENVEOF'
+` + envFileBody(env) + `ENVEOF
+chmod 600 "$ENV_FILE"
+fi
+
+# Script de control con pidfile (start|stop|restart|check). El env guarda
+# los valores escapados (salto de línea = \n): printf %b los desescapa igual
+# que ParseEnv en el server antes de exportarlos al pusher.
+cat > "$CTRL" <<'CTRLEOF'
+#!/bin/sh
+# NetPulse pusher control script (Asuswrt-Merlin).
+BIN="` + bin + `"
+PID_FILE="` + pidFile + `"
+ENV_FILE="` + envFile + `"
+LOG_FILE="` + logFile + `"
+running() {
+	[ -f "$PID_FILE" ] && kill -0 "$(cat "$PID_FILE")" 2>/dev/null
+}
+case "$1" in
+start)
+	[ -x "$BIN" ] || { echo "netpulse: missing $BIN"; exit 1; }
+	if running; then
+		exit 0
+	fi
+	rm -f "$PID_FILE"
+	[ -f "$ENV_FILE" ] || { echo "netpulse: missing $ENV_FILE"; exit 1; }
+	while IFS= read -r line || [ -n "$line" ]; do
+		case "$line" in ""|\#*) continue ;; esac
+		k=${line%%=*}
+		val=${line#*=}
+		val=$(printf '%b' "$val")
+		export "$k=$val"
+	done < "$ENV_FILE"
+	nohup "$BIN" >> "$LOG_FILE" 2>&1 &
+	echo $! > "$PID_FILE"
+	;;
+stop)
+	if [ -f "$PID_FILE" ]; then
+		RUN_PID=$(cat "$PID_FILE")
+		kill "$RUN_PID" 2>/dev/null || true
+		n=0
+		while kill -0 "$RUN_PID" 2>/dev/null && [ "$n" -lt 10 ]; do
+			sleep 1
+			n=$((n+1))
+		done
+		if kill -0 "$RUN_PID" 2>/dev/null; then
+			kill -9 "$RUN_PID" 2>/dev/null || true
+		fi
+		rm -f "$PID_FILE"
+	fi
+	;;
+restart)
+	"$0" stop
+	"$0" start
+	;;
+check)
+	if running; then
+		exit 0
+	fi
+	exit 1
+	;;
+*)
+	echo "usage: $0 {start|stop|restart|check}"
+	exit 2
+	;;
+esac
+CTRLEOF
+chmod 0755 "$CTRL"
+
+# Arranque al boot: bloque gestionado en services-start, delimitado por
+# marcadores únicos para poder quitarlo sin tocar el resto del fichero.
+mkdir -p /jffs/scripts
+if [ ! -f "$HOOK" ]; then
+	printf '#!/bin/sh\n' > "$HOOK"
+fi
+chmod 0755 "$HOOK"
+if ! grep -qF '` + blockStart + `' "$HOOK" 2>/dev/null; then
+	cat >> "$HOOK" <<'BLOKEOF'
+
+` + blockStart + `
+` + ctrl + ` start
+` + blockEnd + `
+BLOKEOF
+fi
+
+"$CTRL" start
+`
+}
+
 // sshEnvReadScript prints the environment file of an integration running
 // inside the router, so the server can merge changes without ever storing the
-// token or the password.
+// token or the password. Merlin vendors keep the env under /jffs/netpulse.
 func sshEnvReadScript(v rintegration.Vendor) string {
+	if v.InitSystem() == "merlin" {
+		return "cat /jffs/netpulse/" + v.Binary + ".env"
+	}
 	return "cat /etc/" + v.Binary + ".env"
 }
 
@@ -869,28 +1043,32 @@ func sshEnvReadScript(v rintegration.Vendor) string {
 // restarts the service. Values come already escaped by EscapeEnvValue and the
 // heredoc is quoted, so the shell does not expand anything.
 func sshEnvWriteScript(v rintegration.Vendor, env map[string]string) string {
+	envBlock := envFileBody(env)
+	if v.InitSystem() == "merlin" {
+		envFile := "/jffs/netpulse/" + v.Binary + ".env"
+		ctrl := "/jffs/netpulse/" + v.Binary + ".sh"
+		return `#!/bin/sh
+set -e
+ENV_FILE="` + envFile + `"
+CTRL="` + ctrl + `"
+cat > "$ENV_FILE.new" <<'ENVEOF'
+` + envBlock + `ENVEOF
+chmod 600 "$ENV_FILE.new"
+mv -f "$ENV_FILE.new" "$ENV_FILE"
+if [ -x "$CTRL" ]; then
+	"$CTRL" restart >/dev/null 2>&1 || true
+fi
+`
+	}
 	init := "/etc/init.d/" + v.Binary
 	envFile := "/etc/" + v.Binary + ".env"
 
-	keys := make([]string, 0, len(env))
-	for k := range env {
-		keys = append(keys, k)
-	}
-	sort.Strings(keys)
-	var envBlock strings.Builder
-	for _, k := range keys {
-		envBlock.WriteString(k)
-		envBlock.WriteString("=")
-		envBlock.WriteString(rintegration.EscapeEnvValue(env[k]))
-		envBlock.WriteString("\n")
-	}
-
 	return `#!/bin/sh
 set -e
 INIT="` + init + `"
 ENV_FILE="` + envFile + `"
 cat > "$ENV_FILE.new" <<'ENVEOF'
-` + envBlock.String() + `ENVEOF
+` + envBlock + `ENVEOF
 chmod 600 "$ENV_FILE.new"
 mv -f "$ENV_FILE.new" "$ENV_FILE"
 if [ -x "$INIT" ]; then
@@ -901,6 +1079,23 @@ fi
 }
 
 func sshServiceScript(v rintegration.Vendor, action string) string {
+	if v.InitSystem() == "merlin" {
+		// Merlin no tiene procd: las acciones van al script de control
+		// con pidfile. check sigue siendo pgrep para no cambiar el camino
+		// de salud del handler.
+		ctrl := "/jffs/netpulse/" + v.Binary + ".sh"
+		switch action {
+		case "start":
+			return "test -x " + ctrl + " && " + ctrl + " start || true"
+		case "stop":
+			return "test -x " + ctrl + " && " + ctrl + " stop || true"
+		case "restart":
+			return "test -x " + ctrl + " && " + ctrl + " restart || true"
+		case "check":
+			return "pgrep -f " + v.Binary + " >/dev/null 2>&1"
+		}
+		return "true"
+	}
 	init := "/etc/init.d/" + v.Binary
 	switch action {
 	case "start":
@@ -916,6 +1111,9 @@ func sshServiceScript(v rintegration.Vendor, action string) string {
 }
 
 func sshUninstallScript(v rintegration.Vendor) string {
+	if v.InitSystem() == "merlin" {
+		return sshMerlinUninstallScript(v)
+	}
 	init := "/etc/init.d/" + v.Binary
 	bin := "/usr/sbin/" + v.Binary
 	envFile := "/etc/" + v.Binary + ".env"
@@ -924,3 +1122,20 @@ func sshUninstallScript(v rintegration.Vendor) string {
 		init, init, init, init, init, bin, envFile,
 	)
 }
+
+// sshMerlinUninstallScript para el pusher con su script de control, quita el
+// bloque gestionado de services-start (el resto del hook queda intacto) y
+// borra /jffs/netpulse entero.
+func sshMerlinUninstallScript(v rintegration.Vendor) string {
+	ctrl := "/jffs/netpulse/" + v.Binary + ".sh"
+	blockStart := "# >>> netpulse " + v.Binary + " >>>"
+	blockEnd := "# <<< netpulse " + v.Binary + " <<<"
+	return `CTRL="` + ctrl + `"
+HOOK="/jffs/scripts/services-start"
+[ -x "$CTRL" ] && "$CTRL" stop >/dev/null 2>&1 || true
+if [ -f "$HOOK" ]; then
+	sed -i '/` + blockStart + `/,/` + blockEnd + `/d' "$HOOK" 2>/dev/null || true
+fi
+rm -rf /jffs/netpulse
+`
+}

+ 8 - 5
server-go/internal/httpapi/integrations_edit_test.go

@@ -7,11 +7,14 @@ import (
 	"github.com/gnacho/netpulse/server-go/internal/rintegration"
 )
 
+// procdVendor returns a synthetic ssh vendor with empty Init, which means the
+// procd layout: the tests below pin that output unchanged.
+func procdVendor() rintegration.Vendor {
+	return rintegration.Vendor{ID: "openwrt", Mode: "ssh", Binary: "test-pusher"}
+}
+
 func TestSSHEnvWriteScriptRewritesFileAndRestarts(t *testing.T) {
-	v, ok := rintegration.LookupVendor("asuswrt")
-	if !ok {
-		t.Fatal("asuswrt vendor missing")
-	}
+	v := procdVendor()
 	env := map[string]string{
 		"ASUSWRT_HOST":      "127.0.0.1",
 		"ASUSWRT_USER":      "admin",
@@ -39,7 +42,7 @@ func TestSSHEnvWriteScriptRewritesFileAndRestarts(t *testing.T) {
 }
 
 func TestSSHEnvReadScriptTargetsEnvFile(t *testing.T) {
-	v, _ := rintegration.LookupVendor("asuswrt")
+	v := procdVendor()
 	if got := sshEnvReadScript(v); got != "cat /etc/"+v.Binary+".env" {
 		t.Fatalf("read script = %q", got)
 	}

+ 187 - 0
server-go/internal/httpapi/integrations_merlin_test.go

@@ -0,0 +1,187 @@
+package httpapi
+
+import (
+	"strings"
+	"testing"
+
+	"github.com/gnacho/netpulse/server-go/internal/rintegration"
+)
+
+// merlinVendor returns the asuswrt vendor: the only ssh vendor and the only
+// one with Init "merlin" (#1681).
+func merlinVendor(t *testing.T) rintegration.Vendor {
+	t.Helper()
+	v, ok := rintegration.LookupVendor("asuswrt")
+	if !ok {
+		t.Fatal("asuswrt vendor missing")
+	}
+	return v
+}
+
+func merlinTestEnv() map[string]string {
+	return map[string]string{
+		"ASUSWRT_HOST":      "127.0.0.1",
+		"ASUSWRT_USER":      "admin",
+		"NETPULSE_SERVER":   "https://np.example",
+		"NETPULSE_INTERVAL": "45s",
+		"NETPULSE_TOKEN":    "token-1",
+	}
+}
+
+func TestSSHInstallScriptMerlinLayout(t *testing.T) {
+	v := merlinVendor(t)
+	script := sshInstallScript(v, merlinTestEnv(), "https://releases.example/a.tar.gz", "abc123")
+
+	for _, want := range []string{
+		"/jffs/netpulse/asuswrt-pusher",
+		"/jffs/netpulse/asuswrt-pusher.env",
+		"/jffs/netpulse/asuswrt-pusher.sh",
+		"/jffs/netpulse/asuswrt-pusher.pid",
+		"/jffs/netpulse/asuswrt-pusher.log",
+		"/jffs/scripts/services-start",
+		"# >>> netpulse asuswrt-pusher >>>",
+		"# <<< netpulse asuswrt-pusher <<<",
+		`mv -f "$BIN.new" "$BIN"`,
+		`if [ ! -f "$ENV_FILE" ]; then`,
+		`chmod 600 "$ENV_FILE"`,
+		"nohup",
+		`"$CTRL" start`,
+	} {
+		if !strings.Contains(script, want) {
+			t.Fatalf("merlin install script missing %q\n%s", want, script)
+		}
+	}
+
+	for _, banned := range []string{"procd", "/usr/sbin", "/etc/init.d", "/etc/asuswrt-pusher.env", "respawn"} {
+		if strings.Contains(script, banned) {
+			t.Fatalf("merlin install script must not contain %q\n%s", banned, script)
+		}
+	}
+
+	// Mismo preflight y misma verificación de checksum que el camino procd.
+	for _, want := range []string{"$SERVER/api/health", "exit 10", "exit 21"} {
+		if !strings.Contains(script, want) {
+			t.Fatalf("merlin install script missing %q\n%s", want, script)
+		}
+	}
+}
+
+func TestSSHInstallScriptIsDeterministic(t *testing.T) {
+	v := merlinVendor(t)
+	a := sshInstallScript(v, merlinTestEnv(), "https://releases.example/a.tar.gz", "abc123")
+	b := sshInstallScript(v, merlinTestEnv(), "https://releases.example/a.tar.gz", "abc123")
+	if a != b {
+		t.Fatal("install script must be deterministic for the same input")
+	}
+}
+
+func TestSSHInstallScriptMerlinBootHookIsIdempotent(t *testing.T) {
+	v := merlinVendor(t)
+	script := sshInstallScript(v, merlinTestEnv(), "https://releases.example/a.tar.gz", "abc123")
+
+	for _, want := range []string{
+		"mkdir -p /jffs/scripts",
+		`if [ ! -f "$HOOK" ]; then`,
+		`printf '#!/bin/sh\n' > "$HOOK"`,
+		`grep -qF '# >>> netpulse asuswrt-pusher >>>' "$HOOK"`,
+		`cat >> "$HOOK"`,
+	} {
+		if !strings.Contains(script, want) {
+			t.Fatalf("merlin boot hook missing %q\n%s", want, script)
+		}
+	}
+	// El bloque del hook llama al control script por su ruta literal, no por
+	// una variable que services-start no tiene.
+	if !strings.Contains(script, "/jffs/netpulse/asuswrt-pusher.sh start") {
+		t.Fatalf("hook block must call the control script by literal path\n%s", script)
+	}
+}
+
+func TestSSHServiceScriptMerlin(t *testing.T) {
+	v := merlinVendor(t)
+
+	if got := sshServiceScript(v, "start"); !strings.Contains(got, "/jffs/netpulse/asuswrt-pusher.sh start") {
+		t.Fatalf("merlin start = %q", got)
+	}
+	if got := sshServiceScript(v, "stop"); !strings.Contains(got, "/jffs/netpulse/asuswrt-pusher.sh stop") {
+		t.Fatalf("merlin stop = %q", got)
+	}
+	if got := sshServiceScript(v, "restart"); !strings.Contains(got, "/jffs/netpulse/asuswrt-pusher.sh restart") {
+		t.Fatalf("merlin restart = %q", got)
+	}
+	// check no cambia: el handler de salud sigue con pgrep.
+	if got := sshServiceScript(v, "check"); got != "pgrep -f asuswrt-pusher >/dev/null 2>&1" {
+		t.Fatalf("merlin check = %q, want unchanged pgrep", got)
+	}
+}
+
+func TestSSHUninstallScriptMerlin(t *testing.T) {
+	v := merlinVendor(t)
+	script := sshUninstallScript(v)
+
+	for _, want := range []string{
+		"/jffs/netpulse/asuswrt-pusher.sh",
+		"stop",
+		`sed -i '/# >>> netpulse asuswrt-pusher >>>/,/# <<< netpulse asuswrt-pusher <<</d'`,
+		"rm -rf /jffs/netpulse",
+	} {
+		if !strings.Contains(script, want) {
+			t.Fatalf("merlin uninstall missing %q\n%s", want, script)
+		}
+	}
+	for _, banned := range []string{"/usr/sbin", "/etc/init.d"} {
+		if strings.Contains(script, banned) {
+			t.Fatalf("merlin uninstall must not contain %q\n%s", banned, script)
+		}
+	}
+}
+
+func TestSSHEnvScriptsMerlin(t *testing.T) {
+	v := merlinVendor(t)
+
+	if got := sshEnvReadScript(v); got != "cat /jffs/netpulse/asuswrt-pusher.env" {
+		t.Fatalf("merlin read script = %q", got)
+	}
+
+	script := sshEnvWriteScript(v, merlinTestEnv())
+	for _, want := range []string{
+		"/jffs/netpulse/asuswrt-pusher.env",
+		`cat > "$ENV_FILE.new" <<'ENVEOF'`,
+		`chmod 600 "$ENV_FILE.new"`,
+		`mv -f "$ENV_FILE.new" "$ENV_FILE"`,
+		`"$CTRL" restart`,
+	} {
+		if !strings.Contains(script, want) {
+			t.Fatalf("merlin write script missing %q\n%s", want, script)
+		}
+	}
+}
+
+func TestSSHInstallScriptProcdUnchanged(t *testing.T) {
+	v := procdVendor()
+	script := sshInstallScript(v, merlinTestEnv(), "https://releases.example/a.tar.gz", "abc123")
+
+	for _, want := range []string{
+		"/usr/sbin/test-pusher",
+		"/etc/init.d/test-pusher",
+		"/etc/test-pusher.env",
+		"USE_PROCD=1",
+		"procd_set_param respawn 3600 5 5",
+		`mv -f "$BIN.new" "$BIN"`,
+		`"$INIT" enable`,
+	} {
+		if !strings.Contains(script, want) {
+			t.Fatalf("procd install script missing %q\n%s", want, script)
+		}
+	}
+	if strings.Contains(script, "/jffs") {
+		t.Fatalf("procd install script must not touch /jffs\n%s", script)
+	}
+
+	if got := sshServiceScript(v, "restart"); !strings.Contains(got, "/etc/init.d/test-pusher restart") {
+		t.Fatalf("procd restart = %q", got)
+	}
+	if got := sshUninstallScript(v); !strings.Contains(got, "rm -f /etc/init.d/test-pusher /usr/sbin/test-pusher /etc/test-pusher.env") {
+		t.Fatalf("procd uninstall = %q", got)
+	}
+}

+ 12 - 0
server-go/internal/rintegration/vendors.go

@@ -15,9 +15,20 @@ type Vendor struct {
 	AssetTmpl   string // asset name template with {version} and {arch}
 	Arches      []string
 	Binary      string // binary name inside the tarball
+	Init        string // on-router init system for Mode "ssh": "procd" (default when empty) | "merlin" (#1681)
 	Description string
 }
 
+// InitSystem returns the on-router layout used by the ssh install scripts:
+// "merlin" (/jffs plus a services-start hook) or "procd" (OpenWrt init.d).
+// An empty Init means procd, the layout vendors shipped with before #1681.
+func (v Vendor) InitSystem() string {
+	if v.Init == "merlin" {
+		return "merlin"
+	}
+	return "procd"
+}
+
 // AssetName renders the asset name for a resolved version and architecture.
 func (v Vendor) AssetName(version, arch string) string {
 	name := v.AssetTmpl
@@ -47,6 +58,7 @@ var vendors = []Vendor{
 		AssetTmpl:   "asuswrt_{version}_linux_{arch}.tar.gz",
 		Arches:      []string{"arm64"},
 		Binary:      "asuswrt-pusher",
+		Init:        "merlin",
 		Description: "Asuswrt (Asuswrt-Merlin) external pusher",
 	},
 	{

+ 7 - 0
server-go/internal/rintegration/vendors_test.go

@@ -29,6 +29,13 @@ func TestVendorsManifest(t *testing.T) {
 	if a.Mode != "ssh" || a.TagPrefix != "asuswrt/v" || a.Binary != "asuswrt-pusher" {
 		t.Fatalf("asuswrt manifest mismatch: %+v", a)
 	}
+	if a.InitSystem() != "merlin" {
+		t.Fatalf("asuswrt init system = %q, want merlin", a.InitSystem())
+	}
+	r2, _ := LookupVendor("routeros")
+	if r2.InitSystem() != "procd" {
+		t.Fatalf("routeros init system = %q, want procd (empty Init default)", r2.InitSystem())
+	}
 	if len(a.Arches) != 1 || a.Arches[0] != "arm64" {
 		t.Fatalf("asuswrt arches = %v, want [arm64]", a.Arches)
 	}