Files
felhom.eu/documentation/audits/release-2b-3-2026-11-15/part2/clock.sh
T

32 lines
1.9 KiB
Bash

# Tester 1 ONLY. clock.sh snap|back|right
# snap — READ: the clock, the time service, every container's id and creation time in guest 9201.
# back — stop the time service and set the clock 150 s BACK (the smaller harm: putting it right is then a
# step FORWARD, the direction a time service steps a late clock; nothing gets a stamp from the future
# while the clock is wrong, and no certificate or signed job ends early).
# right — start the time service and step the clock right.
set -u
grep -q '"tester-1' /etc/felhom-agent/agent.json 2>/dev/null || grep -q 'tester-1' /etc/felhom-agent/agent.json || { echo "REFUSED: this box is not Tester 1"; exit 2; }
snap() {
echo "## $(hostname) clock $(date '+%F %T.%N %Z' | cut -c1-27) epoch $(date +%s.%N | cut -c1-14); chrony $(systemctl is-active chrony); $(chronyc tracking 2>/dev/null | grep -E 'System time|Leap' | tr -s ' ' | tr '\n' ';')"
echo "## kernel boot_id $(cat /proc/sys/kernel/random/boot_id); btime $(awk '/^btime/ {print $2}' /proc/stat); uptime $(cut -d' ' -f1 /proc/uptime) s"
echo "## containers in 9201 (name id created):"
pct exec 9201 -- docker ps -a --format '{{.Names}} {{.ID}} {{.CreatedAt}} [{{.Status}}]' | sort | sed 's/^/ /'
echo "## count $(pct exec 9201 -- docker ps -q | wc -l) running"
}
case "${1:-}" in
snap) snap ;;
back)
busy=$(ps -eo comm | grep -cE "^(vzdump|apt-get|dpkg|proxmox-backup-)")
[ "$busy" = 0 ] || { echo "REFUSED: something is in flight"; exit 2; }
snap
systemctl stop chrony; echo "chrony stopped rc=$?"
date -s "@$(( $(date +%s) - 150 ))" >/dev/null; echo "clock set 150 s back rc=$? → $(date '+%F %T')"
;;
right)
systemctl start chrony; echo "chrony started rc=$?"
sleep 8; chronyc makestep; sleep 6
echo "clock now $(date '+%F %T'); $(chronyc tracking | grep -E 'System time|Leap' | tr -s ' ' | tr '\n' ';')"
;;
*) echo "usage: snap|back|right"; exit 2 ;;
esac