mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-24 15:26:17 +01:00
Compare commits
No commits in common. "cc2fcc44d373d9151dc448ffdc957de8fdda87e6" and "daa712a122efd957485a15d2e8cdd3feb733461e" have entirely different histories.
cc2fcc44d3
...
daa712a122
@ -1,27 +0,0 @@
|
||||
{
|
||||
"intent": "check_and_enable_services.sh reported red 'error' for services that were healthy, and still tracked a service the author no longer uses. Make its report truthful: fix the workout-locker paths left behind by the screen-locker repo extraction, fix user-service queries that could never work from root, and drop thesis_tracker.",
|
||||
"scope": [
|
||||
"linux_configuration/scripts/periodic_background/check_and_enable_services.sh",
|
||||
"Non-goals: focus_mode and guest_mode_removal (their 'error' status is GENUINE — focus-mode.service is not-found and the guest-mode policies are absent); installing/enabling anything"
|
||||
],
|
||||
"changes": [
|
||||
"workout_locker paths: pointed at ~/screen-locker (install_systemd.sh, screen_locker/screen_lock.py) instead of the monorepo python_pkg/screen_locker/ path, which stopped existing when screen-locker was extracted to its own repo. The real user's home is resolved via SUDO_USER + getent, since the script re-execs itself under sudo ($HOME would be /root).",
|
||||
"Added user_systemctl(): queries a USER unit from root via `systemctl --user --machine=<user>@.host`. The previous `sudo -u <user> systemctl --user ...` has no XDG_RUNTIME_DIR/DBUS_SESSION_BUS_ADDRESS, so it always failed with 'Failed to connect to user scope bus' and reported EVERY user service as not-enabled. Rerouted all 6 call sites (focus-mode x2, thorium x1, workout-locker x3).",
|
||||
"Removed thesis_tracker entirely (variable, check function, main() call, summary row, help entry) — the author does not use it; the unit was not-found and the tracker script was never installed. Renumbered the help list."
|
||||
],
|
||||
"verification": [
|
||||
{
|
||||
"command": "systemctl --user is-enabled/is-active workout-locker.service (as the user) vs the checker's report; sudo bash check_and_enable_services.sh --status; bash -n; shellcheck --severity=warning",
|
||||
"result": "pass",
|
||||
"evidence": "Ground truth as kuhy: workout-locker.service enabled+active; focus-mode.service not-found. Before: checker said 'workout-locker.service is not enabled' (false) and screen_lock.py missing. After: workout_locker reports ok with all three checks ✓ (screen_lock.py exists at ~/screen-locker/screen_locker/screen_lock.py, enabled, active); thesis_tracker gone from the summary; focus_mode/guest_mode_removal still correctly error. exit 0; parse OK; shellcheck clean."
|
||||
}
|
||||
],
|
||||
"risks": [
|
||||
"user_systemctl relies on systemd-machined / --machine=<user>@.host; if that is unavailable the user-service checks degrade to reporting not-enabled again (the previous behaviour).",
|
||||
"The workout-locker path assumes the extracted repo is checked out at ~/screen-locker; if it moves, the check reports missing (now loudly, via err_missing_script)."
|
||||
],
|
||||
"rollback": [
|
||||
"git revert the commit.",
|
||||
"Validate after rollback: check_and_enable_services --status again reports workout_locker as error despite the service being enabled+active."
|
||||
]
|
||||
}
|
||||
@ -1,26 +0,0 @@
|
||||
{
|
||||
"intent": "setup_hosts_guard.sh aborted partway on every run under `set -euo pipefail`, silently leaving the hosts guards half-configured or disabled. hosts-guard.path, hosts-bind-mount.service and nsswitch-guard.path were installed 2026-02-02 but disabled, and resolved-guard.path/enforce-resolved.sh were never installed at all — so /etc/hosts had no watcher to restore it if tampered. Make the installer run to completion so all four guards actually get enabled.",
|
||||
"scope": [
|
||||
"linux_configuration/scripts/periodic_background/hosts/guard/setup_hosts_guard.sh",
|
||||
"Non-goals: blocklist content, dnsmasq config, the other drifted services (thesis_tracker, focus_mode, guest_mode_removal, workout_locker) which the author will repair separately"
|
||||
],
|
||||
"changes": [
|
||||
"Added `|| true` to the ReadEtcHosts and DNSOverTLS detection assignments. grep exits 1 when a key is absent; with set -euo pipefail that aborted the whole script — silently skipping the very fix-if-missing branch below it. DNSOverTLS is absent from a default resolved.conf, so the run died there on EVERY invocation, right before resolved-guard.path was enabled. (check_and_enable_services.sh already guarded its copy of the same grep with `|| true`; this brings the installer in line.)",
|
||||
"Guarded the final `systemctl restart systemd-resolved`: systemd-resolved is MASKED on this host (dnsmasq serves DNS), so restarting it failed and set -e aborted the script on its last step — after everything was already configured, making a successful run report failure. Now skips with a note when resolved is masked/disabled."
|
||||
],
|
||||
"verification": [
|
||||
{
|
||||
"command": "sudo bash setup_hosts_guard.sh; systemctl is-enabled/is-active for the four guard units; getent ahosts on blocked domains; bash -n + shellcheck --severity=warning",
|
||||
"result": "pass",
|
||||
"evidence": "Before: exit 1, resolved-guard.path disabled/inactive, nsswitch-guard.path failed (unit-start-limit-hit). After: exit 0, and hosts-guard.path / hosts-bind-mount.service / nsswitch-guard.path / resolved-guard.path are all enabled+active. DNS still resolves (dnsmasq untouched); getent ahosts doubleclick.net / googlesyndication.com / facebook.com all return 0.0.0.0; /etc/hosts still immutable with 176888 lines. parse OK, shellcheck clean."
|
||||
}
|
||||
],
|
||||
"risks": [
|
||||
"The guards are now actually live: /etc/hosts has a read-only bind mount and a path watcher that reverts edits, and nsswitch.conf/resolved.conf are enforced against canonical snapshots. Editing those files now requires the documented unlock path (sudo unlock-hosts) or `setup_hosts_guard.sh --uninstall`.",
|
||||
"nsswitch-guard hit 'unit-start-limit-hit' once during the first run (the enforcement rewrites the file it watches, re-triggering itself). It settled to active, but a rapid drift/restore cycle could trip systemd's start limit again."
|
||||
],
|
||||
"rollback": [
|
||||
"sudo bash setup_hosts_guard.sh --uninstall (disables the units and removes them; canonical snapshots are left in place).",
|
||||
"Validate after rollback: the four units are gone/disabled, /etc/hosts is no longer bind-mounted (findmnt /etc/hosts is empty), and DNS still resolves."
|
||||
]
|
||||
}
|
||||
@ -1,34 +0,0 @@
|
||||
{
|
||||
"intent": "Make periodic-maintenance and self-repair failures impossible to miss. Both tools swallowed failures: execute_with_log appended one line to a log nobody reads and returned 0, so the systemd oneshot reported SUCCESS; check_and_enable_services printed one err line among ~100 and exited 0. That combination is why the 2026-05-15 repo reorg silently killed the pacman-wrapper and hosts self-repair for five months with zero visible symptoms — check_hosts detected the disabled hosts guards on every run, failed to find setup_hosts_guard.sh at the stale $CONFIG_DIR/hosts path, and still exited 0.",
|
||||
"scope": [
|
||||
"linux_configuration/scripts/periodic_background/system-maintenance/bin/periodic-system-maintenance.sh (driver template)",
|
||||
"linux_configuration/scripts/periodic_background/check_and_enable_services.sh",
|
||||
"Non-goals: enabling the currently-disabled hosts guards (separate decision); the author's in-flight night-lockdown WIP in setup_midnight_shutdown.sh"
|
||||
],
|
||||
"changes": [
|
||||
"Driver: added fail_loudly() -> journal at ERROR priority via `logger -p user.err`; collects ALL failures instead of aborting on the first; on any failure writes /var/lib/periodic-system-maintenance/LAST_RUN_FAILED, sends a critical desktop notification (-t 0, never auto-dismisses) to the graphical user via their session bus, and exits 1 so systemd marks the oneshot FAILED (visible in `systemctl --failed` and the timer status) instead of green.",
|
||||
"Driver: `bash script || rc=$?` so set -e cannot abort the run and every step is still attempted/reported.",
|
||||
"check_and_enable_services: added err_missing_script() which records + logs at journal ERROR priority; rerouted all 12 'script not found' err() call sites to it; added a terminal banner and `exit 2` when any repair script is missing (a missing repair script means the tool itself is broken).",
|
||||
"Healthy runs still exit 0 and clear the breadcrumb."
|
||||
],
|
||||
"verification": [
|
||||
{
|
||||
"command": "driver template substituted with nonexistent script paths, temp-redirected LOG_FILE/STATE_DIR, run directly",
|
||||
"result": "pass",
|
||||
"evidence": "exit 1; stderr listed all 3 failures; /state/LAST_RUN_FAILED contained all 3; `journalctl -t periodic-system-maintenance -p err` showed 3 FAILURE entries. All four signals fired."
|
||||
},
|
||||
{
|
||||
"command": "sudo bash setup_periodic_system.sh; sudo /usr/local/bin/periodic-system-maintenance.sh; sudo bash check_and_enable_services.sh --status; shellcheck --severity=warning",
|
||||
"result": "pass",
|
||||
"evidence": "live driver regenerated with the loud code; healthy run rc=0 with all 3 steps ✓ and no breadcrumb; checker rc=0 with no banner; shellcheck clean; bash -n clean."
|
||||
}
|
||||
],
|
||||
"risks": [
|
||||
"The hourly oneshot will now genuinely FAIL (red in systemctl --failed) when a repair script is missing or a repair errors — that is the intent, but it makes previously-invisible breakage visible and may surface pre-existing failures.",
|
||||
"notify_user targets the first graphical session from `loginctl list-sessions`; on a headless boot it silently no-ops (the journal/exit-code/breadcrumb signals still fire)."
|
||||
],
|
||||
"rollback": [
|
||||
"git revert the commit and re-run `sudo bash setup_periodic_system.sh` to regenerate the previous (silent) driver.",
|
||||
"Validate after rollback: /usr/local/bin/periodic-system-maintenance.sh no longer contains fail_loudly; the unit reports success again regardless of failures."
|
||||
]
|
||||
}
|
||||
@ -38,26 +38,15 @@ PERIODIC_SYSTEM_SCRIPT="$CONFIG_DIR/scripts/periodic_background/setup_periodic_s
|
||||
HOSTS_INSTALL_SCRIPT="$CONFIG_DIR/scripts/periodic_background/hosts/install.sh"
|
||||
HOSTS_GUARD_SCRIPT="$CONFIG_DIR/scripts/periodic_background/hosts/guard/setup_hosts_guard.sh"
|
||||
HOSTS_PACMAN_HOOKS_SCRIPT="$CONFIG_DIR/scripts/periodic_background/hosts/guard/install_pacman_hooks.sh"
|
||||
THESIS_TRACKER_SCRIPT="$CONFIG_DIR/scripts/periodic_background/digital_wellbeing/setup_thesis_work_tracker.sh"
|
||||
FOCUS_MODE_SCRIPT="$CONFIG_DIR/scripts/periodic_background/digital_wellbeing/install_focus_mode_daemon.sh"
|
||||
COMPULSIVE_BLOCK_SCRIPT="$CONFIG_DIR/scripts/periodic_background/digital_wellbeing/block_compulsive_opening.sh"
|
||||
THORIUM_STARTUP_SCRIPT="$CONFIG_DIR/scripts/single_use/setup_thorium_startup.sh"
|
||||
LEECHBLOCK_SCRIPT="$CONFIG_DIR/scripts/periodic_background/digital_wellbeing/install_leechblock.sh"
|
||||
REMOVE_GUEST_MODE_SCRIPT="$CONFIG_DIR/scripts/periodic_background/digital_wellbeing/remove_guest_mode.sh"
|
||||
VBOX_HOSTS_SCRIPT="$CONFIG_DIR/scripts/periodic_background/digital_wellbeing/virtualbox/enforce_vbox_hosts.sh"
|
||||
# screen-locker was EXTRACTED out of this monorepo into its own repo
|
||||
# (github.com/kuhyx/screen-locker, checked out at ~/screen-locker), so these
|
||||
# paths deliberately live outside testsAndMisc. They used to point at
|
||||
# python_pkg/screen_locker/, which stopped existing at extraction time — the
|
||||
# result was check_workout_locker reporting a red "error" for a service that was
|
||||
# installed and enabled the whole time, while its "fix" silently did nothing.
|
||||
# Resolve the invoking user's home: this script re-execs itself via sudo, so
|
||||
# $HOME would be /root here.
|
||||
REAL_USER="${SUDO_USER:-${USER:-$(id -un)}}"
|
||||
REAL_HOME="$(getent passwd "$REAL_USER" 2>/dev/null | cut -d: -f6)"
|
||||
[[ -n $REAL_HOME ]] || REAL_HOME="/home/$REAL_USER"
|
||||
WORKOUT_LOCKER_REPO="$REAL_HOME/screen-locker"
|
||||
WORKOUT_LOCKER_INSTALL_SCRIPT="$WORKOUT_LOCKER_REPO/install_systemd.sh"
|
||||
WORKOUT_LOCKER_SCRIPT="$WORKOUT_LOCKER_REPO/screen_locker/screen_lock.py"
|
||||
WORKOUT_LOCKER_INSTALL_SCRIPT="$(dirname "$CONFIG_DIR")/python_pkg/screen_locker/install_systemd.sh"
|
||||
WORKOUT_LOCKER_SCRIPT="$(dirname "$CONFIG_DIR")/python_pkg/screen_locker/screen_lock.py"
|
||||
|
||||
######################################################################
|
||||
# Helpers
|
||||
@ -68,33 +57,6 @@ warn() { printf "${YELLOW}[!]${NC} %s\n" "$*"; }
|
||||
err() { printf "${RED}[✗]${NC} %s\n" "$*"; }
|
||||
header() { printf "\n${CYAN}=== %s ===${NC}\n" "$*"; }
|
||||
|
||||
# A MISSING repair script means THIS TOOL is broken: it silently stops repairing
|
||||
# the thing it exists to repair. That is exactly how the 2026-05-15 reorg left a
|
||||
# stale $CONFIG_DIR/hosts path here — check_hosts detected the disabled guards
|
||||
# every run, failed to find setup_hosts_guard.sh, printed one line among a
|
||||
# hundred, and still exited 0. Five months of dead self-repair, zero symptoms.
|
||||
# So: record it, log at journal ERROR priority, and exit non-zero with a banner.
|
||||
declare -a MISSING_SCRIPTS=()
|
||||
err_missing_script() {
|
||||
err "$*"
|
||||
logger -t check-and-enable-services -p user.err "MISSING REPAIR SCRIPT: $*"
|
||||
MISSING_SCRIPTS+=("$*")
|
||||
}
|
||||
|
||||
# Query a USER systemd unit from root.
|
||||
# `sudo -u <user> systemctl --user ...` does NOT work here: sudo gives it no
|
||||
# XDG_RUNTIME_DIR / DBUS_SESSION_BUS_ADDRESS, so it cannot reach the user bus and
|
||||
# fails with "Failed to connect to user scope bus via local transport". Every
|
||||
# check using it therefore reported EVERY user service as "not enabled" — a false
|
||||
# error for services that were enabled and running (workout-locker was reported
|
||||
# broken for months while working fine). systemd's own error suggests the fix:
|
||||
# --machine=<user>@.host connects to another user's bus correctly.
|
||||
user_systemctl() { # <user> <systemctl args...>
|
||||
local u="$1"
|
||||
shift
|
||||
systemctl --user --machine="${u}@.host" "$@"
|
||||
}
|
||||
|
||||
run() {
|
||||
if [[ $DRY_RUN -eq 1 ]]; then
|
||||
echo -e "${YELLOW}DRY-RUN:${NC} $*"
|
||||
@ -130,13 +92,14 @@ Services checked:
|
||||
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. Focus mode daemon - Steam/Browser mutual exclusion (user service)
|
||||
7. Compulsive blocker - Limits messaging apps to one launch per hour
|
||||
8. Thorium startup - Auto-launch Thorium with Fitatu on boot
|
||||
9. LeechBlock - Browser extension for site blocking
|
||||
10. Guest mode removal - Disable Chromium guest mode via policy
|
||||
11. VirtualBox hosts - Enforce /etc/hosts inside VMs
|
||||
12. Workout lock screen - Requires workout logging to unlock screen (user service)
|
||||
6. Thesis work tracker - Work quota enforcement with distraction blocking
|
||||
7. Focus mode daemon - Steam/Browser mutual exclusion (user service)
|
||||
8. Compulsive blocker - Limits messaging apps to one launch per hour
|
||||
9. Thorium startup - Auto-launch Thorium with Fitatu on boot
|
||||
10. LeechBlock - Browser extension for site blocking
|
||||
11. Guest mode removal - Disable Chromium guest mode via policy
|
||||
12. VirtualBox hosts - Enforce /etc/hosts inside VMs
|
||||
13. Workout lock screen - Requires workout logging to unlock screen (user service)
|
||||
EOF
|
||||
}
|
||||
|
||||
@ -209,7 +172,7 @@ report_and_fix() {
|
||||
_status="ok"
|
||||
fi
|
||||
else
|
||||
err_missing_script "Setup script not found: $setup_script"
|
||||
err "Setup script not found: $setup_script"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
@ -284,7 +247,7 @@ check_pacman_wrapper() {
|
||||
status="ok"
|
||||
fi
|
||||
else
|
||||
err_missing_script "Installer script not found: $PACMAN_WRAPPER_INSTALL"
|
||||
err "Installer script not found: $PACMAN_WRAPPER_INSTALL"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
@ -363,7 +326,7 @@ check_makepkg_wrapper() {
|
||||
status="ok"
|
||||
fi
|
||||
else
|
||||
err_missing_script "Installer script not found: $MAKEPKG_WRAPPER_INSTALL"
|
||||
err "Installer script not found: $MAKEPKG_WRAPPER_INSTALL"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
@ -807,7 +770,7 @@ check_hosts() {
|
||||
run bash "$HOSTS_INSTALL_SCRIPT"
|
||||
((FIXES_APPLIED++)) || true
|
||||
else
|
||||
err_missing_script "Hosts install script not found: $HOSTS_INSTALL_SCRIPT"
|
||||
err "Hosts install script not found: $HOSTS_INSTALL_SCRIPT"
|
||||
fi
|
||||
fi
|
||||
|
||||
@ -825,7 +788,7 @@ check_hosts() {
|
||||
run bash "$HOSTS_GUARD_SCRIPT"
|
||||
((FIXES_APPLIED++)) || true
|
||||
else
|
||||
err_missing_script "Hosts guard script not found: $HOSTS_GUARD_SCRIPT"
|
||||
err "Hosts guard script not found: $HOSTS_GUARD_SCRIPT"
|
||||
fi
|
||||
fi
|
||||
|
||||
@ -836,7 +799,7 @@ check_hosts() {
|
||||
run bash "$HOSTS_PACMAN_HOOKS_SCRIPT"
|
||||
((FIXES_APPLIED++)) || true
|
||||
else
|
||||
err_missing_script "Pacman hooks script not found: $HOSTS_PACMAN_HOOKS_SCRIPT"
|
||||
err "Pacman hooks script not found: $HOSTS_PACMAN_HOOKS_SCRIPT"
|
||||
fi
|
||||
fi
|
||||
|
||||
@ -862,6 +825,58 @@ check_hosts() {
|
||||
SERVICE_STATUS["hosts"]=$status
|
||||
}
|
||||
|
||||
check_thesis_tracker() {
|
||||
header "Thesis Work Tracker"
|
||||
|
||||
local status="ok"
|
||||
local issues=()
|
||||
local user="${SUDO_USER:-$USER}"
|
||||
|
||||
# Check service
|
||||
if systemctl is-enabled "thesis-work-tracker@${user}.service" &>/dev/null; then
|
||||
msg "thesis-work-tracker@${user}.service is enabled"
|
||||
else
|
||||
issues+=("thesis-work-tracker@${user}.service is not enabled")
|
||||
status="error"
|
||||
fi
|
||||
|
||||
if systemctl is-active "thesis-work-tracker@${user}.service" &>/dev/null; then
|
||||
msg "thesis-work-tracker@${user}.service is active"
|
||||
else
|
||||
issues+=("thesis-work-tracker@${user}.service is not active")
|
||||
if [[ $status != "error" ]]; then status="warning"; fi
|
||||
fi
|
||||
|
||||
# Check tracker script
|
||||
if [[ -f /usr/local/bin/thesis_work_tracker.sh ]]; then
|
||||
msg "Tracker script exists at /usr/local/bin/thesis_work_tracker.sh"
|
||||
else
|
||||
issues+=("thesis_work_tracker.sh not found in /usr/local/bin")
|
||||
status="error"
|
||||
fi
|
||||
|
||||
# Check status script
|
||||
if [[ -f /usr/local/bin/thesis_work_status.sh ]]; then
|
||||
msg "Status script exists at /usr/local/bin/thesis_work_status.sh"
|
||||
else
|
||||
issues+=("thesis_work_status.sh not found in /usr/local/bin")
|
||||
if [[ $status != "error" ]]; then status="warning"; fi
|
||||
fi
|
||||
|
||||
# Check state directory
|
||||
if [[ -d /var/lib/thesis-work-tracker ]]; then
|
||||
msg "State directory exists"
|
||||
else
|
||||
issues+=("State directory /var/lib/thesis-work-tracker missing")
|
||||
status="error"
|
||||
fi
|
||||
|
||||
report_and_fix issues status "thesis_tracker" \
|
||||
"Setting up thesis work tracker..." \
|
||||
"$THESIS_TRACKER_SCRIPT" \
|
||||
"thesis-work-tracker@${user}.service"
|
||||
}
|
||||
|
||||
check_focus_mode() {
|
||||
header "Focus Mode Daemon (Steam/Browser Mutual Exclusion)"
|
||||
|
||||
@ -880,14 +895,14 @@ check_focus_mode() {
|
||||
fi
|
||||
|
||||
# Check user service (must run as actual user)
|
||||
if user_systemctl "$user" is-enabled focus-mode.service &>/dev/null 2>&1; then
|
||||
if sudo -u "$user" systemctl --user is-enabled focus-mode.service &>/dev/null 2>&1; then
|
||||
msg "focus-mode.service is enabled (user service)"
|
||||
else
|
||||
issues+=("focus-mode.service is not enabled (user service)")
|
||||
status="error"
|
||||
fi
|
||||
|
||||
if user_systemctl "$user" is-active focus-mode.service &>/dev/null 2>&1; then
|
||||
if sudo -u "$user" systemctl --user is-active focus-mode.service &>/dev/null 2>&1; then
|
||||
msg "focus-mode.service is active"
|
||||
else
|
||||
issues+=("focus-mode.service is not active")
|
||||
@ -911,7 +926,7 @@ check_focus_mode() {
|
||||
run sudo -u "$user" bash "$FOCUS_MODE_SCRIPT" install
|
||||
((FIXES_APPLIED++)) || true
|
||||
else
|
||||
err_missing_script "Install script not found: $FOCUS_MODE_SCRIPT"
|
||||
err "Install script not found: $FOCUS_MODE_SCRIPT"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
@ -969,7 +984,7 @@ check_compulsive_blocker() {
|
||||
run bash "$COMPULSIVE_BLOCK_SCRIPT" install
|
||||
((FIXES_APPLIED++)) || true
|
||||
else
|
||||
err_missing_script "Install script not found: $COMPULSIVE_BLOCK_SCRIPT"
|
||||
err "Install script not found: $COMPULSIVE_BLOCK_SCRIPT"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
@ -989,7 +1004,7 @@ check_thorium_startup() {
|
||||
else
|
||||
# Check user service as fallback
|
||||
local user="${SUDO_USER:-$USER}"
|
||||
if user_systemctl "$user" is-enabled thorium-fitatu-startup.service &>/dev/null 2>&1; then
|
||||
if sudo -u "$user" systemctl --user is-enabled thorium-fitatu-startup.service &>/dev/null 2>&1; then
|
||||
msg "thorium-fitatu-startup.service is enabled (user service)"
|
||||
else
|
||||
issues+=("thorium-fitatu-startup.service is not enabled")
|
||||
@ -1059,7 +1074,7 @@ check_leechblock() {
|
||||
run sudo -u "$user" bash "$LEECHBLOCK_SCRIPT"
|
||||
((FIXES_APPLIED++)) || true
|
||||
else
|
||||
err_missing_script "Install script not found: $LEECHBLOCK_SCRIPT"
|
||||
err "Install script not found: $LEECHBLOCK_SCRIPT"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
@ -1111,7 +1126,7 @@ check_guest_mode_removal() {
|
||||
run bash "$REMOVE_GUEST_MODE_SCRIPT"
|
||||
((FIXES_APPLIED++)) || true
|
||||
else
|
||||
err_missing_script "Script not found: $REMOVE_GUEST_MODE_SCRIPT"
|
||||
err "Script not found: $REMOVE_GUEST_MODE_SCRIPT"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
@ -1152,7 +1167,7 @@ check_vbox_hosts() {
|
||||
run bash "$VBOX_HOSTS_SCRIPT"
|
||||
((FIXES_APPLIED++)) || true
|
||||
else
|
||||
err_missing_script "Script not found: $VBOX_HOSTS_SCRIPT"
|
||||
err "Script not found: $VBOX_HOSTS_SCRIPT"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
@ -1176,7 +1191,7 @@ check_workout_locker() {
|
||||
fi
|
||||
|
||||
# Check user service is enabled
|
||||
if user_systemctl "$user" is-enabled workout-locker.service &>/dev/null 2>&1; then
|
||||
if sudo -u "$user" systemctl --user is-enabled workout-locker.service &>/dev/null 2>&1; then
|
||||
msg "workout-locker.service is enabled (user service)"
|
||||
else
|
||||
issues+=("workout-locker.service is not enabled (user service)")
|
||||
@ -1184,7 +1199,7 @@ check_workout_locker() {
|
||||
fi
|
||||
|
||||
# Check user service is active (advisory — it only runs at login)
|
||||
if user_systemctl "$user" is-active workout-locker.service &>/dev/null 2>&1; then
|
||||
if sudo -u "$user" systemctl --user is-active workout-locker.service &>/dev/null 2>&1; then
|
||||
msg "workout-locker.service is active"
|
||||
else
|
||||
issues+=("workout-locker.service is not active (expected at login time)")
|
||||
@ -1207,11 +1222,11 @@ check_workout_locker() {
|
||||
run sudo -u "$user" bash "$WORKOUT_LOCKER_INSTALL_SCRIPT"
|
||||
((FIXES_APPLIED++)) || true
|
||||
# Re-verify
|
||||
if [[ $DRY_RUN -eq 0 ]] && user_systemctl "$user" is-enabled workout-locker.service &>/dev/null 2>&1; then
|
||||
if [[ $DRY_RUN -eq 0 ]] && sudo -u "$user" systemctl --user is-enabled workout-locker.service &>/dev/null 2>&1; then
|
||||
status="ok"
|
||||
fi
|
||||
else
|
||||
err_missing_script "Install script not found: $WORKOUT_LOCKER_INSTALL_SCRIPT"
|
||||
err "Install script not found: $WORKOUT_LOCKER_INSTALL_SCRIPT"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
@ -1225,7 +1240,7 @@ print_summary() {
|
||||
printf "%-25s %s\n" "Service" "Status"
|
||||
printf "%-25s %s\n" "-------" "------"
|
||||
|
||||
for service in pacman_wrapper makepkg_wrapper midnight_shutdown startup_monitor periodic_systems hosts focus_mode compulsive_blocker thorium_startup leechblock guest_mode_removal vbox_hosts workout_locker; do
|
||||
for service in pacman_wrapper makepkg_wrapper midnight_shutdown startup_monitor periodic_systems hosts thesis_tracker focus_mode compulsive_blocker thorium_startup leechblock guest_mode_removal vbox_hosts workout_locker; do
|
||||
local status="${SERVICE_STATUS[$service]:-unknown}"
|
||||
local color
|
||||
case "$status" in
|
||||
@ -1282,6 +1297,7 @@ main() {
|
||||
check_startup_monitor
|
||||
check_periodic_systems
|
||||
check_hosts
|
||||
check_thesis_tracker
|
||||
check_focus_mode
|
||||
check_compulsive_blocker
|
||||
check_thorium_startup
|
||||
@ -1294,25 +1310,3 @@ main() {
|
||||
}
|
||||
|
||||
main
|
||||
|
||||
######################################################################
|
||||
# A missing repair script means this tool cannot do the one job it exists for.
|
||||
# Exiting 0 there is indistinguishable from "everything is fine" — which is how
|
||||
# it hid dead hosts self-repair for five months. Make it impossible to miss.
|
||||
######################################################################
|
||||
if [[ ${#MISSING_SCRIPTS[@]} -gt 0 ]]; then
|
||||
printf "\n${RED}"
|
||||
printf '=%.0s' {1..74}
|
||||
printf "\n SELF-REPAIR IS BROKEN — %d repair script(s) MISSING\n" "${#MISSING_SCRIPTS[@]}"
|
||||
printf '=%.0s' {1..74}
|
||||
printf "${NC}\n"
|
||||
for missing in "${MISSING_SCRIPTS[@]}"; do
|
||||
err "$missing"
|
||||
done
|
||||
printf "${RED}The services above are NOT being repaired — this tool found the\n"
|
||||
printf "problem and then could not run the fix. Correct these paths first.${NC}\n"
|
||||
printf "${CYAN}Also logged at error priority: journalctl -p err -t check-and-enable-services${NC}\n\n"
|
||||
exit 2
|
||||
fi
|
||||
|
||||
exit 0
|
||||
|
||||
@ -456,13 +456,8 @@ if [[ $ENABLE_RESOLVED -eq 1 ]]; then
|
||||
|
||||
# Ensure ReadEtcHosts=yes in resolved.conf before snapshotting
|
||||
if [[ -f "$RESOLVED_CONF" ]]; then
|
||||
# `|| true` is REQUIRED: grep exits 1 when the key is absent, and under
|
||||
# `set -euo pipefail` that aborts the whole script — silently skipping the
|
||||
# very fix below that exists to handle the absent case. Without it the
|
||||
# "key missing" branch is unreachable. (check_and_enable_services.sh
|
||||
# already guards its copy of this grep the same way.)
|
||||
local_read_hosts=$(grep -E '^\s*ReadEtcHosts\s*=' "$RESOLVED_CONF" 2>/dev/null |
|
||||
tail -1 | sed 's/.*=\s*//' | tr -d '[:space:]') || true
|
||||
tail -1 | sed 's/.*=\s*//' | tr -d '[:space:]')
|
||||
if [[ "$local_read_hosts" != "yes" ]]; then
|
||||
msg "Fixing ReadEtcHosts in resolved.conf (was: '$local_read_hosts')"
|
||||
chattr -i "$RESOLVED_CONF" 2>/dev/null || true
|
||||
@ -477,12 +472,8 @@ if [[ $ENABLE_RESOLVED -eq 1 ]]; then
|
||||
fi
|
||||
|
||||
# Ensure DNSOverTLS is not set to yes or opportunistic
|
||||
# `|| true`: same trap as above. DNSOverTLS is absent from a default
|
||||
# resolved.conf, so without this the script aborted here on every run —
|
||||
# right before resolved-guard.path was enabled, which is why that guard
|
||||
# was never installed.
|
||||
local_dot=$(grep -E '^\s*DNSOverTLS\s*=' "$RESOLVED_CONF" 2>/dev/null |
|
||||
tail -1 | sed 's/.*=\s*//' | tr -d '[:space:]') || true
|
||||
tail -1 | sed 's/.*=\s*//' | tr -d '[:space:]')
|
||||
if [[ -n "$local_dot" && "$local_dot" != "no" ]]; then
|
||||
msg "Disabling DNSOverTLS in resolved.conf (was: '$local_dot')"
|
||||
chattr -i "$RESOLVED_CONF" 2>/dev/null || true
|
||||
@ -523,16 +514,8 @@ if [[ $ENABLE_RESOLVED -eq 1 ]]; then
|
||||
"$INSTALL_ENFORCE_RESOLVED" || warn "resolved enforcement returned non-zero"
|
||||
fi
|
||||
|
||||
# Restart resolved to pick up corrected config.
|
||||
# systemd-resolved is not necessarily the resolver: on this host it is MASKED
|
||||
# and dnsmasq serves DNS. Restarting a masked unit fails, and under `set -e`
|
||||
# that aborted the script on its very last step — after everything was already
|
||||
# configured, so the run reported failure despite having succeeded.
|
||||
if systemctl is-enabled systemd-resolved.service &>/dev/null; then
|
||||
run systemctl restart systemd-resolved || warn "Failed to restart systemd-resolved"
|
||||
else
|
||||
note "systemd-resolved is masked/disabled — skipping restart (DNS is served elsewhere, e.g. dnsmasq)"
|
||||
fi
|
||||
# Restart resolved to pick up corrected config
|
||||
run systemctl restart systemd-resolved
|
||||
else
|
||||
note "Skipping resolved.conf protection (--skip-resolved)"
|
||||
fi
|
||||
|
||||
@ -1,113 +1,54 @@
|
||||
#!/bin/bash
|
||||
# Periodic system maintenance script
|
||||
# Installs pacman/makepkg wrappers and updates hosts file
|
||||
# Installs pacman wrapper and updates hosts file
|
||||
# This file is installed by setup_periodic_system.sh
|
||||
#
|
||||
# FAILURES ARE LOUD, ON PURPOSE.
|
||||
# This script used to swallow every failure: a missing repair script was one
|
||||
# line appended to a log nobody reads, execute_with_log returned 0, and the
|
||||
# systemd unit therefore reported SUCCESS. That is exactly how a stale path
|
||||
# (from the 2026-05-15 repo reorg) silently disabled the pacman-wrapper and
|
||||
# hosts self-repair for five months without a single visible symptom.
|
||||
#
|
||||
# Any failure now surfaces four ways:
|
||||
# 1. journal at ERROR priority -> journalctl -p err -t periodic-system-maintenance
|
||||
# 2. the systemd unit FAILS -> systemctl --failed / red timer (exit 1 below)
|
||||
# 3. a critical desktop notification that does not auto-dismiss
|
||||
# 4. a breadcrumb file -> /var/lib/periodic-system-maintenance/LAST_RUN_FAILED
|
||||
|
||||
set -e
|
||||
|
||||
LOG_FILE="/var/log/periodic-system-maintenance.log"
|
||||
STATE_DIR="/var/lib/periodic-system-maintenance"
|
||||
FAILURE_FLAG="$STATE_DIR/LAST_RUN_FAILED"
|
||||
|
||||
# Path placeholders replaced at install time
|
||||
PACMAN_WRAPPER_INSTALL="__PACMAN_WRAPPER_INSTALL__"
|
||||
MAKEPKG_WRAPPER_INSTALL="__MAKEPKG_WRAPPER_INSTALL__"
|
||||
HOSTS_INSTALL_SCRIPT="__HOSTS_INSTALL_SCRIPT__"
|
||||
|
||||
declare -a FAILURES=()
|
||||
|
||||
# Function to log with timestamp
|
||||
log_message() {
|
||||
echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" >> "$LOG_FILE"
|
||||
}
|
||||
|
||||
# Record a failure loudly: journal at ERROR priority + collect for the summary.
|
||||
fail_loudly() {
|
||||
local msg="$1"
|
||||
log_message "FAILURE: $msg"
|
||||
echo "✗ $msg" >&2
|
||||
logger -t periodic-system-maintenance -p user.err "FAILURE: $msg"
|
||||
FAILURES+=("$msg")
|
||||
}
|
||||
|
||||
# Desktop notification for the graphical user (this runs as root under systemd,
|
||||
# so we have to reach the user's session bus explicitly).
|
||||
notify_user() {
|
||||
local title="$1" body="$2"
|
||||
command -v notify-send >/dev/null 2>&1 || return 0
|
||||
local target_user target_uid
|
||||
target_user="$(loginctl list-sessions --no-legend 2>/dev/null | awk 'NF {print $3; exit}')"
|
||||
[[ -n $target_user ]] || return 0
|
||||
target_uid="$(id -u "$target_user" 2>/dev/null)" || return 0
|
||||
# -t 0 => never auto-dismiss; the user must acknowledge it.
|
||||
sudo -u "$target_user" \
|
||||
DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$target_uid/bus" \
|
||||
notify-send -u critical -t 0 "$title" "$body" 2>/dev/null || true
|
||||
}
|
||||
|
||||
# Function to execute with logging
|
||||
execute_with_log() {
|
||||
local script_path="$1"
|
||||
local script_name="$2"
|
||||
local rc=0
|
||||
|
||||
log_message "Starting $script_name"
|
||||
echo "Executing $script_name..." >&2
|
||||
|
||||
if [[ ! -f $script_path ]]; then
|
||||
fail_loudly "$script_name: script NOT FOUND at $script_path"
|
||||
return 0
|
||||
fi
|
||||
|
||||
# `|| rc=$?` keeps set -e from aborting so every step still runs and we can
|
||||
# report ALL failures, not just the first.
|
||||
bash "$script_path" >> "$LOG_FILE" 2>&1 || rc=$?
|
||||
if ((rc == 0)); then
|
||||
log_message "$script_name completed successfully"
|
||||
echo "✓ $script_name completed successfully" >&2
|
||||
if [[ -f $script_path ]]; then
|
||||
if bash "$script_path" >> "$LOG_FILE" 2>&1; then
|
||||
log_message "$script_name completed successfully"
|
||||
echo "✓ $script_name completed successfully" >&2
|
||||
else
|
||||
local ec=$?
|
||||
log_message "$script_name failed with exit code $ec"
|
||||
echo "✗ $script_name failed (exit $ec)" >&2
|
||||
fi
|
||||
else
|
||||
fail_loudly "$script_name: FAILED (exit $rc) — see $LOG_FILE"
|
||||
log_message "$script_name not found at $script_path"
|
||||
echo "✗ $script_name not found at $script_path" >&2
|
||||
fi
|
||||
}
|
||||
|
||||
# Start maintenance
|
||||
log_message "=== Periodic System Maintenance Started ==="
|
||||
|
||||
# Install pacman/makepkg wrappers
|
||||
# Install pacman wrapper
|
||||
execute_with_log "$PACMAN_WRAPPER_INSTALL" "Pacman Wrapper Installation"
|
||||
execute_with_log "$MAKEPKG_WRAPPER_INSTALL" "Makepkg Wrapper Installation"
|
||||
|
||||
# Update hosts file
|
||||
execute_with_log "$HOSTS_INSTALL_SCRIPT" "Hosts File Update"
|
||||
|
||||
if ((${#FAILURES[@]} > 0)); then
|
||||
mkdir -p "$STATE_DIR"
|
||||
printf '%s\n' "${FAILURES[@]}" > "$FAILURE_FLAG"
|
||||
log_message "=== Periodic System Maintenance FAILED (${#FAILURES[@]} failure(s)) ==="
|
||||
echo "✗ Periodic system maintenance FAILED with ${#FAILURES[@]} failure(s):" >&2
|
||||
printf ' - %s\n' "${FAILURES[@]}" >&2
|
||||
notify_user "⚠ System maintenance FAILED" \
|
||||
"$(printf '%s\n' "${FAILURES[@]}")
|
||||
|
||||
journalctl -p err -t periodic-system-maintenance"
|
||||
# Non-zero => systemd marks the unit failed, so `systemctl --failed` and the
|
||||
# timer's status show it instead of a green "success".
|
||||
exit 1
|
||||
fi
|
||||
|
||||
rm -f "$FAILURE_FLAG" 2>/dev/null || true
|
||||
log_message "=== Periodic System Maintenance Completed ==="
|
||||
echo "Periodic system maintenance completed. Check $LOG_FILE for details." >&2
|
||||
|
||||
Loading…
Reference in New Issue
Block a user