mirror of
https://github.com/tw93/Mole.git
synced 2026-03-22 20:50:06 +00:00
fix(update): keep sudo session alive during installer run
Start sudo keepalive after authorization and clean it up on all failure/success paths to avoid repeated password prompts and overlapping update UI output. Closes #514.
This commit is contained in:
17
mole
17
mole
@@ -249,7 +249,13 @@ update_mole() {
|
|||||||
local force_update="${1:-false}"
|
local force_update="${1:-false}"
|
||||||
local nightly_update="${2:-false}"
|
local nightly_update="${2:-false}"
|
||||||
local update_interrupted=false
|
local update_interrupted=false
|
||||||
trap 'update_interrupted=true; echo ""; exit 130' INT TERM
|
local sudo_keepalive_pid=""
|
||||||
|
|
||||||
|
# Cleanup function for sudo keepalive
|
||||||
|
_update_cleanup() {
|
||||||
|
[[ -n "$sudo_keepalive_pid" ]] && _stop_sudo_keepalive "$sudo_keepalive_pid" || true
|
||||||
|
}
|
||||||
|
trap '_update_cleanup; update_interrupted=true; echo ""; exit 130' INT TERM
|
||||||
|
|
||||||
if is_homebrew_install; then
|
if is_homebrew_install; then
|
||||||
if [[ "$nightly_update" == "true" ]]; then
|
if [[ "$nightly_update" == "true" ]]; then
|
||||||
@@ -360,6 +366,8 @@ update_mole() {
|
|||||||
rm -f "$tmp_installer"
|
rm -f "$tmp_installer"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
# Start sudo keepalive to prevent cache expiration during install
|
||||||
|
sudo_keepalive_pid=$(_start_sudo_keepalive)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -t 1 ]]; then
|
if [[ -t 1 ]]; then
|
||||||
@@ -411,6 +419,7 @@ update_mole() {
|
|||||||
else
|
else
|
||||||
if [[ -t 1 ]]; then stop_inline_spinner; fi
|
if [[ -t 1 ]]; then stop_inline_spinner; fi
|
||||||
rm -f "$tmp_installer"
|
rm -f "$tmp_installer"
|
||||||
|
_update_cleanup
|
||||||
log_error "Nightly update failed"
|
log_error "Nightly update failed"
|
||||||
echo "$install_output" | tail -10 >&2 # Show last 10 lines of error
|
echo "$install_output" | tail -10 >&2 # Show last 10 lines of error
|
||||||
exit 1
|
exit 1
|
||||||
@@ -421,6 +430,7 @@ update_mole() {
|
|||||||
else
|
else
|
||||||
if [[ -t 1 ]]; then stop_inline_spinner; fi
|
if [[ -t 1 ]]; then stop_inline_spinner; fi
|
||||||
rm -f "$tmp_installer"
|
rm -f "$tmp_installer"
|
||||||
|
_update_cleanup
|
||||||
log_error "Update failed"
|
log_error "Update failed"
|
||||||
echo "$install_output" | tail -10 >&2 # Show last 10 lines of error
|
echo "$install_output" | tail -10 >&2 # Show last 10 lines of error
|
||||||
exit 1
|
exit 1
|
||||||
@@ -434,6 +444,7 @@ update_mole() {
|
|||||||
else
|
else
|
||||||
if [[ -t 1 ]]; then stop_inline_spinner; fi
|
if [[ -t 1 ]]; then stop_inline_spinner; fi
|
||||||
rm -f "$tmp_installer"
|
rm -f "$tmp_installer"
|
||||||
|
_update_cleanup
|
||||||
log_error "Update failed"
|
log_error "Update failed"
|
||||||
echo "$install_output" | tail -10 >&2 # Show last 10 lines of error
|
echo "$install_output" | tail -10 >&2 # Show last 10 lines of error
|
||||||
exit 1
|
exit 1
|
||||||
@@ -443,6 +454,10 @@ update_mole() {
|
|||||||
|
|
||||||
rm -f "$tmp_installer"
|
rm -f "$tmp_installer"
|
||||||
rm -f "$HOME/.cache/mole/update_message"
|
rm -f "$HOME/.cache/mole/update_message"
|
||||||
|
|
||||||
|
# Cleanup and reset trap
|
||||||
|
_update_cleanup
|
||||||
|
trap - INT TERM
|
||||||
}
|
}
|
||||||
|
|
||||||
# Remove flow (Homebrew + manual + config/cache).
|
# Remove flow (Homebrew + manual + config/cache).
|
||||||
|
|||||||
Reference in New Issue
Block a user