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:
1 parent
a430a13fc8
commit
69d4cf6363
8 files changed
+456
-11
No files matched your search
+18
-10
@@ -1,22 +1,25 @@
|
||||
#!/usr/bin/env bash
|
||||
# Install or upgrade kernelwatch-agent on a Debian 12/13 or Ubuntu 24.04 host.
|
||||
# Install or upgrade kernelwatch-agent on a Debian 12/13 or Ubuntu 22.04/24.04 host.
|
||||
#
|
||||
# sudo ./install.sh --server https://kernelwatch.example.internal [--ca ca.pem]
|
||||
#
|
||||
# The host token (from `kernelwatch add-host <name>` on the server) is read
|
||||
# from the KERNELWATCH_TOKEN environment variable or prompted for, so it never
|
||||
# lands in shell history. Re-running without --server keeps the existing config.
|
||||
# from --token-file, the KERNELWATCH_TOKEN environment variable, or a prompt,
|
||||
# so it never lands in shell history. Re-running without --server or a token
|
||||
# keeps the existing config and token (that's an upgrade).
|
||||
set -euo pipefail
|
||||
|
||||
here=$(cd "$(dirname "$0")" && pwd)
|
||||
server=
|
||||
ca=
|
||||
token_file=
|
||||
|
||||
while (($#)); do
|
||||
case $1 in
|
||||
--server) server=${2:?--server needs a URL}; shift 2 ;;
|
||||
--ca) ca=${2:?--ca needs a file}; shift 2 ;;
|
||||
-h | --help) sed -n '2,8s/^# \{0,1\}//p' "$0"; exit 0 ;;
|
||||
--token-file) token_file=${2:?--token-file needs a file}; shift 2 ;;
|
||||
-h | --help) sed -n '2,9s/^# \{0,1\}//p' "$0"; exit 0 ;;
|
||||
*) echo "unknown argument: $1" >&2; exit 2 ;;
|
||||
esac
|
||||
done
|
||||
@@ -54,13 +57,18 @@ elif [[ ! -e /etc/kernelwatch/agent.conf ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ ! -s /etc/kernelwatch/agent.token || -n ${KERNELWATCH_TOKEN:-} ]]; then
|
||||
token=${KERNELWATCH_TOKEN:-}
|
||||
if [[ -z $token ]]; then
|
||||
read -r -s -p "Host token: " token
|
||||
echo
|
||||
fi
|
||||
token=
|
||||
if [[ -n $token_file ]]; then
|
||||
token=$(tr -d '[:space:]' <"$token_file")
|
||||
[[ -n $token ]] || { echo "empty token in $token_file" >&2; exit 1; }
|
||||
elif [[ -n ${KERNELWATCH_TOKEN:-} ]]; then
|
||||
token=$KERNELWATCH_TOKEN
|
||||
elif [[ ! -s /etc/kernelwatch/agent.token ]]; then
|
||||
read -r -s -p "Host token: " token
|
||||
echo
|
||||
[[ -n $token ]] || { echo "empty token" >&2; exit 1; }
|
||||
fi
|
||||
if [[ -n $token ]]; then
|
||||
(umask 077 && printf '%s\n' "$token" >/etc/kernelwatch/agent.token)
|
||||
fi
|
||||
chown root:root /etc/kernelwatch/agent.token
|
||||
|
||||
Reference in new issue
Block a user