feat(scripts): add morning health check and daily routine scripts

This commit is contained in:
ja
2026-03-16 10:53:10 +01:00
parent 2bce647b31
commit 69d6757d51
2 changed files with 142 additions and 0 deletions
+80
View File
@@ -0,0 +1,80 @@
#!/bin/bash
set -euo pipefail
# saTway Daily Routine - 7-phase morning workflow
mkdir -p "$HOME/logs" 2>/dev/null || true
LOCAL_LOG="$HOME/logs/daily-routine-$(date +%Y%m%d).log"
HEALTH_SCRIPT="$(dirname "$0")/morning-health-check.sh"
echo "--- Starting Daily Routine $(date) ---" | tee -a "$LOCAL_LOG"
# Phase 0: Health check
echo "[Phase 0/6] Running health check..." | tee -a "$LOCAL_LOG"
if [ -x "$HEALTH_SCRIPT" ]; then
if ! bash "$HEALTH_SCRIPT" 2>&1 | tee -a "$LOCAL_LOG"; then
echo " CRITICAL: Exiting daily routine" | tee -a "$LOCAL_LOG"
exit 2
fi
else
echo " WARNING: health check script not found" | tee -a "$LOCAL_LOG"
fi
# Phase 1: Log review
echo "[Phase 1/6] Reviewing error logs (last 24h)..." | tee -a "$LOCAL_LOG"
if command -v journalctl &> /dev/null; then
ERRORS=$(journalctl -p err --since "24 hours ago" --no-pager 2>/dev/null | tail -20 || true)
if [ -z "$ERRORS" ]; then
echo " No errors found" | tee -a "$LOCAL_LOG"
else
echo "$ERRORS" | tee -a "$LOCAL_LOG"
fi
else
echo " journalctl not available" | tee -a "$LOCAL_LOG"
fi
# Phase 2: Security check
echo "[Phase 2/6] Security status..." | tee -a "$LOCAL_LOG"
if systemctl is-active --quiet fail2ban 2>/dev/null; then
echo " fail2ban: active" | tee -a "$LOCAL_LOG"
else
echo " fail2ban: not running" | tee -a "$LOCAL_LOG"
fi
echo " Recent sudo:" | tee -a "$LOCAL_LOG"
sudo last -5 2>/dev/null | tee -a "$LOCAL_LOG" || echo " unable to query" | tee -a "$LOCAL_LOG"
# Phase 3: Backup verification
echo "[Phase 3/6] Backup verification..." | tee -a "$LOCAL_LOG"
if [ -d "/var/log/satway" ]; then
RECENT=$(find /var/log/satway -type f -mtime -1 2>/dev/null | wc -l)
echo " /var/log/satway: ${RECENT} file(s) modified in last 24h" | tee -a "$LOCAL_LOG"
else
echo " /var/log/satway: not found" | tee -a "$LOCAL_LOG"
fi
# Phase 4: Update check
echo "[Phase 4/6] Checking for updates..." | tee -a "$LOCAL_LOG"
if command -v checkupdates &> /dev/null; then
UPDATES=$(checkupdates 2>/dev/null | wc -l)
echo " ${UPDATES} package(s) pending" | tee -a "$LOCAL_LOG"
elif command -v pacman &> /dev/null; then
echo " Run: pacman -Syu" | tee -a "$LOCAL_LOG"
else
echo " No package manager detected" | tee -a "$LOCAL_LOG"
fi
# Phase 5: Workspace setup
echo "[Phase 5/6] Workspace sync..." | tee -a "$LOCAL_LOG"
WORKSPACE="$HOME/internal/mw-pfeddersheim-workstation"
if [ -d "$WORKSPACE/.git" ]; then
git -C "$WORKSPACE" fetch --all 2>&1 | tee -a "$LOCAL_LOG" || true
echo " Fetch complete" | tee -a "$LOCAL_LOG"
else
echo " Workspace not found" | tee -a "$LOCAL_LOG"
fi
# Phase 6: Focus mode reminder
echo "[Phase 6/6] Focus mode reminder" | tee -a "$LOCAL_LOG"
echo " Work 1: 09:00-13:00 | Regen: 13:00-14:00 | Work 2: 14:00-18:00" | tee -a "$LOCAL_LOG"
echo " Friday post-15:00 = family time" | tee -a "$LOCAL_LOG"
echo "--- Daily Routine Finished $(date) ---" | tee -a "$LOCAL_LOG"