Add agent/deploy.sh: install and upgrade agents over SSH

Run from a workstation checkout; hosts need no git or Gitea access.
A plain run upgrades every host in agent/hosts (config and token kept);
--register runs `kernelwatch add-host --token-only` on the dashboard
over SSH and hands the token to the host on stdin, never argv or the
terminal; --rotate does the same with rotate-token. Newly registered
hosts are appended to agent/hosts. Failures are summarised and don't
stop the rest of the fleet.

Supporting changes: install.sh --token-file, and --token-only on
`kernelwatch add-host` / `rotate-token`. Tested end to end with ssh and
sudo stubbed to run locally against the real CLI.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
patrickandClaude Opus 5.5 committed 2026-10-17 11:51:15 -04:00
1 parent a430a13fc8
commit 69d4cf6363
8 files changed
+456 -11

No files matched your search

+9
View File
@@ -38,6 +38,9 @@ def cmd_add_host(cfg, args) -> int:
return 1
finally:
conn.close()
if args.token_only:
print(token)
return 0
print(f"Added {args.name}. Its token (shown once):\n\n {token}\n")
print("On the host, run: sudo ./agent/install.sh --server <URL> and paste the token.")
return 0
@@ -52,6 +55,9 @@ def cmd_rotate_token(cfg, args) -> int:
return 1
finally:
conn.close()
if args.token_only:
print(token)
return 0
print(f"New token for {args.name} (the old one no longer works):\n\n {token}\n")
print("On the host, run: sudo KERNELWATCH_TOKEN=... ./agent/install.sh or edit /etc/kernelwatch/agent.token")
return 0
@@ -136,6 +142,9 @@ def main(argv: list[str] | None = None) -> int:
):
p = sub.add_parser(name, help=help_)
p.add_argument("name", type=_valid_host)
if name != "remove-host":
p.add_argument("--token-only", action="store_true",
help="print only the token (for scripts such as agent/deploy.sh)")
p.set_defaults(func=func)
sub.add_parser("list-hosts", help="list hosts and when they last reported").set_defaults(
func=cmd_list_hosts)