diff --git a/README.md b/README.md index 81488ab..7c43ca6 100644 --- a/README.md +++ b/README.md @@ -303,6 +303,7 @@ Install method priority: **git+cargo source build** (fish) → **cargo** (other | `screensleep` | Turn off the display via KDE PowerDevil | | `wake-lock ` | Run a command with `systemd-inhibit` to prevent sleep | | `swapstat` | Colorized zRAM compression ratio, swappiness, and swap priority report | +| `sudo-toggle` | Toggle sudo password bypass — writes/clears a `NOPASSWD` rule in `/etc/sudoers.d/nofail-toggle` | | `tmux-clean` | Kill all detached tmux sessions | | `limine-edit` | Safely edit and re-verify Limine bootloader configuration | | `sbver` | Verify bootloader signing status for Secure Boot | diff --git a/functions/sudo-toggle.fish b/functions/sudo-toggle.fish new file mode 100644 index 0000000..8d90e7c --- /dev/null +++ b/functions/sudo-toggle.fish @@ -0,0 +1,16 @@ +function sudo-toggle --description 'Toggle sudo password requirement on/off' + # Check the file size using sudo stat to see if our bypass rule is active + set -l file_size (sudo stat -c %s /etc/sudoers.d/nofail-toggle 2>/dev/null) + + if test -n "$file_size"; and test "$file_size" -gt 0 + # 1. Toggle is currently OFF (Bypass is active). We want to turn security back ON. + # We use 'sudo -k' to clear the execution cache so it locks down instantly. + sudo -k truncate -s 0 /etc/sudoers.d/nofail-toggle + echo "🔒 Sudo security: ENABLED (FIDO Key required)" + else + # 2. Toggle is currently ON (Security active). We want to BYPASS it. + # We write a high-priority user-specific NOPASSWD rule. + echo "$USER ALL=(ALL:ALL) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/nofail-toggle > /dev/null + echo "🔓 Sudo security: DISABLED (Bypass active)" + end +end