|
| 1 | +#!/bin/bash |
| 2 | +# Vole - Optimize |
| 3 | +# System tuning and repair: caches, databases, broken configs, network |
| 4 | +# stack, disk health. Every task is safe to re-run. |
| 5 | + |
| 6 | +set -euo pipefail |
| 7 | + |
| 8 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 9 | +source "$SCRIPT_DIR/../lib/core/common.sh" |
| 10 | +source "$SCRIPT_DIR/../lib/optimize/tasks.sh" |
| 11 | + |
| 12 | +trap cleanup_temp_files EXIT INT TERM |
| 13 | + |
| 14 | +ONLY_KEYS="" |
| 15 | +SKIP_KEYS="" |
| 16 | +for arg in "$@"; do |
| 17 | + case "$arg" in |
| 18 | + --dry-run | -n) DRY_RUN=true ;; |
| 19 | + --only=*) ONLY_KEYS="${arg#--only=}" ;; |
| 20 | + --skip=*) SKIP_KEYS="${arg#--skip=}" ;; |
| 21 | + --list | -l) LIST_ONLY=true ;; |
| 22 | + --help | -h) |
| 23 | + echo "Usage: vole optimize [--dry-run] [--only=<tasks>] [--skip=<tasks>] [--list]" |
| 24 | + echo " --dry-run Show what would change without changing anything" |
| 25 | + echo " --only=a,b Run only these tasks (see --list for keys)" |
| 26 | + echo " --skip=a,b Run everything except these tasks" |
| 27 | + echo " --list List available tasks and exit" |
| 28 | + exit 0 |
| 29 | + ;; |
| 30 | + esac |
| 31 | +done |
| 32 | + |
| 33 | +ensure_vole_dirs |
| 34 | +load_whitelist |
| 35 | + |
| 36 | +# ============================================================================ |
| 37 | +# Task registry — key|label, in run order. macOS and Linux each get their own |
| 38 | +# list since almost every task is implemented differently per platform. |
| 39 | +# ============================================================================ |
| 40 | +if is_macos; then |
| 41 | + TASKS=( |
| 42 | + "dns_and_network|DNS & Network Cache" |
| 43 | + "finder_cache|Finder Cache" |
| 44 | + "app_state_cleanup|App Saved States" |
| 45 | + "broken_prefs|Preference File Repair" |
| 46 | + "database_vacuum|Mail, Safari & Messages Databases" |
| 47 | + "launch_services|LaunchServices (\"Open with\")" |
| 48 | + "dock_refresh|Dock Refresh" |
| 49 | + "dsstore_prevention|.DS_Store Prevention" |
| 50 | + "memory_pressure|Memory Pressure" |
| 51 | + "network_stack|Network Stack" |
| 52 | + "disk_permissions|Disk Permissions" |
| 53 | + "periodic_maintenance|Periodic Maintenance" |
| 54 | + "shared_file_lists|Shared File Lists" |
| 55 | + "login_items|Login Items" |
| 56 | + "quarantine_cleanup|Quarantine Database" |
| 57 | + "launch_agents_cleanup|Launch Agents" |
| 58 | + "notification_cleanup|Notification Center" |
| 59 | + "usage_data_cleanup|Usage Tracking Data" |
| 60 | + "disk_health|Disk Health" |
| 61 | + "battery_health|Battery Health" |
| 62 | + "homebrew_health|Homebrew Health" |
| 63 | + ) |
| 64 | +else |
| 65 | + TASKS=( |
| 66 | + "dns_cache|DNS Cache" |
| 67 | + "font_icon_cache|Font & Icon Cache" |
| 68 | + "desktop_database|Desktop & MIME Database" |
| 69 | + "autostart_audit|Autostart Entries" |
| 70 | + "broken_desktop_entries|Application Launchers" |
| 71 | + "database_vacuum|Browser Databases" |
| 72 | + "systemd_failed_units|Systemd Unit Health" |
| 73 | + "memory_pressure|Memory Pressure" |
| 74 | + "network_stack|Network Stack" |
| 75 | + "home_ownership|Home Directory Ownership" |
| 76 | + "locate_db|locate Database" |
| 77 | + "ssd_trim|SSD TRIM" |
| 78 | + "disk_health|Disk Health" |
| 79 | + "package_health|Package Database Health" |
| 80 | + "journal_health|Journal Disk Usage" |
| 81 | + ) |
| 82 | +fi |
| 83 | + |
| 84 | +if [[ "${LIST_ONLY:-false}" == "true" ]]; then |
| 85 | + echo "Available tasks:" |
| 86 | + for t in "${TASKS[@]}"; do |
| 87 | + printf ' %-24s %s\n' "${t%%|*}" "${t#*|}" |
| 88 | + done |
| 89 | + exit 0 |
| 90 | +fi |
| 91 | + |
| 92 | +# Merge CLI --skip with the configured default skip list. |
| 93 | +effective_skip=",$SKIP_KEYS,${VOLE_CFG_OPTIMIZE_SKIP:-}," |
| 94 | + |
| 95 | +task_selected() { |
| 96 | + local key="$1" |
| 97 | + if [[ -n "$ONLY_KEYS" ]]; then |
| 98 | + case ",$ONLY_KEYS," in *",$key,"*) return 0 ;; *) return 1 ;; esac |
| 99 | + fi |
| 100 | + case "$effective_skip" in *",$key,"*) return 1 ;; esac |
| 101 | + return 0 |
| 102 | +} |
| 103 | + |
| 104 | +echo "" |
| 105 | +if [[ "$DRY_RUN" == "true" ]]; then |
| 106 | + echo -e "${PURPLE_BOLD}${ICON_ARROW} Vole Optimize${NC} ${GRAY}— dry run, nothing will change${NC}" |
| 107 | +else |
| 108 | + echo -e "${PURPLE_BOLD}${ICON_ARROW} Vole Optimize${NC}" |
| 109 | +fi |
| 110 | +fda_hint |
| 111 | + |
| 112 | +# One sudo prompt up front; tasks that need it just skip cleanly if declined. |
| 113 | +if [[ "$DRY_RUN" != "true" ]]; then |
| 114 | + ensure_sudo "Some optimizations need administrator access" || true |
| 115 | +fi |
| 116 | + |
| 117 | +OPT_PREFIX="linux" |
| 118 | +is_macos && OPT_PREFIX="mac" |
| 119 | + |
| 120 | +RUN_COUNT=0 |
| 121 | +for t in "${TASKS[@]}"; do |
| 122 | + key="${t%%|*}" |
| 123 | + label="${t#*|}" |
| 124 | + task_selected "$key" || continue |
| 125 | + RUN_COUNT=$((RUN_COUNT + 1)) |
| 126 | + start_section "$label" |
| 127 | + "opt_${OPT_PREFIX}_${key}" || true |
| 128 | + end_section |
| 129 | +done |
| 130 | + |
| 131 | +echo "" |
| 132 | +if ((RUN_COUNT == 0)); then |
| 133 | + echo -e "${YELLOW}${ICON_WARNING}${NC} No tasks selected" |
| 134 | +elif [[ "$DRY_RUN" == "true" ]]; then |
| 135 | + echo -e "${GREEN}${ICON_SUCCESS}${NC} Dry run complete — $RUN_COUNT task(s) checked" |
| 136 | +else |
| 137 | + vole_phoenix |
| 138 | + echo -e "${GREEN}${ICON_SUCCESS}${NC} Optimized — $RUN_COUNT task(s) checked" |
| 139 | + log_history "optimize" "$RUN_COUNT tasks" 0 |
| 140 | +fi |
| 141 | +echo "" |
0 commit comments