1
0
mirror of https://github.com/tw93/Mole.git synced 2026-03-23 17:00:08 +00:00

Support one-click activation of touchid

This commit is contained in:
Tw93
2025-10-11 22:43:50 +08:00
parent 55f6bd352f
commit 7e42516260
3 changed files with 280 additions and 66 deletions

96
mole
View File

@@ -22,7 +22,7 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/lib/common.sh"
# Version info
VERSION="1.7.5"
VERSION="1.7.6"
MOLE_TAGLINE="can dig deep to clean your Mac."
# Get latest version from remote repository
@@ -122,7 +122,7 @@ EOF
}
show_version() {
printf 'Mole version %s\n' "$VERSION"
printf '\nMole version %s\n\n' "$VERSION"
}
show_help() {
@@ -135,6 +135,7 @@ show_help() {
printf " %s%-28s%s %s\n" "$GREEN" "mo clean --whitelist" "$NC" "Manage protected caches"
printf " %s%-28s%s %s\n" "$GREEN" "mo uninstall" "$NC" "Remove applications completely"
printf " %s%-28s%s %s\n" "$GREEN" "mo analyze" "$NC" "Interactive disk space explorer"
printf " %s%-28s%s %s\n" "$GREEN" "mo touchid" "$NC" "Configure Touch ID for sudo"
printf " %s%-28s%s %s\n" "$GREEN" "mo update" "$NC" "Update Mole to the latest version"
printf " %s%-28s%s %s\n" "$GREEN" "mo remove" "$NC" "Remove Mole from the system"
printf " %s%-28s%s %s\n" "$GREEN" "mo --version" "$NC" "Show installed version"
@@ -161,7 +162,9 @@ update_mole() {
fi
if [[ "$VERSION" == "$latest" ]]; then
echo -e "${GREEN}✓${NC} Mole is already up to date (${VERSION})"
echo ""
echo -e "${GREEN}✓${NC} Already on latest version (${VERSION})"
echo ""
exit 0
fi
@@ -249,11 +252,6 @@ update_mole() {
# Remove Mole from system
remove_mole() {
clear
echo ""
echo -e "${YELLOW}Remove Mole${NC}"
echo ""
# Detect all installations with loading
if [[ -t 1 ]]; then
start_inline_spinner "Detecting Mole installations..."
@@ -302,100 +300,84 @@ remove_mole() {
stop_inline_spinner
fi
printf '\n'
# Check if anything to remove
if [[ "$is_homebrew" == "false" && ${#manual_installs[@]:-0} -eq 0 && ${#alias_installs[@]:-0} -eq 0 ]]; then
echo ""
echo -e "${YELLOW}No Mole installation detected${NC}"
printf '%s\n\n' "${YELLOW}No Mole installation detected${NC}"
exit 0
fi
# Show what will be removed
echo "Will remove:"
echo ""
echo -e "${YELLOW}Remove Mole${NC} - will delete the following:"
if [[ "$is_homebrew" == "true" ]]; then
echo " - Mole via Homebrew"
fi
for install in ${manual_installs[@]+"${manual_installs[@]}"} ${alias_installs[@]+"${alias_installs[@]}"}; do
echo " - $install"
done
echo " - ~/.config/mole"
echo " - ~/.cache/mole"
echo ""
echo -n "Press Enter to confirm, ESC or q to cancel: "
echo -ne "${PURPLE}☛${NC} Press ${GREEN}Enter${NC} to confirm, ${GRAY}ESC${NC} to cancel: "
# Read single key
IFS= read -r -s -n1 key || key=""
echo ""
case "$key" in
$'\e'|q|Q)
echo "Cancelled"
$'\e')
echo -e "${GRAY}Cancelled${NC}"
echo ""
exit 0
;;
""|$'\n'|$'\r')
printf "\r\033[K" # Clear the prompt line
# Continue with removal
;;
*)
echo "Cancelled"
echo -e "${GRAY}Cancelled${NC}"
echo ""
exit 0
;;
esac
echo ""
# Remove Homebrew installation
# Remove Homebrew installation (silent)
local has_error=false
if [[ "$is_homebrew" == "true" ]]; then
if brew uninstall mole 2>&1 | grep -q "Uninstalling"; then
log_success "Uninstalled via Homebrew"
else
log_error "Failed to uninstall via Homebrew"
echo "Try manually: brew uninstall mole"
if ! brew uninstall mole >/dev/null 2>&1; then
has_error=true
fi
fi
# Remove manual installations
# Remove manual installations (silent)
if [[ ${#manual_installs[@]:-0} -gt 0 ]]; then
for install in "${manual_installs[@]}"; do
if [[ -f "$install" ]]; then
if rm -f "$install" 2>/dev/null; then
log_success "Removed: $install"
else
log_error "Failed to remove $install (try with sudo)"
fi
rm -f "$install" 2>/dev/null || has_error=true
fi
done
fi
if [[ ${#alias_installs[@]} -gt 0 ]]; then
for alias in "${alias_installs[@]}"; do
if [[ -f "$alias" ]]; then
if rm -f "$alias" 2>/dev/null; then
log_success "Removed alias: $alias"
else
log_warning "Could not remove alias $alias (may need sudo)"
fi
rm -f "$alias" 2>/dev/null || true
fi
done
fi
# Clean up cache first (logs to config)
# Clean up cache first (silent)
if [[ -d "$HOME/.cache/mole" ]]; then
rm -rf "$HOME/.cache/mole" 2>/dev/null && log_success "Removed cache"
rm -rf "$HOME/.cache/mole" 2>/dev/null || true
fi
# Clean up configuration last (contains logs)
# Clean up configuration last (silent)
if [[ -d "$HOME/.config/mole" ]]; then
log_success "Removed configuration"
rm -rf "$HOME/.config/mole" 2>/dev/null
rm -rf "$HOME/.config/mole" 2>/dev/null || true
fi
echo ""
echo -e "${GREEN}Mole has been removed successfully${NC}"
echo ""
echo "Thank you for using Mole!"
# Show final result
local final_message
if [[ "$has_error" == "true" ]]; then
final_message="${YELLOW}⚠ Mole uninstalled with some errors, thank you for using Mole!${NC}"
else
final_message="${GREEN}✓ Mole uninstalled successfully, thank you for using Mole!${NC}"
fi
printf '\n%s\n\n' "$final_message"
exit 0
}
@@ -443,6 +425,7 @@ show_main_menu() {
if [[ -t 0 ]]; then
printf '\r\033[2K\n'
printf '\r\033[2K%s\n' " ${GRAY}↑/↓${NC} Navigate ${GRAY}|${NC} ${GRAY}Enter${NC} Select ${GRAY}|${NC} ${GRAY}Q/ESC${NC} Quit"
printf '\r\033[2K\n'
fi
# Clear any remaining content below without full screen wipe
@@ -478,8 +461,6 @@ interactive_main_menu() {
cleanup_and_exit() {
show_cursor
echo ""
echo "Thank you for using Mole!"
exit 0
}
@@ -541,6 +522,9 @@ main() {
"analyze")
exec "$SCRIPT_DIR/bin/analyze.sh" "${@:2}"
;;
"touchid")
exec "$SCRIPT_DIR/bin/touchid.sh" "${@:2}"
;;
"update")
update_mole
exit 0