Scaffold kernelwatch: fleet kernel status agent and dashboard

Agent: bash script run hourly by a hardened systemd timer on Debian 12/13
and Ubuntu 24.04. Collects running vs installed kernel (needrestart when
available), pending/security updates via a read-only apt simulation,
reboot-required state and apt list freshness, and POSTs them as JSON.

Server: stdlib-only Python + SQLite (system python3 >= 3.11). Token-bound
ingest API, login-protected dashboard with per-host status
(stale/reboot/update/ok) and history, admin CLI, systemd unit and installer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
patrickandClaude Opus 5.5 committed 2026-10-17 10:15:06 -04:00
commit 07749b01b0
27 files changed
+2406

No files matched your search

+83
View File
@@ -0,0 +1,83 @@
#!/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: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
if ! command -v needrestart >/dev/null; then
echo "note: needrestart is not installed; kernel ABI-compatible upgrades won't be detected." >&2
echo " Install it with: apt-get install needrestart" >&2
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