From 45a713cfc547eaa27bd2dd9df87cfef42e974605 Mon Sep 17 00:00:00 2001 From: mason Date: Fri, 6 Nov 2026 10:41:57 -0600 Subject: [PATCH] require sudo for -r, remove hardcoded password --- sysop | 46 +++++++++------------------------------------- 1 file changed, 9 insertions(+), 37 deletions(-) diff --git a/sysop b/sysop index 65fe1fb..5d9d4b0 100755 --- a/sysop +++ b/sysop @@ -2,8 +2,6 @@ # GNU GPL v3 2025 K9BFF - -# gots 2 make sure su_check() { if [[ $EUID -ne 0 ]]; then echo "sysop: needs to be run as sudo..." @@ -11,35 +9,22 @@ su_check() { fi } - - -# inverse sudo check because i found a bug last night inv_su_check() { - if [[ $EUID -ne 0 ]]; then - : - else - echo "sysop: don't run this flag as sudo!" - exit 1 - fi + if [[ $EUID -eq 0 ]]; then + echo "sysop: don't run this flag as sudo!" + exit 1 + fi } - - -# rebuild if [[ $1 == "-r" ]]; then - inv_su_check - update-dotfiles - sudo nixos-rebuild switch |& nom + su_check + update-dotfiles + nixos-rebuild switch |& nom - -# upgrade elif [[ $1 == "-u" ]]; then su_check nixos-rebuild switch --upgrade |& nom - - -# garbage collection elif [[ $1 == "-d" ]]; then su_check read -p "sysop: garbage collection: are you sure? (y/N): " yesno @@ -50,25 +35,15 @@ elif [[ $1 == "-d" ]]; then exit 1 fi - - -# nix-shell elif [[ $1 == "-p" ]]; then - inv_su_check + inv_su_check nix-shell -p "$2" |& nom - - -# search elif [[ $1 == "-s" ]]; then - inv_su_check + inv_su_check nix-search "$2" - - -# help elif [[ $1 == "-h" ]]; then - inv_su_check echo "sysop: system operations" echo echo "flag operation" @@ -79,9 +54,6 @@ elif [[ $1 == "-h" ]]; then echo "-s Search" echo "-h Display this help" - - -# bad flag detector else echo "sysop: $1: not a valid flag. Please see sysop -h for more information." exit 1