mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-13 17:50:48 +01:00
1225 lines down to 202, with the 21 functions moved into eight sourced libraries grouped by subject. The entry script now holds only the configuration, the argument parsing and the order the checks run in. check_hosts was the one function that could not move verbatim: at 260 lines it would have stayed over the cap on its own, so its repair half is now hosts_fix_nsswitch / hosts_fix_resolved / hosts_repair_all in services_hosts_fix.sh. Repair order is preserved (resolver config, then the hosts file, then the guard-lib migration), and hosts_repair_all returns non-zero under --dry-run so a dry run can no longer promote a status to "ok" on the strength of repairs that never happened. SERVICE_STATUS was a write-only global across five libs, which is a real SC2034 rather than noise: the pre-commit hook runs shellcheck with no -x and genuinely cannot see the one reader. It now goes through set_service_status / get_service_status, which also rejects a duplicate write — each check owns exactly one summary row, so a second write means two checks are fighting over it. No suppression was added anywhere. Proof the behaviour is unchanged: `--status --dry-run` run as root against this machine is byte-identical to the same command from a worktree at the pre-split revision, modulo the Date: line. verify_shell_split.sh reports check_hosts as the single expected difference; the other 20 functions hash identically. 72 assertions across three test files pass, with 100% line coverage on services_common.sh (54/54) and services_report.sh (27/27). services_units.sh measures 84.51% (60/71). The 11 uncovered lines are the else-branches of [[ -f /etc/systemd/system/*.service ]] and [[ -f /usr/local/bin/*.sh ]] probes — absolute root-owned paths that exist on this machine and that no PATH shim can redirect. Reaching them needs a root-prefix rewrite of live enforcement logic, which is not a line-count fix and would forfeit the verbatim-move proof for everything else. Found while testing, deliberately NOT fixed here: in all three unit checks the is-active branch assigns status="warning" unconditionally, overwriting the status="error" the is-enabled branch set just above it. A timer that is both disabled and inactive therefore never gets repaired, because report_and_fix only repairs on "error". It is identical in the pre-split file, so this split neither caused nor hides it. The tests pin the current behaviour and name it; fixing it changes enforcement and earns its own commit. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F3PzGc75gBcdxP3PkHXGcV
75 lines
2.4 KiB
Bash
Executable File
75 lines
2.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# lib/services_report.sh — usage text and the end-of-run status summary table.
|
|
#
|
|
# Sourced by check_and_enable_services.sh. Reads SERVICE_STATUS, ISSUES_FOUND,
|
|
# FIXES_APPLIED, DRY_RUN, STATUS_ONLY and the colour globals from the caller.
|
|
|
|
usage() {
|
|
cat <<'EOF'
|
|
Check and Enable Digital Wellbeing Services
|
|
============================================
|
|
|
|
Usage: sudo ./check_and_enable_services.sh [options]
|
|
|
|
Options:
|
|
--dry-run Show what would be done without making changes
|
|
--status Only show status, don't enable anything
|
|
-h, --help Show this help message
|
|
|
|
Services checked:
|
|
1. Pacman wrapper - Policy-aware pacman wrapper with friction mechanics
|
|
2. Midnight shutdown - Day-specific automatic shutdown timer
|
|
3. Startup monitor - PC startup time monitoring service
|
|
4. Periodic systems - Hourly maintenance timer and hosts monitor
|
|
5. Hosts and guards - /etc/hosts blocking and protection layers
|
|
6. Compulsive blocker - Limits messaging apps to one launch per hour
|
|
7. Thorium startup - Auto-launch Thorium with Fitatu on boot
|
|
8. LeechBlock - Browser extension for site blocking
|
|
9. Guest mode removal - Disable Chromium guest mode via policy
|
|
10. VirtualBox hosts - Enforce /etc/hosts inside VMs
|
|
11. Workout lock screen - Requires workout logging to unlock screen (user service)
|
|
EOF
|
|
}
|
|
|
|
print_summary() {
|
|
header "Summary"
|
|
|
|
echo ""
|
|
printf "%-25s %s\n" "Service" "Status"
|
|
printf "%-25s %s\n" "-------" "------"
|
|
|
|
for service in pacman_wrapper makepkg_wrapper midnight_shutdown startup_monitor periodic_systems hosts compulsive_blocker leechblock guest_mode_removal vbox_hosts workout_locker; do
|
|
local status
|
|
status="$(get_service_status "$service")"
|
|
local color
|
|
case "$status" in
|
|
ok) color=$GREEN ;;
|
|
warning) color=$YELLOW ;;
|
|
error) color=$RED ;;
|
|
"n/a" | skipped) color=$BLUE ;;
|
|
*) color=$NC ;;
|
|
esac
|
|
printf "%-25s ${color}%s${NC}\n" "$service" "$status"
|
|
done
|
|
|
|
echo ""
|
|
if [[ $DRY_RUN -eq 1 ]]; then
|
|
note "DRY RUN - No changes were made"
|
|
fi
|
|
|
|
if [[ $ISSUES_FOUND -eq 0 ]]; then
|
|
msg "All services are properly configured!"
|
|
else
|
|
if [[ $STATUS_ONLY -eq 1 ]]; then
|
|
warn "Found $ISSUES_FOUND service(s) with issues"
|
|
note "Run without --status to fix issues"
|
|
else
|
|
if [[ $FIXES_APPLIED -gt 0 ]]; then
|
|
msg "Applied $FIXES_APPLIED fix(es)"
|
|
else
|
|
warn "Found $ISSUES_FOUND issue(s) but no fixes were applied"
|
|
fi
|
|
fi
|
|
fi
|
|
}
|