From 69d6757d51f874daacdaad33863a28c2a4491bee Mon Sep 17 00:00:00 2001 From: Jane Alesi Date: Mon, 16 Mar 2026 10:53:10 +0100 Subject: [PATCH] feat(scripts): add morning health check and daily routine scripts --- scripts/daily-routine.sh | 80 +++++++++++++++++++++++++++++++++ scripts/morning-health-check.sh | 62 +++++++++++++++++++++++++ 2 files changed, 142 insertions(+) create mode 100755 scripts/daily-routine.sh create mode 100755 scripts/morning-health-check.sh diff --git a/scripts/daily-routine.sh b/scripts/daily-routine.sh new file mode 100755 index 0000000..29e0cc6 --- /dev/null +++ b/scripts/daily-routine.sh @@ -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" \ No newline at end of file diff --git a/scripts/morning-health-check.sh b/scripts/morning-health-check.sh new file mode 100755 index 0000000..9c846da --- /dev/null +++ b/scripts/morning-health-check.sh @@ -0,0 +1,62 @@ +#!/bin/bash +set -euo pipefail + +# saTway Morning Health Check +# Quick Phase 0-2 system health assessment +# Exit codes: 0=healthy, 1=warning, 2=critical + +mkdir -p "$HOME/logs" 2>/dev/null || true +LOCAL_LOG="$HOME/logs/health-check-$(date +%Y%m%d).log" + +# ANSI colors +RED='\033[0;31m' +YELLOW='\033[0;33m' +GREEN='\033[0;32m' +NC='\033[0m' + +WORST_STATE=0 + +echo "--- Morning Health Check $(date) ---" | tee -a "$LOCAL_LOG" + +# Phase 0: Disk usage +echo "[Phase 0] Checking disk usage..." | tee -a "$LOCAL_LOG" +DISK_PCT=$(df / | awk 'NR==2 {gsub(/%/, ""); print $5}') +echo " Root partition: ${DISK_PCT}% used" | tee -a "$LOCAL_LOG" +if [ "$DISK_PCT" -ge 90 ]; then + echo -e " ${RED}CRITICAL: Disk at ${DISK_PCT}%${NC}" | tee -a "$LOCAL_LOG" + WORST_STATE=2 +elif [ "$DISK_PCT" -ge 80 ]; then + echo -e " ${YELLOW}WARNING: Disk at ${DISK_PCT}%${NC}" | tee -a "$LOCAL_LOG" + [ "$WORST_STATE" -lt 1 ] && WORST_STATE=1 +else + echo -e " ${GREEN}OK${NC}" | tee -a "$LOCAL_LOG" +fi + +# Phase 1: Git status +echo "[Phase 1] Checking workspace git status..." | tee -a "$LOCAL_LOG" +WORKSPACE="$HOME/internal/mw-pfeddersheim-workstation" +if [ -d "$WORKSPACE/.git" ]; then + GIT_DIRTY=$(git -C "$WORKSPACE" status --porcelain || true) + if [ -z "$GIT_DIRTY" ]; then + echo -e " ${GREEN}Clean${NC}" | tee -a "$LOCAL_LOG" + else + echo -e " ${YELLOW}Dirty (${#GIT_DIRTY} changes)${NC}" | tee -a "$LOCAL_LOG" + echo "$GIT_DIRTY" | head -5 | tee -a "$LOCAL_LOG" + [ "$WORST_STATE" -lt 1 ] && WORST_STATE=1 + fi +else + echo " Workspace not found at $WORKSPACE" | tee -a "$LOCAL_LOG" +fi + +# Phase 2: Docker & Uptime +echo "[Phase 2] Checking services..." | tee -a "$LOCAL_LOG" +if command -v docker &> /dev/null; then + RUNNING=$(docker ps --format "{{.Names}}" 2>/dev/null | wc -l) + echo " Docker: ${RUNNING} container(s) running" | tee -a "$LOCAL_LOG" +else + echo " Docker: not installed" | tee -a "$LOCAL_LOG" +fi +echo " Uptime: $(uptime -p)" | tee -a "$LOCAL_LOG" + +echo "--- Health Check Finished $(date) ---" | tee -a "$LOCAL_LOG" +exit "$WORST_STATE" \ No newline at end of file