feat: one-time sudo at start with background keep-alive, no more password prompts
This commit is contained in:
@@ -229,6 +229,9 @@ main() {
|
|||||||
log_info "Log file: $OMERON_LOG_FILE"
|
log_info "Log file: $OMERON_LOG_FILE"
|
||||||
log_info "Project: $OMERON_ROOT"
|
log_info "Project: $OMERON_ROOT"
|
||||||
|
|
||||||
|
sudo_init
|
||||||
|
trap 'sudo_cleanup' EXIT
|
||||||
|
|
||||||
detect_environment
|
detect_environment
|
||||||
|
|
||||||
show_banner
|
show_banner
|
||||||
|
|||||||
30
lib/utils.sh
30
lib/utils.sh
@@ -32,9 +32,39 @@ is_root() {
|
|||||||
[[ "$EUID" -eq 0 ]]
|
[[ "$EUID" -eq 0 ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OMERON_SUDO_PID=""
|
||||||
|
|
||||||
|
OMERON_SUDO_PID=""
|
||||||
|
|
||||||
|
sudo_init() {
|
||||||
|
if is_root; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
tui_info "Sudo access needed — enter your password once"
|
||||||
|
sudo -v || {
|
||||||
|
tui_error "Sudo authentication failed"
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
(
|
||||||
|
while true; do
|
||||||
|
sleep 240
|
||||||
|
sudo -v 2>/dev/null || break
|
||||||
|
done
|
||||||
|
) &
|
||||||
|
OMERON_SUDO_PID=$!
|
||||||
|
}
|
||||||
|
|
||||||
|
sudo_cleanup() {
|
||||||
|
[[ -n "$OMERON_SUDO_PID" ]] && kill "$OMERON_SUDO_PID" 2>/dev/null || true
|
||||||
|
}
|
||||||
|
|
||||||
sudo_run() {
|
sudo_run() {
|
||||||
if is_root; then
|
if is_root; then
|
||||||
"$@"
|
"$@"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
if [[ -n "${OMERON_SUDO_PID:-}" ]] && kill -0 "$OMERON_SUDO_PID" 2>/dev/null; then
|
||||||
|
sudo -n "$@"
|
||||||
else
|
else
|
||||||
sudo "$@"
|
sudo "$@"
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user