mirror of
https://github.com/tw93/Mole.git
synced 2026-02-15 20:25:04 +00:00
format
This commit is contained in:
@@ -90,5 +90,4 @@ main() {
|
|||||||
printf '\n'
|
printf '\n'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
main "$@"
|
main "$@"
|
||||||
|
|||||||
476
bin/clean.sh
476
bin/clean.sh
@@ -666,8 +666,8 @@ perform_cleanup() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Mark permissions as granted (won't prompt again)
|
# Mark permissions as granted (won't prompt again)
|
||||||
mkdir -p "$(dirname "$permission_flag")" 2>/dev/null || true
|
mkdir -p "$(dirname "$permission_flag")" 2> /dev/null || true
|
||||||
touch "$permission_flag" 2>/dev/null || true
|
touch "$permission_flag" 2> /dev/null || true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Show whitelist info if patterns are active
|
# Show whitelist info if patterns are active
|
||||||
@@ -730,7 +730,7 @@ perform_cleanup() {
|
|||||||
|
|
||||||
# Check if cache is valid (less than 2 days old)
|
# Check if cache is valid (less than 2 days old)
|
||||||
if [[ -f "$cask_cache" ]]; then
|
if [[ -f "$cask_cache" ]]; then
|
||||||
local cache_age=$(( $(date +%s) - $(stat -f%m "$cask_cache") ))
|
local cache_age=$(($(date +%s) - $(stat -f%m "$cask_cache")))
|
||||||
if [[ $cache_age -lt 172800 ]]; then
|
if [[ $cache_age -lt 172800 ]]; then
|
||||||
use_cache=true
|
use_cache=true
|
||||||
fi
|
fi
|
||||||
@@ -750,7 +750,7 @@ perform_cleanup() {
|
|||||||
while IFS= read -r cask; do
|
while IFS= read -r cask; do
|
||||||
# Get app path from cask info
|
# Get app path from cask info
|
||||||
local cask_info
|
local cask_info
|
||||||
cask_info=$(brew info --cask "$cask" 2>/dev/null || true)
|
cask_info=$(brew info --cask "$cask" 2> /dev/null || true)
|
||||||
|
|
||||||
# Extract app name from "AppName.app (App)" format
|
# Extract app name from "AppName.app (App)" format
|
||||||
local app_name
|
local app_name
|
||||||
@@ -764,13 +764,13 @@ perform_cleanup() {
|
|||||||
|
|
||||||
# Check if app exists
|
# Check if app exists
|
||||||
[[ ! -e "/Applications/$app_name" ]] && orphaned_casks+=("$cask")
|
[[ ! -e "/Applications/$app_name" ]] && orphaned_casks+=("$cask")
|
||||||
done < <(brew list --cask 2>/dev/null || true)
|
done < <(brew list --cask 2> /dev/null || true)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Remove orphaned casks if found
|
# Remove orphaned casks if found
|
||||||
if [[ ${#orphaned_casks[@]} -gt 0 ]]; then
|
if [[ ${#orphaned_casks[@]} -gt 0 ]]; then
|
||||||
# Check if sudo session is still valid (without prompting)
|
# Check if sudo session is still valid (without prompting)
|
||||||
if sudo -n true 2>/dev/null; then
|
if sudo -n true 2> /dev/null; then
|
||||||
if [[ -t 1 ]]; then
|
if [[ -t 1 ]]; then
|
||||||
stop_inline_spinner
|
stop_inline_spinner
|
||||||
MOLE_SPINNER_PREFIX=" " start_inline_spinner "Cleaning orphaned casks..."
|
MOLE_SPINNER_PREFIX=" " start_inline_spinner "Cleaning orphaned casks..."
|
||||||
@@ -1041,7 +1041,7 @@ perform_cleanup() {
|
|||||||
|
|
||||||
if [[ -f "$brew_cache_file" ]]; then
|
if [[ -f "$brew_cache_file" ]]; then
|
||||||
local last_cleanup
|
local last_cleanup
|
||||||
last_cleanup=$(cat "$brew_cache_file" 2>/dev/null || echo "0")
|
last_cleanup=$(cat "$brew_cache_file" 2> /dev/null || echo "0")
|
||||||
local current_time
|
local current_time
|
||||||
current_time=$(date +%s)
|
current_time=$(date +%s)
|
||||||
local time_diff=$((current_time - last_cleanup))
|
local time_diff=$((current_time - last_cleanup))
|
||||||
@@ -1058,73 +1058,73 @@ perform_cleanup() {
|
|||||||
|
|
||||||
local timeout_seconds=${MO_BREW_TIMEOUT:-120}
|
local timeout_seconds=${MO_BREW_TIMEOUT:-120}
|
||||||
|
|
||||||
# Run brew cleanup and autoremove in parallel
|
# Run brew cleanup and autoremove in parallel
|
||||||
local brew_tmp_file autoremove_tmp_file
|
local brew_tmp_file autoremove_tmp_file
|
||||||
brew_tmp_file=$(create_temp_file)
|
brew_tmp_file=$(create_temp_file)
|
||||||
autoremove_tmp_file=$(create_temp_file)
|
autoremove_tmp_file=$(create_temp_file)
|
||||||
|
|
||||||
(brew cleanup > "$brew_tmp_file" 2>&1) &
|
(brew cleanup > "$brew_tmp_file" 2>&1) &
|
||||||
local brew_pid=$!
|
local brew_pid=$!
|
||||||
|
|
||||||
(brew autoremove > "$autoremove_tmp_file" 2>&1) &
|
(brew autoremove > "$autoremove_tmp_file" 2>&1) &
|
||||||
local autoremove_pid=$!
|
local autoremove_pid=$!
|
||||||
|
|
||||||
local elapsed=0
|
local elapsed=0
|
||||||
local brew_done=false
|
local brew_done=false
|
||||||
local autoremove_done=false
|
local autoremove_done=false
|
||||||
|
|
||||||
# Wait for both to complete or timeout
|
# Wait for both to complete or timeout
|
||||||
while [[ "$brew_done" == "false" ]] || [[ "$autoremove_done" == "false" ]]; do
|
while [[ "$brew_done" == "false" ]] || [[ "$autoremove_done" == "false" ]]; do
|
||||||
if [[ $elapsed -ge $timeout_seconds ]]; then
|
if [[ $elapsed -ge $timeout_seconds ]]; then
|
||||||
kill -TERM $brew_pid $autoremove_pid 2> /dev/null || true
|
kill -TERM $brew_pid $autoremove_pid 2> /dev/null || true
|
||||||
break
|
break
|
||||||
fi
|
|
||||||
|
|
||||||
kill -0 $brew_pid 2> /dev/null || brew_done=true
|
|
||||||
kill -0 $autoremove_pid 2> /dev/null || autoremove_done=true
|
|
||||||
|
|
||||||
sleep 1
|
|
||||||
((elapsed++))
|
|
||||||
done
|
|
||||||
|
|
||||||
# Wait for processes to finish
|
|
||||||
wait $brew_pid 2> /dev/null && local brew_success=true || local brew_success=false
|
|
||||||
wait $autoremove_pid 2> /dev/null && local autoremove_success=true || local autoremove_success=false
|
|
||||||
|
|
||||||
if [[ -t 1 ]]; then stop_inline_spinner; fi
|
|
||||||
|
|
||||||
# Process cleanup output
|
|
||||||
if [[ "$brew_success" == "true" && -f "$brew_tmp_file" ]]; then
|
|
||||||
local brew_output
|
|
||||||
brew_output=$(cat "$brew_tmp_file" 2> /dev/null || echo "")
|
|
||||||
local removed_count freed_space
|
|
||||||
removed_count=$(printf '%s\n' "$brew_output" | grep -c "Removing:" 2> /dev/null || true)
|
|
||||||
freed_space=$(printf '%s\n' "$brew_output" | grep -o "[0-9.]*[KMGT]B freed" 2> /dev/null | tail -1 || true)
|
|
||||||
|
|
||||||
if [[ $removed_count -gt 0 ]] || [[ -n "$freed_space" ]]; then
|
|
||||||
if [[ -n "$freed_space" ]]; then
|
|
||||||
echo -e " ${GREEN}${ICON_SUCCESS}${NC} Homebrew cleanup ${GREEN}($freed_space)${NC}"
|
|
||||||
else
|
|
||||||
echo -e " ${GREEN}${ICON_SUCCESS}${NC} Homebrew cleanup (${removed_count} items)"
|
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
elif [[ $elapsed -ge $timeout_seconds ]]; then
|
|
||||||
echo -e " ${YELLOW}${ICON_WARNING}${NC} Homebrew cleanup timed out (run ${GRAY}brew cleanup${NC} manually)"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Process autoremove output - only show if packages were removed
|
kill -0 $brew_pid 2> /dev/null || brew_done=true
|
||||||
if [[ "$autoremove_success" == "true" && -f "$autoremove_tmp_file" ]]; then
|
kill -0 $autoremove_pid 2> /dev/null || autoremove_done=true
|
||||||
local autoremove_output
|
|
||||||
autoremove_output=$(cat "$autoremove_tmp_file" 2> /dev/null || echo "")
|
|
||||||
local removed_packages
|
|
||||||
removed_packages=$(printf '%s\n' "$autoremove_output" | grep -c "^Uninstalling" 2> /dev/null || true)
|
|
||||||
|
|
||||||
if [[ $removed_packages -gt 0 ]]; then
|
sleep 1
|
||||||
echo -e " ${GREEN}${ICON_SUCCESS}${NC} Removed orphaned dependencies (${removed_packages} packages)"
|
((elapsed++))
|
||||||
|
done
|
||||||
|
|
||||||
|
# Wait for processes to finish
|
||||||
|
wait $brew_pid 2> /dev/null && local brew_success=true || local brew_success=false
|
||||||
|
wait $autoremove_pid 2> /dev/null && local autoremove_success=true || local autoremove_success=false
|
||||||
|
|
||||||
|
if [[ -t 1 ]]; then stop_inline_spinner; fi
|
||||||
|
|
||||||
|
# Process cleanup output
|
||||||
|
if [[ "$brew_success" == "true" && -f "$brew_tmp_file" ]]; then
|
||||||
|
local brew_output
|
||||||
|
brew_output=$(cat "$brew_tmp_file" 2> /dev/null || echo "")
|
||||||
|
local removed_count freed_space
|
||||||
|
removed_count=$(printf '%s\n' "$brew_output" | grep -c "Removing:" 2> /dev/null || true)
|
||||||
|
freed_space=$(printf '%s\n' "$brew_output" | grep -o "[0-9.]*[KMGT]B freed" 2> /dev/null | tail -1 || true)
|
||||||
|
|
||||||
|
if [[ $removed_count -gt 0 ]] || [[ -n "$freed_space" ]]; then
|
||||||
|
if [[ -n "$freed_space" ]]; then
|
||||||
|
echo -e " ${GREEN}${ICON_SUCCESS}${NC} Homebrew cleanup ${GREEN}($freed_space)${NC}"
|
||||||
|
else
|
||||||
|
echo -e " ${GREEN}${ICON_SUCCESS}${NC} Homebrew cleanup (${removed_count} items)"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
elif [[ $elapsed -ge $timeout_seconds ]]; then
|
||||||
|
echo -e " ${YELLOW}${ICON_WARNING}${NC} Homebrew cleanup timed out (run ${GRAY}brew cleanup${NC} manually)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Process autoremove output - only show if packages were removed
|
||||||
|
if [[ "$autoremove_success" == "true" && -f "$autoremove_tmp_file" ]]; then
|
||||||
|
local autoremove_output
|
||||||
|
autoremove_output=$(cat "$autoremove_tmp_file" 2> /dev/null || echo "")
|
||||||
|
local removed_packages
|
||||||
|
removed_packages=$(printf '%s\n' "$autoremove_output" | grep -c "^Uninstalling" 2> /dev/null || true)
|
||||||
|
|
||||||
|
if [[ $removed_packages -gt 0 ]]; then
|
||||||
|
echo -e " ${GREEN}${ICON_SUCCESS}${NC} Removed orphaned dependencies (${removed_packages} packages)"
|
||||||
|
fi
|
||||||
|
elif [[ $elapsed -ge $timeout_seconds ]]; then
|
||||||
|
echo -e " ${YELLOW}${ICON_WARNING}${NC} Autoremove timed out (run ${GRAY}brew autoremove${NC} manually)"
|
||||||
fi
|
fi
|
||||||
elif [[ $elapsed -ge $timeout_seconds ]]; then
|
|
||||||
echo -e " ${YELLOW}${ICON_WARNING}${NC} Autoremove timed out (run ${GRAY}brew autoremove${NC} manually)"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Update cache timestamp on successful completion
|
# Update cache timestamp on successful completion
|
||||||
if [[ "$brew_success" == "true" || "$autoremove_success" == "true" ]]; then
|
if [[ "$brew_success" == "true" || "$autoremove_success" == "true" ]]; then
|
||||||
@@ -1185,16 +1185,16 @@ perform_cleanup() {
|
|||||||
local find_timeout=10
|
local find_timeout=10
|
||||||
local elapsed=0
|
local elapsed=0
|
||||||
|
|
||||||
while kill -0 $find_pid 2>/dev/null && [[ $elapsed -lt $find_timeout ]]; do
|
while kill -0 $find_pid 2> /dev/null && [[ $elapsed -lt $find_timeout ]]; do
|
||||||
sleep 1
|
sleep 1
|
||||||
((elapsed++))
|
((elapsed++))
|
||||||
done
|
done
|
||||||
|
|
||||||
if kill -0 $find_pid 2>/dev/null; then
|
if kill -0 $find_pid 2> /dev/null; then
|
||||||
kill -TERM $find_pid 2>/dev/null || true
|
kill -TERM $find_pid 2> /dev/null || true
|
||||||
wait $find_pid 2>/dev/null || true
|
wait $find_pid 2> /dev/null || true
|
||||||
else
|
else
|
||||||
wait $find_pid 2>/dev/null || true
|
wait $find_pid 2> /dev/null || true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
while IFS= read -r next_dir; do
|
while IFS= read -r next_dir; do
|
||||||
@@ -1226,16 +1226,16 @@ perform_cleanup() {
|
|||||||
local find_timeout=10
|
local find_timeout=10
|
||||||
local elapsed=0
|
local elapsed=0
|
||||||
|
|
||||||
while kill -0 $find_pid 2>/dev/null && [[ $elapsed -lt $find_timeout ]]; do
|
while kill -0 $find_pid 2> /dev/null && [[ $elapsed -lt $find_timeout ]]; do
|
||||||
sleep 1
|
sleep 1
|
||||||
((elapsed++))
|
((elapsed++))
|
||||||
done
|
done
|
||||||
|
|
||||||
if kill -0 $find_pid 2>/dev/null; then
|
if kill -0 $find_pid 2> /dev/null; then
|
||||||
kill -TERM $find_pid 2>/dev/null || true
|
kill -TERM $find_pid 2> /dev/null || true
|
||||||
wait $find_pid 2>/dev/null || true
|
wait $find_pid 2> /dev/null || true
|
||||||
else
|
else
|
||||||
wait $find_pid 2>/dev/null || true
|
wait $find_pid 2> /dev/null || true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
while IFS= read -r pycache; do
|
while IFS= read -r pycache; do
|
||||||
@@ -1467,29 +1467,29 @@ perform_cleanup() {
|
|||||||
# Use simple ls test instead of find to avoid hanging
|
# Use simple ls test instead of find to avoid hanging
|
||||||
if [[ -d "$HOME/Library/Application Support" ]] && ls "$HOME/Library/Application Support" > /dev/null 2>&1; then
|
if [[ -d "$HOME/Library/Application Support" ]] && ls "$HOME/Library/Application Support" > /dev/null 2>&1; then
|
||||||
|
|
||||||
# Clean log directories for apps that store logs in Application Support
|
# Clean log directories for apps that store logs in Application Support
|
||||||
for app_dir in ~/Library/Application\ Support/*; do
|
for app_dir in ~/Library/Application\ Support/*; do
|
||||||
[[ -d "$app_dir" ]] || continue
|
[[ -d "$app_dir" ]] || continue
|
||||||
app_name=$(basename "$app_dir")
|
app_name=$(basename "$app_dir")
|
||||||
|
|
||||||
# Skip system and protected apps
|
# Skip system and protected apps
|
||||||
case "$app_name" in
|
case "$app_name" in
|
||||||
com.apple.* | Adobe* | JetBrains* | 1Password | Claude | *ClashX* | *clash* | mihomo* | *Surge* | iTerm* | *iterm* | Warp* | Kitty* | Alacritty* | WezTerm* | Ghostty*)
|
com.apple.* | Adobe* | JetBrains* | 1Password | Claude | *ClashX* | *clash* | mihomo* | *Surge* | iTerm* | *iterm* | Warp* | Kitty* | Alacritty* | WezTerm* | Ghostty*)
|
||||||
continue
|
continue
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# Clean common log directories
|
# Clean common log directories
|
||||||
if [[ -d "$app_dir/log" ]]; then
|
if [[ -d "$app_dir/log" ]]; then
|
||||||
safe_clean "$app_dir/log"/* "App logs: $app_name"
|
safe_clean "$app_dir/log"/* "App logs: $app_name"
|
||||||
fi
|
fi
|
||||||
if [[ -d "$app_dir/logs" ]]; then
|
if [[ -d "$app_dir/logs" ]]; then
|
||||||
safe_clean "$app_dir/logs"/* "App logs: $app_name"
|
safe_clean "$app_dir/logs"/* "App logs: $app_name"
|
||||||
fi
|
fi
|
||||||
if [[ -d "$app_dir/activitylog" ]]; then
|
if [[ -d "$app_dir/activitylog" ]]; then
|
||||||
safe_clean "$app_dir/activitylog"/* "Activity logs: $app_name"
|
safe_clean "$app_dir/activitylog"/* "Activity logs: $app_name"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
else
|
else
|
||||||
note_activity
|
note_activity
|
||||||
@@ -1516,173 +1516,173 @@ perform_cleanup() {
|
|||||||
echo -e " ${GRAY}Tip: Grant 'Full Disk Access' to iTerm2/Terminal in System Settings${NC}"
|
echo -e " ${GRAY}Tip: Grant 'Full Disk Access' to iTerm2/Terminal in System Settings${NC}"
|
||||||
else
|
else
|
||||||
|
|
||||||
local -r ORPHAN_AGE_THRESHOLD=60 # 60 days - good balance between safety and cleanup
|
local -r ORPHAN_AGE_THRESHOLD=60 # 60 days - good balance between safety and cleanup
|
||||||
|
|
||||||
# Build list of installed application bundle identifiers
|
# Build list of installed application bundle identifiers
|
||||||
MOLE_SPINNER_PREFIX=" " start_inline_spinner "Scanning installed applications..."
|
MOLE_SPINNER_PREFIX=" " start_inline_spinner "Scanning installed applications..."
|
||||||
local installed_bundles=$(create_temp_file)
|
local installed_bundles=$(create_temp_file)
|
||||||
|
|
||||||
# Simplified: only scan primary locations (reduces scan time by ~70%)
|
# Simplified: only scan primary locations (reduces scan time by ~70%)
|
||||||
local -a search_paths=(
|
local -a search_paths=(
|
||||||
"/Applications"
|
"/Applications"
|
||||||
"$HOME/Applications"
|
"$HOME/Applications"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Scan for .app bundles with timeout protection
|
# Scan for .app bundles with timeout protection
|
||||||
for search_path in "${search_paths[@]}"; do
|
for search_path in "${search_paths[@]}"; do
|
||||||
[[ -d "$search_path" ]] || continue
|
[[ -d "$search_path" ]] || continue
|
||||||
while IFS= read -r app; do
|
while IFS= read -r app; do
|
||||||
[[ -f "$app/Contents/Info.plist" ]] || continue
|
[[ -f "$app/Contents/Info.plist" ]] || continue
|
||||||
bundle_id=$(defaults read "$app/Contents/Info.plist" CFBundleIdentifier 2> /dev/null || echo "")
|
bundle_id=$(defaults read "$app/Contents/Info.plist" CFBundleIdentifier 2> /dev/null || echo "")
|
||||||
[[ -n "$bundle_id" ]] && echo "$bundle_id" >> "$installed_bundles"
|
[[ -n "$bundle_id" ]] && echo "$bundle_id" >> "$installed_bundles"
|
||||||
done < <(run_with_timeout 10 find "$search_path" -maxdepth 2 -type d -name "*.app" 2> /dev/null || true)
|
done < <(run_with_timeout 10 find "$search_path" -maxdepth 2 -type d -name "*.app" 2> /dev/null || true)
|
||||||
done
|
done
|
||||||
|
|
||||||
# Get running applications and LaunchAgents with timeout protection
|
# Get running applications and LaunchAgents with timeout protection
|
||||||
local running_apps=$(run_with_timeout 5 osascript -e 'tell application "System Events" to get bundle identifier of every application process' 2> /dev/null || echo "")
|
local running_apps=$(run_with_timeout 5 osascript -e 'tell application "System Events" to get bundle identifier of every application process' 2> /dev/null || echo "")
|
||||||
echo "$running_apps" | tr ',' '\n' | sed -e 's/^ *//;s/ *$//' -e '/^$/d' >> "$installed_bundles"
|
echo "$running_apps" | tr ',' '\n' | sed -e 's/^ *//;s/ *$//' -e '/^$/d' >> "$installed_bundles"
|
||||||
|
|
||||||
run_with_timeout 5 find ~/Library/LaunchAgents /Library/LaunchAgents \
|
run_with_timeout 5 find ~/Library/LaunchAgents /Library/LaunchAgents \
|
||||||
-name "*.plist" -type f 2> /dev/null | while IFS= read -r plist; do
|
-name "*.plist" -type f 2> /dev/null | while IFS= read -r plist; do
|
||||||
basename "$plist" .plist
|
basename "$plist" .plist
|
||||||
done >> "$installed_bundles" 2> /dev/null || true
|
done >> "$installed_bundles" 2> /dev/null || true
|
||||||
|
|
||||||
# Deduplicate
|
# Deduplicate
|
||||||
sort -u "$installed_bundles" -o "$installed_bundles"
|
sort -u "$installed_bundles" -o "$installed_bundles"
|
||||||
|
|
||||||
local app_count=$(wc -l < "$installed_bundles" 2> /dev/null | tr -d ' ')
|
local app_count=$(wc -l < "$installed_bundles" 2> /dev/null | tr -d ' ')
|
||||||
stop_inline_spinner
|
stop_inline_spinner
|
||||||
echo -e " ${GREEN}${ICON_SUCCESS}${NC} Found $app_count active/installed apps"
|
echo -e " ${GREEN}${ICON_SUCCESS}${NC} Found $app_count active/installed apps"
|
||||||
|
|
||||||
# Track statistics
|
# Track statistics
|
||||||
local orphaned_count=0
|
local orphaned_count=0
|
||||||
local total_orphaned_kb=0
|
local total_orphaned_kb=0
|
||||||
|
|
||||||
# Check if bundle is orphaned - conservative approach
|
# Check if bundle is orphaned - conservative approach
|
||||||
is_orphaned() {
|
is_orphaned() {
|
||||||
local bundle_id="$1"
|
local bundle_id="$1"
|
||||||
local directory_path="$2"
|
local directory_path="$2"
|
||||||
|
|
||||||
# Skip system-critical and protected apps
|
# Skip system-critical and protected apps
|
||||||
if should_protect_data "$bundle_id"; then
|
if should_protect_data "$bundle_id"; then
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check if app exists in our scan
|
|
||||||
if grep -q "^$bundle_id$" "$installed_bundles" 2> /dev/null; then
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Extra check for system bundles
|
|
||||||
case "$bundle_id" in
|
|
||||||
com.apple.* | loginwindow | dock | systempreferences | finder | safari)
|
|
||||||
return 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
# Skip major vendors
|
|
||||||
case "$bundle_id" in
|
|
||||||
com.adobe.* | com.microsoft.* | com.google.* | org.mozilla.* | com.jetbrains.* | com.docker.*)
|
|
||||||
return 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
# Check file age - only clean if 60+ days inactive
|
|
||||||
# Use modification time (mtime) instead of access time (atime)
|
|
||||||
# because macOS disables atime updates by default for performance
|
|
||||||
if [[ -e "$directory_path" ]]; then
|
|
||||||
local last_modified_epoch=$(stat -f%m "$directory_path" 2> /dev/null || echo "0")
|
|
||||||
local current_epoch=$(date +%s)
|
|
||||||
local days_since_modified=$(((current_epoch - last_modified_epoch) / 86400))
|
|
||||||
|
|
||||||
if [[ $days_since_modified -lt $ORPHAN_AGE_THRESHOLD ]]; then
|
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
|
|
||||||
return 0
|
# Check if app exists in our scan
|
||||||
}
|
if grep -q "^$bundle_id$" "$installed_bundles" 2> /dev/null; then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Unified orphaned resource scanner (caches, logs, states, webkit, HTTP, cookies)
|
# Extra check for system bundles
|
||||||
MOLE_SPINNER_PREFIX=" " start_inline_spinner "Scanning orphaned app resources..."
|
case "$bundle_id" in
|
||||||
|
com.apple.* | loginwindow | dock | systempreferences | finder | safari)
|
||||||
|
return 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
# Define resource types to scan
|
# Skip major vendors
|
||||||
local -a resource_types=(
|
case "$bundle_id" in
|
||||||
"$HOME/Library/Caches|Caches|com.*:org.*:net.*:io.*"
|
com.adobe.* | com.microsoft.* | com.google.* | org.mozilla.* | com.jetbrains.* | com.docker.*)
|
||||||
"$HOME/Library/Logs|Logs|com.*:org.*:net.*:io.*"
|
return 1
|
||||||
"$HOME/Library/Saved Application State|States|*.savedState"
|
;;
|
||||||
"$HOME/Library/WebKit|WebKit|com.*:org.*:net.*:io.*"
|
esac
|
||||||
"$HOME/Library/HTTPStorages|HTTP|com.*:org.*:net.*:io.*"
|
|
||||||
"$HOME/Library/Cookies|Cookies|*.binarycookies"
|
|
||||||
)
|
|
||||||
|
|
||||||
orphaned_count=0
|
# Check file age - only clean if 60+ days inactive
|
||||||
|
# Use modification time (mtime) instead of access time (atime)
|
||||||
|
# because macOS disables atime updates by default for performance
|
||||||
|
if [[ -e "$directory_path" ]]; then
|
||||||
|
local last_modified_epoch=$(stat -f%m "$directory_path" 2> /dev/null || echo "0")
|
||||||
|
local current_epoch=$(date +%s)
|
||||||
|
local days_since_modified=$(((current_epoch - last_modified_epoch) / 86400))
|
||||||
|
|
||||||
for resource_type in "${resource_types[@]}"; do
|
if [[ $days_since_modified -lt $ORPHAN_AGE_THRESHOLD ]]; then
|
||||||
IFS='|' read -r base_path label patterns <<< "$resource_type"
|
return 1
|
||||||
|
|
||||||
# Check both existence and permission to avoid hanging
|
|
||||||
if [[ ! -d "$base_path" ]]; then
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Quick permission check - if we can't ls the directory, skip it
|
|
||||||
if ! ls "$base_path" > /dev/null 2>&1; then
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Build file pattern array
|
|
||||||
local -a file_patterns=()
|
|
||||||
IFS=':' read -ra pattern_arr <<< "$patterns"
|
|
||||||
for pat in "${pattern_arr[@]}"; do
|
|
||||||
file_patterns+=("$base_path/$pat")
|
|
||||||
done
|
|
||||||
|
|
||||||
# Scan and clean orphaned items
|
|
||||||
for item_path in "${file_patterns[@]}"; do
|
|
||||||
# Use shell glob (no ls needed)
|
|
||||||
# Limit iterations to prevent hanging on directories with too many files
|
|
||||||
local iteration_count=0
|
|
||||||
local max_iterations=100
|
|
||||||
|
|
||||||
for match in $item_path; do
|
|
||||||
[[ -e "$match" ]] || continue
|
|
||||||
|
|
||||||
# Safety: limit iterations to prevent infinite loops on massive directories
|
|
||||||
((iteration_count++))
|
|
||||||
if [[ $iteration_count -gt $max_iterations ]]; then
|
|
||||||
break
|
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# Extract bundle ID from filename
|
return 0
|
||||||
local bundle_id=$(basename "$match")
|
}
|
||||||
bundle_id="${bundle_id%.savedState}"
|
|
||||||
bundle_id="${bundle_id%.binarycookies}"
|
|
||||||
|
|
||||||
if is_orphaned "$bundle_id" "$match"; then
|
# Unified orphaned resource scanner (caches, logs, states, webkit, HTTP, cookies)
|
||||||
# Use timeout to prevent du from hanging on large/problematic directories
|
MOLE_SPINNER_PREFIX=" " start_inline_spinner "Scanning orphaned app resources..."
|
||||||
local size_kb
|
|
||||||
size_kb=$(run_with_timeout 2 du -sk "$match" 2> /dev/null | awk '{print $1}' || echo "0")
|
# Define resource types to scan
|
||||||
if [[ -z "$size_kb" || "$size_kb" == "0" ]]; then
|
local -a resource_types=(
|
||||||
continue
|
"$HOME/Library/Caches|Caches|com.*:org.*:net.*:io.*"
|
||||||
|
"$HOME/Library/Logs|Logs|com.*:org.*:net.*:io.*"
|
||||||
|
"$HOME/Library/Saved Application State|States|*.savedState"
|
||||||
|
"$HOME/Library/WebKit|WebKit|com.*:org.*:net.*:io.*"
|
||||||
|
"$HOME/Library/HTTPStorages|HTTP|com.*:org.*:net.*:io.*"
|
||||||
|
"$HOME/Library/Cookies|Cookies|*.binarycookies"
|
||||||
|
)
|
||||||
|
|
||||||
|
orphaned_count=0
|
||||||
|
|
||||||
|
for resource_type in "${resource_types[@]}"; do
|
||||||
|
IFS='|' read -r base_path label patterns <<< "$resource_type"
|
||||||
|
|
||||||
|
# Check both existence and permission to avoid hanging
|
||||||
|
if [[ ! -d "$base_path" ]]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Quick permission check - if we can't ls the directory, skip it
|
||||||
|
if ! ls "$base_path" > /dev/null 2>&1; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Build file pattern array
|
||||||
|
local -a file_patterns=()
|
||||||
|
IFS=':' read -ra pattern_arr <<< "$patterns"
|
||||||
|
for pat in "${pattern_arr[@]}"; do
|
||||||
|
file_patterns+=("$base_path/$pat")
|
||||||
|
done
|
||||||
|
|
||||||
|
# Scan and clean orphaned items
|
||||||
|
for item_path in "${file_patterns[@]}"; do
|
||||||
|
# Use shell glob (no ls needed)
|
||||||
|
# Limit iterations to prevent hanging on directories with too many files
|
||||||
|
local iteration_count=0
|
||||||
|
local max_iterations=100
|
||||||
|
|
||||||
|
for match in $item_path; do
|
||||||
|
[[ -e "$match" ]] || continue
|
||||||
|
|
||||||
|
# Safety: limit iterations to prevent infinite loops on massive directories
|
||||||
|
((iteration_count++))
|
||||||
|
if [[ $iteration_count -gt $max_iterations ]]; then
|
||||||
|
break
|
||||||
fi
|
fi
|
||||||
safe_clean "$match" "Orphaned $label: $bundle_id"
|
|
||||||
((orphaned_count++))
|
# Extract bundle ID from filename
|
||||||
((total_orphaned_kb += size_kb))
|
local bundle_id=$(basename "$match")
|
||||||
fi
|
bundle_id="${bundle_id%.savedState}"
|
||||||
|
bundle_id="${bundle_id%.binarycookies}"
|
||||||
|
|
||||||
|
if is_orphaned "$bundle_id" "$match"; then
|
||||||
|
# Use timeout to prevent du from hanging on large/problematic directories
|
||||||
|
local size_kb
|
||||||
|
size_kb=$(run_with_timeout 2 du -sk "$match" 2> /dev/null | awk '{print $1}' || echo "0")
|
||||||
|
if [[ -z "$size_kb" || "$size_kb" == "0" ]]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
safe_clean "$match" "Orphaned $label: $bundle_id"
|
||||||
|
((orphaned_count++))
|
||||||
|
((total_orphaned_kb += size_kb))
|
||||||
|
fi
|
||||||
|
done
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
done
|
|
||||||
|
|
||||||
stop_inline_spinner
|
stop_inline_spinner
|
||||||
|
|
||||||
if [[ $orphaned_count -gt 0 ]]; then
|
if [[ $orphaned_count -gt 0 ]]; then
|
||||||
local orphaned_mb=$(echo "$total_orphaned_kb" | awk '{printf "%.1f", $1/1024}')
|
local orphaned_mb=$(echo "$total_orphaned_kb" | awk '{printf "%.1f", $1/1024}')
|
||||||
echo " ${GREEN}${ICON_SUCCESS}${NC} Cleaned $orphaned_count items (~${orphaned_mb}MB)"
|
echo " ${GREEN}${ICON_SUCCESS}${NC} Cleaned $orphaned_count items (~${orphaned_mb}MB)"
|
||||||
note_activity
|
note_activity
|
||||||
fi
|
fi
|
||||||
|
|
||||||
rm -f "$installed_bundles"
|
rm -f "$installed_bundles"
|
||||||
|
|
||||||
fi # end of has_library_access check
|
fi # end of has_library_access check
|
||||||
|
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ run_system_checks() {
|
|||||||
show_optimization_summary() {
|
show_optimization_summary() {
|
||||||
local safe_count="${OPTIMIZE_SAFE_COUNT:-0}"
|
local safe_count="${OPTIMIZE_SAFE_COUNT:-0}"
|
||||||
local confirm_count="${OPTIMIZE_CONFIRM_COUNT:-0}"
|
local confirm_count="${OPTIMIZE_CONFIRM_COUNT:-0}"
|
||||||
if (( safe_count == 0 && confirm_count == 0 )) && [[ -z "${AUTO_FIX_SUMMARY:-}" ]]; then
|
if ((safe_count == 0 && confirm_count == 0)) && [[ -z "${AUTO_FIX_SUMMARY:-}" ]]; then
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
echo ""
|
echo ""
|
||||||
@@ -104,7 +104,6 @@ show_optimization_summary() {
|
|||||||
print_summary_block "success" "$summary_title" "${summary_details[@]}"
|
print_summary_block "success" "$summary_title" "${summary_details[@]}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
show_system_health() {
|
show_system_health() {
|
||||||
local health_json="$1"
|
local health_json="$1"
|
||||||
|
|
||||||
@@ -315,7 +314,6 @@ perform_security_fixes() {
|
|||||||
SECURITY_FIXES=()
|
SECURITY_FIXES=()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
cleanup_all() {
|
cleanup_all() {
|
||||||
stop_sudo_session
|
stop_sudo_session
|
||||||
cleanup_temp_files
|
cleanup_temp_files
|
||||||
|
|||||||
@@ -692,7 +692,7 @@ main() {
|
|||||||
fi
|
fi
|
||||||
show_cursor
|
show_cursor
|
||||||
clear_screen
|
clear_screen
|
||||||
printf '\033[2J\033[H' >&2 # Also clear stderr
|
printf '\033[2J\033[H' >&2 # Also clear stderr
|
||||||
rm -f "$apps_file"
|
rm -f "$apps_file"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
@@ -707,7 +707,7 @@ main() {
|
|||||||
# Restore cursor and clear screen (output to both stdout and stderr for reliability)
|
# Restore cursor and clear screen (output to both stdout and stderr for reliability)
|
||||||
show_cursor
|
show_cursor
|
||||||
clear_screen
|
clear_screen
|
||||||
printf '\033[2J\033[H' >&2 # Also clear stderr in case of mixed output
|
printf '\033[2J\033[H' >&2 # Also clear stderr in case of mixed output
|
||||||
local selection_count=${#selected_apps[@]}
|
local selection_count=${#selected_apps[@]}
|
||||||
if [[ $selection_count -eq 0 ]]; then
|
if [[ $selection_count -eq 0 ]]; then
|
||||||
echo "No apps selected"
|
echo "No apps selected"
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ show_suggestions() {
|
|||||||
# Health suggestions
|
# Health suggestions
|
||||||
if [[ -n "${CACHE_SIZE_GB:-}" ]]; then
|
if [[ -n "${CACHE_SIZE_GB:-}" ]]; then
|
||||||
local cache_gb="${CACHE_SIZE_GB:-0}"
|
local cache_gb="${CACHE_SIZE_GB:-0}"
|
||||||
if (( $(echo "$cache_gb > 5" | bc -l 2>/dev/null || echo 0) )); then
|
if (($(echo "$cache_gb > 5" | bc -l 2> /dev/null || echo 0))); then
|
||||||
manual_items+=("Free up ${cache_gb}GB by cleaning caches|Run: mo clean")
|
manual_items+=("Free up ${cache_gb}GB by cleaning caches|Run: mo clean")
|
||||||
has_suggestions=true
|
has_suggestions=true
|
||||||
fi
|
fi
|
||||||
@@ -51,7 +51,7 @@ show_suggestions() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -n "${DISK_FREE_GB:-}" && "${DISK_FREE_GB:-0}" -lt 50 ]]; then
|
if [[ -n "${DISK_FREE_GB:-}" && "${DISK_FREE_GB:-0}" -lt 50 ]]; then
|
||||||
if [[ -z "${CACHE_SIZE_GB:-}" ]] || (( $(echo "${CACHE_SIZE_GB:-0} <= 5" | bc -l 2>/dev/null || echo 1) )); then
|
if [[ -z "${CACHE_SIZE_GB:-}" ]] || (($(echo "${CACHE_SIZE_GB:-0} <= 5" | bc -l 2> /dev/null || echo 1))); then
|
||||||
manual_items+=("Low disk space (${DISK_FREE_GB}GB free)|Run: mo analyze to find large files")
|
manual_items+=("Low disk space (${DISK_FREE_GB}GB free)|Run: mo analyze to find large files")
|
||||||
has_suggestions=true
|
has_suggestions=true
|
||||||
fi
|
fi
|
||||||
@@ -132,7 +132,7 @@ perform_auto_fix() {
|
|||||||
# Fix Firewall
|
# Fix Firewall
|
||||||
if [[ -n "${FIREWALL_DISABLED:-}" && "${FIREWALL_DISABLED}" == "true" ]]; then
|
if [[ -n "${FIREWALL_DISABLED:-}" && "${FIREWALL_DISABLED}" == "true" ]]; then
|
||||||
echo -e "${BLUE}Enabling Firewall...${NC}"
|
echo -e "${BLUE}Enabling Firewall...${NC}"
|
||||||
if sudo defaults write /Library/Preferences/com.apple.alf globalstate -int 1 2>/dev/null; then
|
if sudo defaults write /Library/Preferences/com.apple.alf globalstate -int 1 2> /dev/null; then
|
||||||
echo -e "${GREEN}✓${NC} Firewall enabled"
|
echo -e "${GREEN}✓${NC} Firewall enabled"
|
||||||
((fixed_count++))
|
((fixed_count++))
|
||||||
fixed_items+=("Firewall enabled")
|
fixed_items+=("Firewall enabled")
|
||||||
@@ -148,7 +148,7 @@ perform_auto_fix() {
|
|||||||
local pam_file="/etc/pam.d/sudo"
|
local pam_file="/etc/pam.d/sudo"
|
||||||
if sudo bash -c "grep -q 'pam_tid.so' '$pam_file' 2>/dev/null || sed -i '' '2i\\
|
if sudo bash -c "grep -q 'pam_tid.so' '$pam_file' 2>/dev/null || sed -i '' '2i\\
|
||||||
auth sufficient pam_tid.so
|
auth sufficient pam_tid.so
|
||||||
' '$pam_file'" 2>/dev/null; then
|
' '$pam_file'" 2> /dev/null; then
|
||||||
echo -e "${GREEN}✓${NC} Touch ID configured"
|
echo -e "${GREEN}✓${NC} Touch ID configured"
|
||||||
((fixed_count++))
|
((fixed_count++))
|
||||||
fixed_items+=("Touch ID configured for sudo")
|
fixed_items+=("Touch ID configured for sudo")
|
||||||
|
|||||||
@@ -5,13 +5,13 @@
|
|||||||
check_touchid_sudo() {
|
check_touchid_sudo() {
|
||||||
# Check if Touch ID is configured for sudo
|
# Check if Touch ID is configured for sudo
|
||||||
local pam_file="/etc/pam.d/sudo"
|
local pam_file="/etc/pam.d/sudo"
|
||||||
if [[ -f "$pam_file" ]] && grep -q "pam_tid.so" "$pam_file" 2>/dev/null; then
|
if [[ -f "$pam_file" ]] && grep -q "pam_tid.so" "$pam_file" 2> /dev/null; then
|
||||||
echo -e " ${GREEN}✓${NC} Touch ID Enabled for sudo"
|
echo -e " ${GREEN}✓${NC} Touch ID Enabled for sudo"
|
||||||
else
|
else
|
||||||
# Check if Touch ID is supported
|
# Check if Touch ID is supported
|
||||||
local is_supported=false
|
local is_supported=false
|
||||||
if command -v bioutil > /dev/null 2>&1; then
|
if command -v bioutil > /dev/null 2>&1; then
|
||||||
if bioutil -r 2>/dev/null | grep -q "Touch ID"; then
|
if bioutil -r 2> /dev/null | grep -q "Touch ID"; then
|
||||||
is_supported=true
|
is_supported=true
|
||||||
fi
|
fi
|
||||||
elif [[ "$(uname -m)" == "arm64" ]]; then
|
elif [[ "$(uname -m)" == "arm64" ]]; then
|
||||||
@@ -40,8 +40,8 @@ check_rosetta() {
|
|||||||
check_git_config() {
|
check_git_config() {
|
||||||
# Check basic Git configuration
|
# Check basic Git configuration
|
||||||
if command -v git > /dev/null 2>&1; then
|
if command -v git > /dev/null 2>&1; then
|
||||||
local git_name=$(git config --global user.name 2>/dev/null || echo "")
|
local git_name=$(git config --global user.name 2> /dev/null || echo "")
|
||||||
local git_email=$(git config --global user.email 2>/dev/null || echo "")
|
local git_email=$(git config --global user.email 2> /dev/null || echo "")
|
||||||
|
|
||||||
if [[ -n "$git_name" && -n "$git_email" ]]; then
|
if [[ -n "$git_name" && -n "$git_email" ]]; then
|
||||||
echo -e " ${GREEN}✓${NC} Git Config Configured"
|
echo -e " ${GREEN}✓${NC} Git Config Configured"
|
||||||
|
|||||||
@@ -20,14 +20,14 @@ check_disk_space() {
|
|||||||
|
|
||||||
check_memory_usage() {
|
check_memory_usage() {
|
||||||
local mem_total
|
local mem_total
|
||||||
mem_total=$(sysctl -n hw.memsize 2>/dev/null || echo "0")
|
mem_total=$(sysctl -n hw.memsize 2> /dev/null || echo "0")
|
||||||
if [[ -z "$mem_total" || "$mem_total" -le 0 ]]; then
|
if [[ -z "$mem_total" || "$mem_total" -le 0 ]]; then
|
||||||
echo -e " ${GRAY}-${NC} Memory Unable to determine"
|
echo -e " ${GRAY}-${NC} Memory Unable to determine"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local vm_output
|
local vm_output
|
||||||
vm_output=$(vm_stat 2>/dev/null || echo "")
|
vm_output=$(vm_stat 2> /dev/null || echo "")
|
||||||
|
|
||||||
local page_size
|
local page_size
|
||||||
page_size=$(echo "$vm_output" | awk '/page size of/ {print $8}')
|
page_size=$(echo "$vm_output" | awk '/page size of/ {print $8}')
|
||||||
@@ -133,7 +133,7 @@ check_cache_size() {
|
|||||||
for cache_path in "${cache_paths[@]}"; do
|
for cache_path in "${cache_paths[@]}"; do
|
||||||
if [[ -d "$cache_path" ]]; then
|
if [[ -d "$cache_path" ]]; then
|
||||||
local size_output
|
local size_output
|
||||||
size_output=$(du -sk "$cache_path" 2>/dev/null | awk 'NR==1 {print $1}' | tr -d '[:space:]' || echo "")
|
size_output=$(du -sk "$cache_path" 2> /dev/null | awk 'NR==1 {print $1}' | tr -d '[:space:]' || echo "")
|
||||||
[[ "$size_output" =~ ^[0-9]+$ ]] || size_output=0
|
[[ "$size_output" =~ ^[0-9]+$ ]] || size_output=0
|
||||||
cache_size_kb=$((cache_size_kb + size_output))
|
cache_size_kb=$((cache_size_kb + size_output))
|
||||||
fi
|
fi
|
||||||
@@ -162,7 +162,7 @@ check_cache_size() {
|
|||||||
check_swap_usage() {
|
check_swap_usage() {
|
||||||
# Check swap usage
|
# Check swap usage
|
||||||
if command -v sysctl > /dev/null 2>&1; then
|
if command -v sysctl > /dev/null 2>&1; then
|
||||||
local swap_info=$(sysctl vm.swapusage 2>/dev/null || echo "")
|
local swap_info=$(sysctl vm.swapusage 2> /dev/null || echo "")
|
||||||
if [[ -n "$swap_info" ]]; then
|
if [[ -n "$swap_info" ]]; then
|
||||||
local swap_used=$(echo "$swap_info" | grep -o "used = [0-9.]*[GM]" | awk '{print $3}' || echo "0M")
|
local swap_used=$(echo "$swap_info" | grep -o "used = [0-9.]*[GM]" | awk '{print $3}' || echo "0M")
|
||||||
local swap_num=$(echo "$swap_used" | sed 's/[GM]//')
|
local swap_num=$(echo "$swap_used" | sed 's/[GM]//')
|
||||||
@@ -184,13 +184,13 @@ check_swap_usage() {
|
|||||||
check_timemachine() {
|
check_timemachine() {
|
||||||
# Check Time Machine backup status
|
# Check Time Machine backup status
|
||||||
if command -v tmutil > /dev/null 2>&1; then
|
if command -v tmutil > /dev/null 2>&1; then
|
||||||
local tm_status=$(tmutil latestbackup 2>/dev/null || echo "")
|
local tm_status=$(tmutil latestbackup 2> /dev/null || echo "")
|
||||||
if [[ -z "$tm_status" ]]; then
|
if [[ -z "$tm_status" ]]; then
|
||||||
echo -e " ${YELLOW}${ICON_WARNING}${NC} Time Machine No backups found"
|
echo -e " ${YELLOW}${ICON_WARNING}${NC} Time Machine No backups found"
|
||||||
echo -e " ${GRAY}Set up in System Settings → General → Time Machine (optional but recommended)${NC}"
|
echo -e " ${GRAY}Set up in System Settings → General → Time Machine (optional but recommended)${NC}"
|
||||||
else
|
else
|
||||||
# Get last backup time
|
# Get last backup time
|
||||||
local backup_date=$(tmutil latestbackup 2>/dev/null | xargs basename 2>/dev/null || echo "")
|
local backup_date=$(tmutil latestbackup 2> /dev/null | xargs basename 2> /dev/null || echo "")
|
||||||
if [[ -n "$backup_date" ]]; then
|
if [[ -n "$backup_date" ]]; then
|
||||||
echo -e " ${GREEN}✓${NC} Time Machine Backup active"
|
echo -e " ${GREEN}✓${NC} Time Machine Backup active"
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
check_filevault() {
|
check_filevault() {
|
||||||
# Check FileVault encryption status
|
# Check FileVault encryption status
|
||||||
if command -v fdesetup > /dev/null 2>&1; then
|
if command -v fdesetup > /dev/null 2>&1; then
|
||||||
local fv_status=$(fdesetup status 2>/dev/null || echo "")
|
local fv_status=$(fdesetup status 2> /dev/null || echo "")
|
||||||
if echo "$fv_status" | grep -q "FileVault is On"; then
|
if echo "$fv_status" | grep -q "FileVault is On"; then
|
||||||
echo -e " ${GREEN}✓${NC} FileVault Enabled"
|
echo -e " ${GREEN}✓${NC} FileVault Enabled"
|
||||||
else
|
else
|
||||||
@@ -18,7 +18,7 @@ check_filevault() {
|
|||||||
check_firewall() {
|
check_firewall() {
|
||||||
# Check firewall status
|
# Check firewall status
|
||||||
unset FIREWALL_DISABLED
|
unset FIREWALL_DISABLED
|
||||||
local firewall_status=$(defaults read /Library/Preferences/com.apple.alf globalstate 2>/dev/null || echo "0")
|
local firewall_status=$(defaults read /Library/Preferences/com.apple.alf globalstate 2> /dev/null || echo "0")
|
||||||
if [[ "$firewall_status" == "1" || "$firewall_status" == "2" ]]; then
|
if [[ "$firewall_status" == "1" || "$firewall_status" == "2" ]]; then
|
||||||
echo -e " ${GREEN}✓${NC} Firewall Enabled"
|
echo -e " ${GREEN}✓${NC} Firewall Enabled"
|
||||||
else
|
else
|
||||||
@@ -32,7 +32,7 @@ check_firewall() {
|
|||||||
check_gatekeeper() {
|
check_gatekeeper() {
|
||||||
# Check Gatekeeper status
|
# Check Gatekeeper status
|
||||||
if command -v spctl > /dev/null 2>&1; then
|
if command -v spctl > /dev/null 2>&1; then
|
||||||
local gk_status=$(spctl --status 2>/dev/null || echo "")
|
local gk_status=$(spctl --status 2> /dev/null || echo "")
|
||||||
if echo "$gk_status" | grep -q "enabled"; then
|
if echo "$gk_status" | grep -q "enabled"; then
|
||||||
echo -e " ${GREEN}✓${NC} Gatekeeper Active"
|
echo -e " ${GREEN}✓${NC} Gatekeeper Active"
|
||||||
unset GATEKEEPER_DISABLED
|
unset GATEKEEPER_DISABLED
|
||||||
@@ -48,7 +48,7 @@ check_gatekeeper() {
|
|||||||
check_sip() {
|
check_sip() {
|
||||||
# Check System Integrity Protection
|
# Check System Integrity Protection
|
||||||
if command -v csrutil > /dev/null 2>&1; then
|
if command -v csrutil > /dev/null 2>&1; then
|
||||||
local sip_status=$(csrutil status 2>/dev/null || echo "")
|
local sip_status=$(csrutil status 2> /dev/null || echo "")
|
||||||
if echo "$sip_status" | grep -q "enabled"; then
|
if echo "$sip_status" | grep -q "enabled"; then
|
||||||
echo -e " ${GREEN}✓${NC} SIP Enabled"
|
echo -e " ${GREEN}✓${NC} SIP Enabled"
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -5,14 +5,14 @@
|
|||||||
|
|
||||||
# Cache configuration
|
# Cache configuration
|
||||||
CACHE_DIR="${HOME}/.cache/mole"
|
CACHE_DIR="${HOME}/.cache/mole"
|
||||||
CACHE_TTL=600 # 10 minutes in seconds
|
CACHE_TTL=600 # 10 minutes in seconds
|
||||||
|
|
||||||
# Ensure cache directory exists
|
# Ensure cache directory exists
|
||||||
mkdir -p "$CACHE_DIR" 2>/dev/null || true
|
mkdir -p "$CACHE_DIR" 2> /dev/null || true
|
||||||
|
|
||||||
clear_cache_file() {
|
clear_cache_file() {
|
||||||
local file="$1"
|
local file="$1"
|
||||||
rm -f "$file" 2>/dev/null || true
|
rm -f "$file" 2> /dev/null || true
|
||||||
}
|
}
|
||||||
|
|
||||||
reset_brew_cache() {
|
reset_brew_cache() {
|
||||||
@@ -37,7 +37,7 @@ is_cache_valid() {
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local cache_age=$(($(date +%s) - $(stat -f%m "$cache_file" 2>/dev/null || echo 0)))
|
local cache_age=$(($(date +%s) - $(stat -f%m "$cache_file" 2> /dev/null || echo 0)))
|
||||||
[[ $cache_age -lt $ttl ]]
|
[[ $cache_age -lt $ttl ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ check_homebrew_updates() {
|
|||||||
local cask_count=0
|
local cask_count=0
|
||||||
|
|
||||||
if is_cache_valid "$cache_file"; then
|
if is_cache_valid "$cache_file"; then
|
||||||
read -r formula_count cask_count < "$cache_file" 2>/dev/null || true
|
read -r formula_count cask_count < "$cache_file" 2> /dev/null || true
|
||||||
formula_count=${formula_count:-0}
|
formula_count=${formula_count:-0}
|
||||||
cask_count=${cask_count:-0}
|
cask_count=${cask_count:-0}
|
||||||
else
|
else
|
||||||
@@ -61,18 +61,18 @@ check_homebrew_updates() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
local outdated_list=""
|
local outdated_list=""
|
||||||
outdated_list=$(brew outdated --quiet 2>/dev/null || echo "")
|
outdated_list=$(brew outdated --quiet 2> /dev/null || echo "")
|
||||||
if [[ -n "$outdated_list" ]]; then
|
if [[ -n "$outdated_list" ]]; then
|
||||||
formula_count=$(echo "$outdated_list" | wc -l | tr -d ' ')
|
formula_count=$(echo "$outdated_list" | wc -l | tr -d ' ')
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local cask_list=""
|
local cask_list=""
|
||||||
cask_list=$(brew outdated --cask --quiet 2>/dev/null || echo "")
|
cask_list=$(brew outdated --cask --quiet 2> /dev/null || echo "")
|
||||||
if [[ -n "$cask_list" ]]; then
|
if [[ -n "$cask_list" ]]; then
|
||||||
cask_count=$(echo "$cask_list" | wc -l | tr -d ' ')
|
cask_count=$(echo "$cask_list" | wc -l | tr -d ' ')
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "$formula_count $cask_count" > "$cache_file" 2>/dev/null || true
|
echo "$formula_count $cask_count" > "$cache_file" 2> /dev/null || true
|
||||||
|
|
||||||
# Stop spinner before output
|
# Stop spinner before output
|
||||||
if [[ -t 1 ]]; then
|
if [[ -t 1 ]]; then
|
||||||
@@ -110,7 +110,7 @@ get_software_updates() {
|
|||||||
if [[ -z "$SOFTWARE_UPDATE_LIST" ]]; then
|
if [[ -z "$SOFTWARE_UPDATE_LIST" ]]; then
|
||||||
# Check cache first
|
# Check cache first
|
||||||
if is_cache_valid "$cache_file"; then
|
if is_cache_valid "$cache_file"; then
|
||||||
SOFTWARE_UPDATE_LIST=$(cat "$cache_file" 2>/dev/null || echo "")
|
SOFTWARE_UPDATE_LIST=$(cat "$cache_file" 2> /dev/null || echo "")
|
||||||
else
|
else
|
||||||
# Show spinner while checking (only on first call)
|
# Show spinner while checking (only on first call)
|
||||||
local show_spinner=false
|
local show_spinner=false
|
||||||
@@ -120,9 +120,9 @@ get_software_updates() {
|
|||||||
export SOFTWAREUPDATE_SPINNER_SHOWN="true"
|
export SOFTWAREUPDATE_SPINNER_SHOWN="true"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
SOFTWARE_UPDATE_LIST=$(softwareupdate -l 2>/dev/null || echo "")
|
SOFTWARE_UPDATE_LIST=$(softwareupdate -l 2> /dev/null || echo "")
|
||||||
# Save to cache
|
# Save to cache
|
||||||
echo "$SOFTWARE_UPDATE_LIST" > "$cache_file" 2>/dev/null || true
|
echo "$SOFTWARE_UPDATE_LIST" > "$cache_file" 2> /dev/null || true
|
||||||
|
|
||||||
# Stop spinner
|
# Stop spinner
|
||||||
if [[ "$show_spinner" == "true" ]]; then
|
if [[ "$show_spinner" == "true" ]]; then
|
||||||
@@ -208,7 +208,7 @@ check_mole_update() {
|
|||||||
# Auto-detect version from mole main script
|
# Auto-detect version from mole main script
|
||||||
local current_version
|
local current_version
|
||||||
if [[ -f "${SCRIPT_DIR:-/usr/local/bin}/mole" ]]; then
|
if [[ -f "${SCRIPT_DIR:-/usr/local/bin}/mole" ]]; then
|
||||||
current_version=$(grep '^VERSION=' "${SCRIPT_DIR:-/usr/local/bin}/mole" 2>/dev/null | head -1 | sed 's/VERSION="\(.*\)"/\1/' || echo "unknown")
|
current_version=$(grep '^VERSION=' "${SCRIPT_DIR:-/usr/local/bin}/mole" 2> /dev/null | head -1 | sed 's/VERSION="\(.*\)"/\1/' || echo "unknown")
|
||||||
else
|
else
|
||||||
current_version="${VERSION:-unknown}"
|
current_version="${VERSION:-unknown}"
|
||||||
fi
|
fi
|
||||||
@@ -220,7 +220,7 @@ check_mole_update() {
|
|||||||
|
|
||||||
# Check cache first
|
# Check cache first
|
||||||
if is_cache_valid "$cache_file"; then
|
if is_cache_valid "$cache_file"; then
|
||||||
latest_version=$(cat "$cache_file" 2>/dev/null || echo "")
|
latest_version=$(cat "$cache_file" 2> /dev/null || echo "")
|
||||||
else
|
else
|
||||||
# Show spinner while checking
|
# Show spinner while checking
|
||||||
if [[ -t 1 ]]; then
|
if [[ -t 1 ]]; then
|
||||||
@@ -229,10 +229,10 @@ check_mole_update() {
|
|||||||
|
|
||||||
# Try to get latest version from GitHub
|
# Try to get latest version from GitHub
|
||||||
if command -v curl > /dev/null 2>&1; then
|
if command -v curl > /dev/null 2>&1; then
|
||||||
latest_version=$(curl -fsSL https://api.github.com/repos/tw93/mole/releases/latest 2>/dev/null | grep '"tag_name"' | sed -E 's/.*"v?([^"]+)".*/\1/' || echo "")
|
latest_version=$(curl -fsSL https://api.github.com/repos/tw93/mole/releases/latest 2> /dev/null | grep '"tag_name"' | sed -E 's/.*"v?([^"]+)".*/\1/' || echo "")
|
||||||
# Save to cache
|
# Save to cache
|
||||||
if [[ -n "$latest_version" ]]; then
|
if [[ -n "$latest_version" ]]; then
|
||||||
echo "$latest_version" > "$cache_file" 2>/dev/null || true
|
echo "$latest_version" > "$cache_file" 2> /dev/null || true
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@@ -532,14 +532,14 @@ is_clamshell_mode() {
|
|||||||
|
|
||||||
# Check if lid is closed; ignore pipeline failures so set -e doesn't exit
|
# Check if lid is closed; ignore pipeline failures so set -e doesn't exit
|
||||||
local clamshell_state=""
|
local clamshell_state=""
|
||||||
clamshell_state=$( (ioreg -r -k AppleClamshellState -d 4 2>/dev/null \
|
clamshell_state=$( (ioreg -r -k AppleClamshellState -d 4 2> /dev/null |
|
||||||
| grep "AppleClamshellState" \
|
grep "AppleClamshellState" |
|
||||||
| head -1) || true )
|
head -1) || true)
|
||||||
|
|
||||||
if [[ "$clamshell_state" =~ \"AppleClamshellState\"\ =\ Yes ]]; then
|
if [[ "$clamshell_state" =~ \"AppleClamshellState\"\ =\ Yes ]]; then
|
||||||
return 0 # Lid is closed
|
return 0 # Lid is closed
|
||||||
fi
|
fi
|
||||||
return 1 # Lid is open
|
return 1 # Lid is open
|
||||||
}
|
}
|
||||||
|
|
||||||
# Manual password input (no Touch ID)
|
# Manual password input (no Touch ID)
|
||||||
@@ -549,7 +549,7 @@ _request_password() {
|
|||||||
local show_hint=true
|
local show_hint=true
|
||||||
|
|
||||||
# Extra safety: ensure sudo cache is cleared before password input
|
# Extra safety: ensure sudo cache is cleared before password input
|
||||||
sudo -k 2>/dev/null
|
sudo -k 2> /dev/null
|
||||||
|
|
||||||
while ((attempts < 3)); do
|
while ((attempts < 3)); do
|
||||||
local password=""
|
local password=""
|
||||||
@@ -635,13 +635,13 @@ request_sudo_access() {
|
|||||||
|
|
||||||
# Wait for sudo to complete or timeout (5 seconds)
|
# Wait for sudo to complete or timeout (5 seconds)
|
||||||
local elapsed=0
|
local elapsed=0
|
||||||
local timeout=50 # 50 * 0.1s = 5 seconds
|
local timeout=50 # 50 * 0.1s = 5 seconds
|
||||||
while ((elapsed < timeout)); do
|
while ((elapsed < timeout)); do
|
||||||
if ! kill -0 "$sudo_pid" 2>/dev/null; then
|
if ! kill -0 "$sudo_pid" 2> /dev/null; then
|
||||||
# Process exited
|
# Process exited
|
||||||
wait "$sudo_pid" 2>/dev/null
|
wait "$sudo_pid" 2> /dev/null
|
||||||
local exit_code=$?
|
local exit_code=$?
|
||||||
if [[ $exit_code -eq 0 ]] && sudo -n true 2>/dev/null; then
|
if [[ $exit_code -eq 0 ]] && sudo -n true 2> /dev/null; then
|
||||||
# Touch ID succeeded
|
# Touch ID succeeded
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
@@ -655,13 +655,13 @@ request_sudo_access() {
|
|||||||
# Touch ID failed/cancelled - clean up thoroughly before password input
|
# Touch ID failed/cancelled - clean up thoroughly before password input
|
||||||
|
|
||||||
# Kill the sudo process if still running
|
# Kill the sudo process if still running
|
||||||
if kill -0 "$sudo_pid" 2>/dev/null; then
|
if kill -0 "$sudo_pid" 2> /dev/null; then
|
||||||
kill -9 "$sudo_pid" 2>/dev/null
|
kill -9 "$sudo_pid" 2> /dev/null
|
||||||
wait "$sudo_pid" 2>/dev/null || true
|
wait "$sudo_pid" 2> /dev/null || true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Clear sudo state immediately
|
# Clear sudo state immediately
|
||||||
sudo -k 2>/dev/null
|
sudo -k 2> /dev/null
|
||||||
|
|
||||||
# IMPORTANT: Wait longer for macOS to fully close Touch ID UI and SecurityAgent
|
# IMPORTANT: Wait longer for macOS to fully close Touch ID UI and SecurityAgent
|
||||||
# Without this delay, subsequent sudo calls may re-trigger Touch ID
|
# Without this delay, subsequent sudo calls may re-trigger Touch ID
|
||||||
@@ -702,17 +702,17 @@ update_via_homebrew() {
|
|||||||
# Use background process to allow interruption
|
# Use background process to allow interruption
|
||||||
local brew_update_timeout="${MO_BREW_UPDATE_TIMEOUT:-300}"
|
local brew_update_timeout="${MO_BREW_UPDATE_TIMEOUT:-300}"
|
||||||
local brew_tmp_file
|
local brew_tmp_file
|
||||||
brew_tmp_file=$(mktemp -t mole-brew-update 2>/dev/null || echo "/tmp/mole-brew-update.$$")
|
brew_tmp_file=$(mktemp -t mole-brew-update 2> /dev/null || echo "/tmp/mole-brew-update.$$")
|
||||||
|
|
||||||
(brew update > "$brew_tmp_file" 2>&1) &
|
(brew update > "$brew_tmp_file" 2>&1) &
|
||||||
local brew_pid=$!
|
local brew_pid=$!
|
||||||
local elapsed=0
|
local elapsed=0
|
||||||
|
|
||||||
# Wait for completion or timeout
|
# Wait for completion or timeout
|
||||||
while kill -0 $brew_pid 2>/dev/null; do
|
while kill -0 $brew_pid 2> /dev/null; do
|
||||||
if [[ $elapsed -ge $brew_update_timeout ]]; then
|
if [[ $elapsed -ge $brew_update_timeout ]]; then
|
||||||
kill -TERM $brew_pid 2>/dev/null || true
|
kill -TERM $brew_pid 2> /dev/null || true
|
||||||
wait $brew_pid 2>/dev/null || true
|
wait $brew_pid 2> /dev/null || true
|
||||||
if [[ -t 1 ]]; then stop_inline_spinner; fi
|
if [[ -t 1 ]]; then stop_inline_spinner; fi
|
||||||
rm -f "$brew_tmp_file"
|
rm -f "$brew_tmp_file"
|
||||||
log_error "Homebrew update timed out (${brew_update_timeout}s)"
|
log_error "Homebrew update timed out (${brew_update_timeout}s)"
|
||||||
@@ -722,7 +722,7 @@ update_via_homebrew() {
|
|||||||
((elapsed++))
|
((elapsed++))
|
||||||
done
|
done
|
||||||
|
|
||||||
wait $brew_pid 2>/dev/null || {
|
wait $brew_pid 2> /dev/null || {
|
||||||
if [[ -t 1 ]]; then stop_inline_spinner; fi
|
if [[ -t 1 ]]; then stop_inline_spinner; fi
|
||||||
rm -f "$brew_tmp_file"
|
rm -f "$brew_tmp_file"
|
||||||
log_error "Homebrew update failed"
|
log_error "Homebrew update failed"
|
||||||
|
|||||||
@@ -22,13 +22,13 @@ _pm_get_terminal_height() {
|
|||||||
# Try stty size first (most reliable, real-time)
|
# Try stty size first (most reliable, real-time)
|
||||||
# Use </dev/tty to ensure we read from terminal even if stdin is redirected
|
# Use </dev/tty to ensure we read from terminal even if stdin is redirected
|
||||||
if [[ -t 0 ]] || [[ -t 2 ]]; then
|
if [[ -t 0 ]] || [[ -t 2 ]]; then
|
||||||
height=$(stty size </dev/tty 2>/dev/null | awk '{print $1}')
|
height=$(stty size < /dev/tty 2> /dev/null | awk '{print $1}')
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Fallback to tput
|
# Fallback to tput
|
||||||
if [[ -z "$height" || $height -le 0 ]]; then
|
if [[ -z "$height" || $height -le 0 ]]; then
|
||||||
if command -v tput > /dev/null 2>&1; then
|
if command -v tput > /dev/null 2>&1; then
|
||||||
height=$(tput lines 2>/dev/null || echo "24")
|
height=$(tput lines 2> /dev/null || echo "24")
|
||||||
else
|
else
|
||||||
height=24
|
height=24
|
||||||
fi
|
fi
|
||||||
@@ -40,7 +40,7 @@ _pm_get_terminal_height() {
|
|||||||
# Calculate dynamic items per page based on terminal height
|
# Calculate dynamic items per page based on terminal height
|
||||||
_pm_calculate_items_per_page() {
|
_pm_calculate_items_per_page() {
|
||||||
local term_height=$(_pm_get_terminal_height)
|
local term_height=$(_pm_get_terminal_height)
|
||||||
local reserved=6 # header(2) + footer(3) + spacing(1)
|
local reserved=6 # header(2) + footer(3) + spacing(1)
|
||||||
local available=$((term_height - reserved))
|
local available=$((term_height - reserved))
|
||||||
|
|
||||||
# Ensure minimum and maximum bounds
|
# Ensure minimum and maximum bounds
|
||||||
|
|||||||
@@ -14,13 +14,13 @@ _ms_get_terminal_height() {
|
|||||||
# Try stty size first (most reliable, real-time)
|
# Try stty size first (most reliable, real-time)
|
||||||
# Use </dev/tty to ensure we read from terminal even if stdin is redirected
|
# Use </dev/tty to ensure we read from terminal even if stdin is redirected
|
||||||
if [[ -t 0 ]] || [[ -t 2 ]]; then
|
if [[ -t 0 ]] || [[ -t 2 ]]; then
|
||||||
height=$(stty size </dev/tty 2>/dev/null | awk '{print $1}')
|
height=$(stty size < /dev/tty 2> /dev/null | awk '{print $1}')
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Fallback to tput
|
# Fallback to tput
|
||||||
if [[ -z "$height" || $height -le 0 ]]; then
|
if [[ -z "$height" || $height -le 0 ]]; then
|
||||||
if command -v tput > /dev/null 2>&1; then
|
if command -v tput > /dev/null 2>&1; then
|
||||||
height=$(tput lines 2>/dev/null || echo "24")
|
height=$(tput lines 2> /dev/null || echo "24")
|
||||||
else
|
else
|
||||||
height=24
|
height=24
|
||||||
fi
|
fi
|
||||||
@@ -33,7 +33,7 @@ _ms_get_terminal_height() {
|
|||||||
_ms_calculate_items_per_page() {
|
_ms_calculate_items_per_page() {
|
||||||
local term_height=$(_ms_get_terminal_height)
|
local term_height=$(_ms_get_terminal_height)
|
||||||
# Layout: header(1) + spacing(1) + items + spacing(1) + footer(1) + clear(1) = 5 fixed lines
|
# Layout: header(1) + spacing(1) + items + spacing(1) + footer(1) + clear(1) = 5 fixed lines
|
||||||
local reserved=6 # Increased to prevent header from being overwritten
|
local reserved=6 # Increased to prevent header from being overwritten
|
||||||
local available=$((term_height - reserved))
|
local available=$((term_height - reserved))
|
||||||
|
|
||||||
# Ensure minimum and maximum bounds
|
# Ensure minimum and maximum bounds
|
||||||
|
|||||||
@@ -4,11 +4,14 @@
|
|||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
readonly MAIL_DOWNLOADS_MIN_KB=5120 # ~5MB threshold
|
readonly MAIL_DOWNLOADS_MIN_KB=5120 # ~5MB threshold
|
||||||
|
|
||||||
_opt_get_dir_size_kb() {
|
_opt_get_dir_size_kb() {
|
||||||
local path="$1"
|
local path="$1"
|
||||||
[[ -e "$path" ]] || { echo 0; return; }
|
[[ -e "$path" ]] || {
|
||||||
|
echo 0
|
||||||
|
return
|
||||||
|
}
|
||||||
du -sk "$path" 2> /dev/null | awk '{print $1}' || echo 0
|
du -sk "$path" 2> /dev/null | awk '{print $1}' || echo 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -352,19 +355,19 @@ execute_optimization() {
|
|||||||
local path="${2:-}"
|
local path="${2:-}"
|
||||||
|
|
||||||
case "$action" in
|
case "$action" in
|
||||||
system_maintenance) opt_system_maintenance ;;
|
system_maintenance) opt_system_maintenance ;;
|
||||||
cache_refresh) opt_cache_refresh ;;
|
cache_refresh) opt_cache_refresh ;;
|
||||||
maintenance_scripts) opt_maintenance_scripts ;;
|
maintenance_scripts) opt_maintenance_scripts ;;
|
||||||
log_cleanup) opt_log_cleanup ;;
|
log_cleanup) opt_log_cleanup ;;
|
||||||
recent_items) opt_recent_items ;;
|
recent_items) opt_recent_items ;;
|
||||||
radio_refresh) opt_radio_refresh ;;
|
radio_refresh) opt_radio_refresh ;;
|
||||||
mail_downloads) opt_mail_downloads ;;
|
mail_downloads) opt_mail_downloads ;;
|
||||||
saved_state_cleanup) opt_saved_state_cleanup ;;
|
saved_state_cleanup) opt_saved_state_cleanup ;;
|
||||||
finder_dock_refresh) opt_finder_dock_refresh ;;
|
finder_dock_refresh) opt_finder_dock_refresh ;;
|
||||||
swap_cleanup) opt_swap_cleanup ;;
|
swap_cleanup) opt_swap_cleanup ;;
|
||||||
startup_cache) opt_startup_cache ;;
|
startup_cache) opt_startup_cache ;;
|
||||||
local_snapshots) opt_local_snapshots ;;
|
local_snapshots) opt_local_snapshots ;;
|
||||||
developer_cleanup) opt_developer_cleanup ;;
|
developer_cleanup) opt_developer_cleanup ;;
|
||||||
*)
|
*)
|
||||||
echo -e "${RED}${ICON_ERROR}${NC} Unknown action: $action"
|
echo -e "${RED}${ICON_ERROR}${NC} Unknown action: $action"
|
||||||
return 1
|
return 1
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ _start_sudo_keepalive() {
|
|||||||
sleep 30
|
sleep 30
|
||||||
kill -0 "$$" 2> /dev/null || exit
|
kill -0 "$$" 2> /dev/null || exit
|
||||||
done
|
done
|
||||||
) >/dev/null 2>&1 &
|
) > /dev/null 2>&1 &
|
||||||
|
|
||||||
local pid=$!
|
local pid=$!
|
||||||
[[ "${MO_DEBUG:-}" == "1" ]] && echo "DEBUG: _start_sudo_keepalive: background PID = $pid" >&2
|
[[ "${MO_DEBUG:-}" == "1" ]] && echo "DEBUG: _start_sudo_keepalive: background PID = $pid" >&2
|
||||||
|
|||||||
@@ -20,7 +20,10 @@ format_brew_update_label() {
|
|||||||
|
|
||||||
local detail_str="(${total} updates)"
|
local detail_str="(${total} updates)"
|
||||||
if ((${#details[@]} > 0)); then
|
if ((${#details[@]} > 0)); then
|
||||||
detail_str="($(IFS=', '; printf '%s' "${details[*]}"))"
|
detail_str="($(
|
||||||
|
IFS=', '
|
||||||
|
printf '%s' "${details[*]}"
|
||||||
|
))"
|
||||||
fi
|
fi
|
||||||
printf " • Homebrew %s" "$detail_str"
|
printf " • Homebrew %s" "$detail_str"
|
||||||
}
|
}
|
||||||
@@ -271,7 +274,7 @@ perform_updates() {
|
|||||||
_perform_appstore_update() {
|
_perform_appstore_update() {
|
||||||
echo -e "${BLUE}Updating App Store apps...${NC}"
|
echo -e "${BLUE}Updating App Store apps...${NC}"
|
||||||
local appstore_log
|
local appstore_log
|
||||||
appstore_log=$(mktemp -t mole-appstore 2>/dev/null || echo "/tmp/mole-appstore.log")
|
appstore_log=$(mktemp -t mole-appstore 2> /dev/null || echo "/tmp/mole-appstore.log")
|
||||||
|
|
||||||
if [[ "$appstore_needs_fallback" == "true" ]]; then
|
if [[ "$appstore_needs_fallback" == "true" ]]; then
|
||||||
echo -e " ${GRAY}Installing all available updates${NC}"
|
echo -e " ${GRAY}Installing all available updates${NC}"
|
||||||
@@ -293,7 +296,7 @@ _perform_appstore_update() {
|
|||||||
echo -e "${RED}✗${NC} App Store update failed"
|
echo -e "${RED}✗${NC} App Store update failed"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
rm -f "$appstore_log" 2>/dev/null || true
|
rm -f "$appstore_log" 2> /dev/null || true
|
||||||
reset_softwareupdate_cache
|
reset_softwareupdate_cache
|
||||||
echo ""
|
echo ""
|
||||||
}
|
}
|
||||||
@@ -304,7 +307,7 @@ _perform_macos_update() {
|
|||||||
echo -e "${YELLOW}Note:${NC} System update may require restart"
|
echo -e "${YELLOW}Note:${NC} System update may require restart"
|
||||||
|
|
||||||
local macos_log
|
local macos_log
|
||||||
macos_log=$(mktemp -t mole-macos 2>/dev/null || echo "/tmp/mole-macos.log")
|
macos_log=$(mktemp -t mole-macos 2> /dev/null || echo "/tmp/mole-macos.log")
|
||||||
|
|
||||||
if [[ "$macos_needs_fallback" == "true" ]]; then
|
if [[ "$macos_needs_fallback" == "true" ]]; then
|
||||||
if sudo softwareupdate -i -r 2>&1 | tee "$macos_log" | grep -v "^$"; then
|
if sudo softwareupdate -i -r 2>&1 | tee "$macos_log" | grep -v "^$"; then
|
||||||
@@ -322,11 +325,11 @@ _perform_macos_update() {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if grep -qi "restart" "$macos_log" 2>/dev/null; then
|
if grep -qi "restart" "$macos_log" 2> /dev/null; then
|
||||||
echo -e "${YELLOW}${ICON_WARNING}${NC} Restart required to complete update"
|
echo -e "${YELLOW}${ICON_WARNING}${NC} Restart required to complete update"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
rm -f "$macos_log" 2>/dev/null || true
|
rm -f "$macos_log" 2> /dev/null || true
|
||||||
reset_softwareupdate_cache
|
reset_softwareupdate_cache
|
||||||
echo ""
|
echo ""
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,9 +108,11 @@ setup() {
|
|||||||
|
|
||||||
run bash --noprofile --norc -c "cd '$PROJECT_ROOT'; printf \$' \\n' | HOME='$HOME' ./mo clean --whitelist"
|
run bash --noprofile --norc -c "cd '$PROJECT_ROOT'; printf \$' \\n' | HOME='$HOME' ./mo clean --whitelist"
|
||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
! grep -q "\\.m2/repository" "$whitelist_file"
|
run grep -q "\\.m2/repository" "$whitelist_file"
|
||||||
|
[ "$status" -eq 1 ]
|
||||||
|
|
||||||
run bash --noprofile --norc -c "cd '$PROJECT_ROOT'; printf \$'\\n' | HOME='$HOME' ./mo clean --whitelist"
|
run bash --noprofile --norc -c "cd '$PROJECT_ROOT'; printf \$'\\n' | HOME='$HOME' ./mo clean --whitelist"
|
||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
! grep -q "\\.m2/repository" "$whitelist_file"
|
run grep -q "\\.m2/repository" "$whitelist_file"
|
||||||
|
[ "$status" -eq 1 ]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user