mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-11 13:47:47 +01:00
Two levels of pure taxonomy carrying no information, and a 2-directory
cap leaves no room for them. Categories now sit directly under
linux_configuration/: features, fixes, utils, misc, fresh-install,
installers, diagnostics, gaming, boot_recovery, periodic_background, lib,
meta, tests. A script's own lib/ and tests/ are exempt from the cap, so
those stay put.
Depth violations 248 -> 139; roughly 40 of the remainder are inside
digital_wellbeing and hosts, deferred until the guard-lib repoint.
The moves are the easy half. What breaks is every path that counted
levels, and three classes of it had to be found by resolving paths rather
than reading diffs:
- 52 relative `source` lines for lib/common.sh and lib/android.sh. The
correct prefix differs per file: 40 were ../../ and 12 were ../../../,
so a blanket replace would have fixed one set and broken the other.
- REPO_ROOT in 7 fixes/lib/tests harnesses and setup_syncyomi_guard.sh,
each walking up four levels from a directory now two levels shallower.
This caused a real regression -- the fixes suite went red with
"log_warn: command not found" -- caught by running it and comparing
against the pre-move baseline worktree.
- conftest.py's sys.path entries, which took the pytest gate down with
14 collection errors, and the `# shellcheck source=` directives, which
took shellcheck down with SC1091.
16 symlinks in $HOME broke, including the entire i3blocks bar. All
repointed, and cpu_monitor/memory/disk/time/volume were run to confirm
they emit real output rather than merely resolving.
Verified: 1798 tests pass at 100% coverage, 8 of 9 lib/tests suites pass
(the ninth needs the coverage jail, identically at baseline), pre-commit
is clean, and the two untracked secret configs are still ignored after
their gitignore paths changed.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PJrqKERAo5QUeEHWS5Asgp
128 lines
5.2 KiB
Bash
Executable File
128 lines
5.2 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# ============================================================================
|
|
# setup_night_lockdown.sh
|
|
#
|
|
# Installs the "night lockdown" action that REPLACES the midnight power-off.
|
|
#
|
|
# This machine is a 24/7 home server (Gitea, the Caddy TLS edge, SyncYomi, the
|
|
# personal website, Open WebUI, Joplin, dufs, ollama, dnsmasq, wg-quick@wg0,
|
|
# nftables, sshd). The old digital-wellbeing curfew powered the PC off at night,
|
|
# which also took every server down. Night lockdown keeps the curfew's lockout
|
|
# intent but leaves the machine ON: it tears down the user GUI and masks the
|
|
# TTY login surface so the machine is unusable from the keyboard, while every
|
|
# background server keeps running. At 05:00 a morning timer restores the desktop.
|
|
#
|
|
# The evening/morning SCHEDULE and its anti-tamper guards still live in
|
|
# setup_midnight_shutdown.sh; that script's terminal action is swapped to call
|
|
# night-lockdown-enter.sh instead of powering off. This installer owns only the
|
|
# lock/unlock action and the morning-unlock timer, and is deliberately NOT made
|
|
# immutable so the reversal path can always be iterated and can never be taken
|
|
# down by a bug in the (guarded) lock path.
|
|
#
|
|
# HARD LOCKOUT: the only recovery path once locked is SSH (WireGuard / LAN).
|
|
# `setup_night_lockdown.sh unlock` restores the GUI immediately over SSH.
|
|
#
|
|
# Usage:
|
|
# sudo ./setup_night_lockdown.sh setup # install / re-install (idempotent)
|
|
# ./setup_night_lockdown.sh status # show current state
|
|
# sudo ./setup_night_lockdown.sh unlock # emergency: lift lockdown now (SSH)
|
|
# ./setup_night_lockdown.sh help
|
|
# ============================================================================
|
|
|
|
set -euo pipefail
|
|
|
|
# shellcheck source=lib/nl_commands.sh
|
|
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/lib/nl_commands.sh"
|
|
|
|
# shellcheck source=lib/nl_config.sh
|
|
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/lib/nl_config.sh"
|
|
|
|
# shellcheck source=lib/nl_units.sh
|
|
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/lib/nl_units.sh"
|
|
|
|
# shellcheck source=lib/nl_unlock.sh
|
|
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/lib/nl_unlock.sh"
|
|
|
|
# shellcheck source=lib/nl_enter.sh
|
|
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/lib/nl_enter.sh"
|
|
|
|
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
|
|
# shellcheck source=../../lib/common.sh
|
|
source "$SCRIPT_DIR/../../lib/common.sh"
|
|
|
|
# --- Installed artifact locations -------------------------------------------
|
|
readonly ENTER_SCRIPT="/usr/local/bin/night-lockdown-enter.sh"
|
|
readonly UNLOCK_SCRIPT="/usr/local/bin/night-lockdown-unlock.sh"
|
|
readonly CONF_FILE="/etc/night-lockdown.conf"
|
|
readonly STATE_DIR="/var/lib/night-lockdown"
|
|
readonly STATE_FILE="$STATE_DIR/state"
|
|
readonly I2C_MODULES_FILE="/etc/modules-load.d/night-lockdown-i2c.conf"
|
|
readonly UNLOCK_SERVICE="/etc/systemd/system/night-lockdown-unlock.service"
|
|
readonly UNLOCK_TIMER="/etc/systemd/system/night-lockdown-unlock.timer"
|
|
readonly RGB_OFF_SERVICE="/etc/systemd/system/rgb-off.service"
|
|
readonly OVERRIDE_MANAGER="/usr/local/bin/shutdown-override-manager.sh"
|
|
# HOME openrgb runs with; must match RGB_HOME in the generated config.
|
|
readonly RGB_HOME_DEFAULT="/root"
|
|
readonly MANAGED_BANNER="# Managed by setup_night_lockdown.sh — do not edit by hand."
|
|
|
|
# =============================================================================
|
|
# Hardware / environment detection (run at install time, written into the conf)
|
|
# =============================================================================
|
|
|
|
# =============================================================================
|
|
# The lock action — installed to $ENTER_SCRIPT
|
|
# =============================================================================
|
|
|
|
# =============================================================================
|
|
# The reversal — installed to $UNLOCK_SCRIPT
|
|
# =============================================================================
|
|
|
|
# =============================================================================
|
|
# Morning-unlock systemd timer family (outside the shutdown fortress)
|
|
# =============================================================================
|
|
|
|
install_i2c_modules() {
|
|
log_info "Installing i2c module-load for future RGB support"
|
|
cat >"$I2C_MODULES_FILE" <<EOF
|
|
$MANAGED_BANNER
|
|
# SMBus/i2c so OpenRGB can eventually reach motherboard/RAM RGB controllers.
|
|
i2c-dev
|
|
i2c-piix4
|
|
EOF
|
|
chmod 0644 "$I2C_MODULES_FILE"
|
|
# Load now too (harmless if already loaded); ignore failure on odd hardware.
|
|
modprobe i2c-dev 2>/dev/null || true
|
|
modprobe i2c-piix4 2>/dev/null || true
|
|
}
|
|
|
|
# =============================================================================
|
|
# Install verification
|
|
# =============================================================================
|
|
|
|
# =============================================================================
|
|
# Subcommands
|
|
# =============================================================================
|
|
|
|
main() {
|
|
local cmd="${1:-setup}"
|
|
# Elevate BEFORE shifting so the subcommand survives the sudo re-exec.
|
|
case "$cmd" in
|
|
setup | unlock) require_root "$@" ;;
|
|
esac
|
|
shift || true
|
|
case "$cmd" in
|
|
setup) cmd_setup "$@" ;;
|
|
status) cmd_status "$@" ;;
|
|
unlock) cmd_unlock "$@" ;;
|
|
help | -h | --help) usage ;;
|
|
*)
|
|
log_error "Unknown command: $cmd"
|
|
usage
|
|
exit 1
|
|
;;
|
|
esac
|
|
}
|
|
|
|
main "$@"
|