Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions bin/manjikaze
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,16 @@ show_header() {
}

main() {
# Ensure the sudo keep-alive is always cleaned up, even on unexpected exit.
trap 'stop_sudo_keepalive' EXIT

if [[ "$1" == "update" ]]; then
clear
show_header

status "Requesting administrator privileges for system commands..."
sudo -v
(while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &)
start_sudo_keepalive

# First update manjikaze itself
check_updates "$@"
Expand All @@ -116,7 +119,7 @@ main() {

status "Requesting administrator privileges for system commands..."
sudo -v
(while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &)
start_sudo_keepalive

check_updates "$@"

Expand All @@ -126,10 +129,14 @@ main() {

run_audits || status "Audit check/run finished with errors or cancellation."

# Stop the keep-alive before entering the interactive menu.
stop_sudo_keepalive

clear
show_header

handle_menu menu "Main Menu"
}

main "$@"

16 changes: 16 additions & 0 deletions lib/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ enable_sleep() {
fi
}

start_sudo_keepalive() {
if [[ -n "${_SUDO_KEEPALIVE_PID:-}" ]] && kill -0 "$_SUDO_KEEPALIVE_PID" 2>/dev/null; then
return 0 # Already running
fi
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
_SUDO_KEEPALIVE_PID=$!
}

stop_sudo_keepalive() {
if [[ -n "${_SUDO_KEEPALIVE_PID:-}" ]]; then
kill "$_SUDO_KEEPALIVE_PID" 2>/dev/null || true
wait "$_SUDO_KEEPALIVE_PID" 2>/dev/null || true
unset _SUDO_KEEPALIVE_PID
fi
}

activate_zsh_plugin() {
local plugin="$1"
local zshrc="$HOME/.zshrc"
Expand Down