1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-04 15:04:42 +00:00

clean: auto-enable system cleanup when sudo session is active

This commit is contained in:
Tw93
2026-01-22 17:10:18 +08:00
parent 507582c51d
commit dad15a5dc6

View File

@@ -724,42 +724,53 @@ EOF
fi fi
if [[ -t 0 ]]; then if [[ -t 0 ]]; then
echo -ne "${PURPLE}${ICON_ARROW}${NC} System caches need sudo — ${GREEN}Enter${NC} continue, ${GRAY}Space${NC} skip: " if sudo -n true 2> /dev/null; then
SYSTEM_CLEAN=true
local choice echo -e "${GREEN}${ICON_SUCCESS}${NC} Admin access already available"
choice=$(read_key)
# ESC/Q aborts, Space skips, Enter enables system cleanup.
if [[ "$choice" == "QUIT" ]]; then
echo -e " ${GRAY}Canceled${NC}"
exit 0
fi
if [[ "$choice" == "SPACE" ]]; then
echo -e " ${GRAY}Skipped${NC}"
echo "" echo ""
SYSTEM_CLEAN=false else
elif [[ "$choice" == "ENTER" ]]; then echo -ne "${PURPLE}${ICON_ARROW}${NC} System caches need sudo — ${GREEN}Enter${NC} continue, ${GRAY}Space${NC} skip: "
printf "\r\033[K" # Clear the prompt line
if ensure_sudo_session "System cleanup requires admin access"; then local choice
SYSTEM_CLEAN=true choice=$(read_key)
echo -e "${GREEN}${ICON_SUCCESS}${NC} Admin access granted"
# ESC/Q aborts, Space skips, Enter enables system cleanup.
if [[ "$choice" == "QUIT" ]]; then
echo -e " ${GRAY}Canceled${NC}"
exit 0
fi
if [[ "$choice" == "SPACE" ]]; then
echo -e " ${GRAY}Skipped${NC}"
echo "" echo ""
SYSTEM_CLEAN=false
elif [[ "$choice" == "ENTER" ]]; then
printf "\r\033[K" # Clear the prompt line
if ensure_sudo_session "System cleanup requires admin access"; then
SYSTEM_CLEAN=true
echo -e "${GREEN}${ICON_SUCCESS}${NC} Admin access granted"
echo ""
else
SYSTEM_CLEAN=false
echo ""
echo -e "${YELLOW}Authentication failed${NC}, continuing with user-level cleanup"
fi
else else
SYSTEM_CLEAN=false SYSTEM_CLEAN=false
echo -e " ${GRAY}Skipped${NC}"
echo "" echo ""
echo -e "${YELLOW}Authentication failed${NC}, continuing with user-level cleanup"
fi fi
else
SYSTEM_CLEAN=false
echo -e " ${GRAY}Skipped${NC}"
echo ""
fi fi
else else
SYSTEM_CLEAN=false
echo "" echo ""
echo "Running in non-interactive mode" echo "Running in non-interactive mode"
echo " ${ICON_LIST} System-level cleanup skipped (requires interaction)" if sudo -n true 2> /dev/null; then
SYSTEM_CLEAN=true
echo " ${ICON_LIST} System-level cleanup enabled (sudo session active)"
else
SYSTEM_CLEAN=false
echo " ${ICON_LIST} System-level cleanup skipped (requires sudo)"
fi
echo " ${ICON_LIST} User-level cleanup will proceed automatically" echo " ${ICON_LIST} User-level cleanup will proceed automatically"
echo "" echo ""
fi fi