Files
kernel-automation/agent/install.sh
T
patrickandClaude Opus 5.5 16d647cf9c Support Ubuntu 22.04 (agent and server on Python 3.10)
The server only needed Python 3.11 for tomllib. Fall back to a small
parser for the flat key = value subset the config uses, checked against
tomllib on the shipped example. Relax the installer's version check to
3.10 and list Ubuntu 22.04 as supported for agents and server.

Add status tests using uname -v / package versions captured from real
22.04.5 and 24.04.4 HWE hosts, confirming the Ubuntu build mapping.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-17 10:23:00 -04:00

80 lines
2.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# Install or upgrade kernelwatch-agent on a Debian 12/13 or Ubuntu 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.
set -euo pipefail
here=$(cd "$(dirname "$0")" && pwd)
server=
ca=
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 ;;
*) echo "unknown argument: $1" >&2; exit 2 ;;
esac
done
[[ $(id -u) == 0 ]] || { echo "run as root" >&2; exit 1; }
# shellcheck source=/dev/null
. /etc/os-release
case "$ID:$VERSION_ID" in
debian:12 | debian:13 | ubuntu:22.04 | ubuntu:24.04) ;;
*) echo "warning: untested OS $PRETTY_NAME; continuing" >&2 ;;
esac
if ! command -v curl >/dev/null; then
apt-get install -y --no-install-recommends curl ca-certificates
fi
install -d -m 0755 /etc/kernelwatch
install -m 0755 "$here/kernelwatch-agent" /usr/local/sbin/kernelwatch-agent
install -m 0644 "$here/kernelwatch-agent.service" "$here/kernelwatch-agent.timer" /etc/systemd/system/
if [[ -n $ca ]]; then
install -m 0644 "$ca" /etc/kernelwatch/ca.pem
fi
if [[ -n $server ]]; then
{
echo "SERVER_URL=$server"
echo "TOKEN_FILE=/etc/kernelwatch/agent.token"
[[ -e /etc/kernelwatch/ca.pem ]] && echo "CA_FILE=/etc/kernelwatch/ca.pem"
} >/etc/kernelwatch/agent.conf
chmod 0644 /etc/kernelwatch/agent.conf
elif [[ ! -e /etc/kernelwatch/agent.conf ]]; then
echo "no /etc/kernelwatch/agent.conf yet; pass --server URL" >&2
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
[[ -n $token ]] || { echo "empty token" >&2; exit 1; }
(umask 077 && printf '%s\n' "$token" >/etc/kernelwatch/agent.token)
fi
chown root:root /etc/kernelwatch/agent.token
chmod 0600 /etc/kernelwatch/agent.token
systemctl daemon-reload
systemctl enable --now kernelwatch-agent.timer
echo "Sending first report..."
if systemctl start kernelwatch-agent.service; then
echo "OK. Check the dashboard, or: journalctl -u kernelwatch-agent"
else
echo "First report failed:" >&2
journalctl -u kernelwatch-agent -n 20 --no-pager >&2
exit 1
fi