mirror of
https://github.com/tw93/Mole.git
synced 2026-02-04 15:39:42 +00:00
format
This commit is contained in:
@@ -90,5 +90,4 @@ main() {
|
||||
printf '\n'
|
||||
}
|
||||
|
||||
|
||||
main "$@"
|
||||
|
||||
34
bin/clean.sh
34
bin/clean.sh
@@ -666,8 +666,8 @@ perform_cleanup() {
|
||||
fi
|
||||
|
||||
# Mark permissions as granted (won't prompt again)
|
||||
mkdir -p "$(dirname "$permission_flag")" 2>/dev/null || true
|
||||
touch "$permission_flag" 2>/dev/null || true
|
||||
mkdir -p "$(dirname "$permission_flag")" 2> /dev/null || true
|
||||
touch "$permission_flag" 2> /dev/null || true
|
||||
fi
|
||||
|
||||
# Show whitelist info if patterns are active
|
||||
@@ -730,7 +730,7 @@ perform_cleanup() {
|
||||
|
||||
# Check if cache is valid (less than 2 days old)
|
||||
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
|
||||
use_cache=true
|
||||
fi
|
||||
@@ -750,7 +750,7 @@ perform_cleanup() {
|
||||
while IFS= read -r cask; do
|
||||
# Get app path from 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
|
||||
local app_name
|
||||
@@ -764,13 +764,13 @@ perform_cleanup() {
|
||||
|
||||
# Check if app exists
|
||||
[[ ! -e "/Applications/$app_name" ]] && orphaned_casks+=("$cask")
|
||||
done < <(brew list --cask 2>/dev/null || true)
|
||||
done < <(brew list --cask 2> /dev/null || true)
|
||||
fi
|
||||
|
||||
# Remove orphaned casks if found
|
||||
if [[ ${#orphaned_casks[@]} -gt 0 ]]; then
|
||||
# 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
|
||||
stop_inline_spinner
|
||||
MOLE_SPINNER_PREFIX=" " start_inline_spinner "Cleaning orphaned casks..."
|
||||
@@ -1041,7 +1041,7 @@ perform_cleanup() {
|
||||
|
||||
if [[ -f "$brew_cache_file" ]]; then
|
||||
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
|
||||
current_time=$(date +%s)
|
||||
local time_diff=$((current_time - last_cleanup))
|
||||
@@ -1185,16 +1185,16 @@ perform_cleanup() {
|
||||
local find_timeout=10
|
||||
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
|
||||
((elapsed++))
|
||||
done
|
||||
|
||||
if kill -0 $find_pid 2>/dev/null; then
|
||||
kill -TERM $find_pid 2>/dev/null || true
|
||||
wait $find_pid 2>/dev/null || true
|
||||
if kill -0 $find_pid 2> /dev/null; then
|
||||
kill -TERM $find_pid 2> /dev/null || true
|
||||
wait $find_pid 2> /dev/null || true
|
||||
else
|
||||
wait $find_pid 2>/dev/null || true
|
||||
wait $find_pid 2> /dev/null || true
|
||||
fi
|
||||
|
||||
while IFS= read -r next_dir; do
|
||||
@@ -1226,16 +1226,16 @@ perform_cleanup() {
|
||||
local find_timeout=10
|
||||
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
|
||||
((elapsed++))
|
||||
done
|
||||
|
||||
if kill -0 $find_pid 2>/dev/null; then
|
||||
kill -TERM $find_pid 2>/dev/null || true
|
||||
wait $find_pid 2>/dev/null || true
|
||||
if kill -0 $find_pid 2> /dev/null; then
|
||||
kill -TERM $find_pid 2> /dev/null || true
|
||||
wait $find_pid 2> /dev/null || true
|
||||
else
|
||||
wait $find_pid 2>/dev/null || true
|
||||
wait $find_pid 2> /dev/null || true
|
||||
fi
|
||||
|
||||
while IFS= read -r pycache; do
|
||||
|
||||
@@ -73,7 +73,7 @@ run_system_checks() {
|
||||
show_optimization_summary() {
|
||||
local safe_count="${OPTIMIZE_SAFE_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
|
||||
fi
|
||||
echo ""
|
||||
@@ -104,7 +104,6 @@ show_optimization_summary() {
|
||||
print_summary_block "success" "$summary_title" "${summary_details[@]}"
|
||||
}
|
||||
|
||||
|
||||
show_system_health() {
|
||||
local health_json="$1"
|
||||
|
||||
@@ -315,7 +314,6 @@ perform_security_fixes() {
|
||||
SECURITY_FIXES=()
|
||||
}
|
||||
|
||||
|
||||
cleanup_all() {
|
||||
stop_sudo_session
|
||||
cleanup_temp_files
|
||||
|
||||
@@ -39,7 +39,7 @@ show_suggestions() {
|
||||
# Health suggestions
|
||||
if [[ -n "${CACHE_SIZE_GB:-}" ]]; then
|
||||
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")
|
||||
has_suggestions=true
|
||||
fi
|
||||
@@ -51,7 +51,7 @@ show_suggestions() {
|
||||
fi
|
||||
|
||||
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")
|
||||
has_suggestions=true
|
||||
fi
|
||||
@@ -132,7 +132,7 @@ perform_auto_fix() {
|
||||
# Fix Firewall
|
||||
if [[ -n "${FIREWALL_DISABLED:-}" && "${FIREWALL_DISABLED}" == "true" ]]; then
|
||||
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"
|
||||
((fixed_count++))
|
||||
fixed_items+=("Firewall enabled")
|
||||
@@ -148,7 +148,7 @@ perform_auto_fix() {
|
||||
local pam_file="/etc/pam.d/sudo"
|
||||
if sudo bash -c "grep -q 'pam_tid.so' '$pam_file' 2>/dev/null || sed -i '' '2i\\
|
||||
auth sufficient pam_tid.so
|
||||
' '$pam_file'" 2>/dev/null; then
|
||||
' '$pam_file'" 2> /dev/null; then
|
||||
echo -e "${GREEN}✓${NC} Touch ID configured"
|
||||
((fixed_count++))
|
||||
fixed_items+=("Touch ID configured for sudo")
|
||||
|
||||
@@ -5,13 +5,13 @@
|
||||
check_touchid_sudo() {
|
||||
# Check if Touch ID is configured for 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"
|
||||
else
|
||||
# Check if Touch ID is supported
|
||||
local is_supported=false
|
||||
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
|
||||
fi
|
||||
elif [[ "$(uname -m)" == "arm64" ]]; then
|
||||
@@ -40,8 +40,8 @@ check_rosetta() {
|
||||
check_git_config() {
|
||||
# Check basic Git configuration
|
||||
if command -v git > /dev/null 2>&1; then
|
||||
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_name=$(git config --global user.name 2> /dev/null || echo "")
|
||||
local git_email=$(git config --global user.email 2> /dev/null || echo "")
|
||||
|
||||
if [[ -n "$git_name" && -n "$git_email" ]]; then
|
||||
echo -e " ${GREEN}✓${NC} Git Config Configured"
|
||||
|
||||
@@ -20,14 +20,14 @@ check_disk_space() {
|
||||
|
||||
check_memory_usage() {
|
||||
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
|
||||
echo -e " ${GRAY}-${NC} Memory Unable to determine"
|
||||
return
|
||||
fi
|
||||
|
||||
local vm_output
|
||||
vm_output=$(vm_stat 2>/dev/null || echo "")
|
||||
vm_output=$(vm_stat 2> /dev/null || echo "")
|
||||
|
||||
local page_size
|
||||
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
|
||||
if [[ -d "$cache_path" ]]; then
|
||||
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
|
||||
cache_size_kb=$((cache_size_kb + size_output))
|
||||
fi
|
||||
@@ -162,7 +162,7 @@ check_cache_size() {
|
||||
check_swap_usage() {
|
||||
# Check swap usage
|
||||
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
|
||||
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]//')
|
||||
@@ -184,13 +184,13 @@ check_swap_usage() {
|
||||
check_timemachine() {
|
||||
# Check Time Machine backup status
|
||||
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
|
||||
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}"
|
||||
else
|
||||
# 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
|
||||
echo -e " ${GREEN}✓${NC} Time Machine Backup active"
|
||||
else
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
check_filevault() {
|
||||
# Check FileVault encryption status
|
||||
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
|
||||
echo -e " ${GREEN}✓${NC} FileVault Enabled"
|
||||
else
|
||||
@@ -18,7 +18,7 @@ check_filevault() {
|
||||
check_firewall() {
|
||||
# Check firewall status
|
||||
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
|
||||
echo -e " ${GREEN}✓${NC} Firewall Enabled"
|
||||
else
|
||||
@@ -32,7 +32,7 @@ check_firewall() {
|
||||
check_gatekeeper() {
|
||||
# Check Gatekeeper status
|
||||
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
|
||||
echo -e " ${GREEN}✓${NC} Gatekeeper Active"
|
||||
unset GATEKEEPER_DISABLED
|
||||
@@ -48,7 +48,7 @@ check_gatekeeper() {
|
||||
check_sip() {
|
||||
# Check System Integrity Protection
|
||||
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
|
||||
echo -e " ${GREEN}✓${NC} SIP Enabled"
|
||||
else
|
||||
|
||||
@@ -8,11 +8,11 @@ CACHE_DIR="${HOME}/.cache/mole"
|
||||
CACHE_TTL=600 # 10 minutes in seconds
|
||||
|
||||
# Ensure cache directory exists
|
||||
mkdir -p "$CACHE_DIR" 2>/dev/null || true
|
||||
mkdir -p "$CACHE_DIR" 2> /dev/null || true
|
||||
|
||||
clear_cache_file() {
|
||||
local file="$1"
|
||||
rm -f "$file" 2>/dev/null || true
|
||||
rm -f "$file" 2> /dev/null || true
|
||||
}
|
||||
|
||||
reset_brew_cache() {
|
||||
@@ -37,7 +37,7 @@ is_cache_valid() {
|
||||
return 1
|
||||
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 ]]
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ check_homebrew_updates() {
|
||||
local cask_count=0
|
||||
|
||||
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}
|
||||
cask_count=${cask_count:-0}
|
||||
else
|
||||
@@ -61,18 +61,18 @@ check_homebrew_updates() {
|
||||
fi
|
||||
|
||||
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
|
||||
formula_count=$(echo "$outdated_list" | wc -l | tr -d ' ')
|
||||
fi
|
||||
|
||||
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
|
||||
cask_count=$(echo "$cask_list" | wc -l | tr -d ' ')
|
||||
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
|
||||
if [[ -t 1 ]]; then
|
||||
@@ -110,7 +110,7 @@ get_software_updates() {
|
||||
if [[ -z "$SOFTWARE_UPDATE_LIST" ]]; then
|
||||
# Check cache first
|
||||
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
|
||||
# Show spinner while checking (only on first call)
|
||||
local show_spinner=false
|
||||
@@ -120,9 +120,9 @@ get_software_updates() {
|
||||
export SOFTWAREUPDATE_SPINNER_SHOWN="true"
|
||||
fi
|
||||
|
||||
SOFTWARE_UPDATE_LIST=$(softwareupdate -l 2>/dev/null || echo "")
|
||||
SOFTWARE_UPDATE_LIST=$(softwareupdate -l 2> /dev/null || echo "")
|
||||
# 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
|
||||
if [[ "$show_spinner" == "true" ]]; then
|
||||
@@ -208,7 +208,7 @@ check_mole_update() {
|
||||
# Auto-detect version from mole main script
|
||||
local current_version
|
||||
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
|
||||
current_version="${VERSION:-unknown}"
|
||||
fi
|
||||
@@ -220,7 +220,7 @@ check_mole_update() {
|
||||
|
||||
# Check cache first
|
||||
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
|
||||
# Show spinner while checking
|
||||
if [[ -t 1 ]]; then
|
||||
@@ -229,10 +229,10 @@ check_mole_update() {
|
||||
|
||||
# Try to get latest version from GitHub
|
||||
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
|
||||
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
|
||||
|
||||
|
||||
@@ -532,9 +532,9 @@ is_clamshell_mode() {
|
||||
|
||||
# Check if lid is closed; ignore pipeline failures so set -e doesn't exit
|
||||
local clamshell_state=""
|
||||
clamshell_state=$( (ioreg -r -k AppleClamshellState -d 4 2>/dev/null \
|
||||
| grep "AppleClamshellState" \
|
||||
| head -1) || true )
|
||||
clamshell_state=$( (ioreg -r -k AppleClamshellState -d 4 2> /dev/null |
|
||||
grep "AppleClamshellState" |
|
||||
head -1) || true)
|
||||
|
||||
if [[ "$clamshell_state" =~ \"AppleClamshellState\"\ =\ Yes ]]; then
|
||||
return 0 # Lid is closed
|
||||
@@ -549,7 +549,7 @@ _request_password() {
|
||||
local show_hint=true
|
||||
|
||||
# Extra safety: ensure sudo cache is cleared before password input
|
||||
sudo -k 2>/dev/null
|
||||
sudo -k 2> /dev/null
|
||||
|
||||
while ((attempts < 3)); do
|
||||
local password=""
|
||||
@@ -637,11 +637,11 @@ request_sudo_access() {
|
||||
local elapsed=0
|
||||
local timeout=50 # 50 * 0.1s = 5 seconds
|
||||
while ((elapsed < timeout)); do
|
||||
if ! kill -0 "$sudo_pid" 2>/dev/null; then
|
||||
if ! kill -0 "$sudo_pid" 2> /dev/null; then
|
||||
# Process exited
|
||||
wait "$sudo_pid" 2>/dev/null
|
||||
wait "$sudo_pid" 2> /dev/null
|
||||
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
|
||||
return 0
|
||||
fi
|
||||
@@ -655,13 +655,13 @@ request_sudo_access() {
|
||||
# Touch ID failed/cancelled - clean up thoroughly before password input
|
||||
|
||||
# Kill the sudo process if still running
|
||||
if kill -0 "$sudo_pid" 2>/dev/null; then
|
||||
kill -9 "$sudo_pid" 2>/dev/null
|
||||
wait "$sudo_pid" 2>/dev/null || true
|
||||
if kill -0 "$sudo_pid" 2> /dev/null; then
|
||||
kill -9 "$sudo_pid" 2> /dev/null
|
||||
wait "$sudo_pid" 2> /dev/null || true
|
||||
fi
|
||||
|
||||
# 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
|
||||
# Without this delay, subsequent sudo calls may re-trigger Touch ID
|
||||
@@ -702,17 +702,17 @@ update_via_homebrew() {
|
||||
# Use background process to allow interruption
|
||||
local brew_update_timeout="${MO_BREW_UPDATE_TIMEOUT:-300}"
|
||||
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) &
|
||||
local brew_pid=$!
|
||||
local elapsed=0
|
||||
|
||||
# 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
|
||||
kill -TERM $brew_pid 2>/dev/null || true
|
||||
wait $brew_pid 2>/dev/null || true
|
||||
kill -TERM $brew_pid 2> /dev/null || true
|
||||
wait $brew_pid 2> /dev/null || true
|
||||
if [[ -t 1 ]]; then stop_inline_spinner; fi
|
||||
rm -f "$brew_tmp_file"
|
||||
log_error "Homebrew update timed out (${brew_update_timeout}s)"
|
||||
@@ -722,7 +722,7 @@ update_via_homebrew() {
|
||||
((elapsed++))
|
||||
done
|
||||
|
||||
wait $brew_pid 2>/dev/null || {
|
||||
wait $brew_pid 2> /dev/null || {
|
||||
if [[ -t 1 ]]; then stop_inline_spinner; fi
|
||||
rm -f "$brew_tmp_file"
|
||||
log_error "Homebrew update failed"
|
||||
|
||||
@@ -22,13 +22,13 @@ _pm_get_terminal_height() {
|
||||
# Try stty size first (most reliable, real-time)
|
||||
# Use </dev/tty to ensure we read from terminal even if stdin is redirected
|
||||
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
|
||||
|
||||
# Fallback to tput
|
||||
if [[ -z "$height" || $height -le 0 ]]; 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
|
||||
height=24
|
||||
fi
|
||||
|
||||
@@ -14,13 +14,13 @@ _ms_get_terminal_height() {
|
||||
# Try stty size first (most reliable, real-time)
|
||||
# Use </dev/tty to ensure we read from terminal even if stdin is redirected
|
||||
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
|
||||
|
||||
# Fallback to tput
|
||||
if [[ -z "$height" || $height -le 0 ]]; 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
|
||||
height=24
|
||||
fi
|
||||
|
||||
@@ -8,7 +8,10 @@ readonly MAIL_DOWNLOADS_MIN_KB=5120 # ~5MB threshold
|
||||
|
||||
_opt_get_dir_size_kb() {
|
||||
local path="$1"
|
||||
[[ -e "$path" ]] || { echo 0; return; }
|
||||
[[ -e "$path" ]] || {
|
||||
echo 0
|
||||
return
|
||||
}
|
||||
du -sk "$path" 2> /dev/null | awk '{print $1}' || echo 0
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ _start_sudo_keepalive() {
|
||||
sleep 30
|
||||
kill -0 "$$" 2> /dev/null || exit
|
||||
done
|
||||
) >/dev/null 2>&1 &
|
||||
) > /dev/null 2>&1 &
|
||||
|
||||
local pid=$!
|
||||
[[ "${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)"
|
||||
if ((${#details[@]} > 0)); then
|
||||
detail_str="($(IFS=', '; printf '%s' "${details[*]}"))"
|
||||
detail_str="($(
|
||||
IFS=', '
|
||||
printf '%s' "${details[*]}"
|
||||
))"
|
||||
fi
|
||||
printf " • Homebrew %s" "$detail_str"
|
||||
}
|
||||
@@ -271,7 +274,7 @@ perform_updates() {
|
||||
_perform_appstore_update() {
|
||||
echo -e "${BLUE}Updating App Store apps...${NC}"
|
||||
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
|
||||
echo -e " ${GRAY}Installing all available updates${NC}"
|
||||
@@ -293,7 +296,7 @@ _perform_appstore_update() {
|
||||
echo -e "${RED}✗${NC} App Store update failed"
|
||||
fi
|
||||
fi
|
||||
rm -f "$appstore_log" 2>/dev/null || true
|
||||
rm -f "$appstore_log" 2> /dev/null || true
|
||||
reset_softwareupdate_cache
|
||||
echo ""
|
||||
}
|
||||
@@ -304,7 +307,7 @@ _perform_macos_update() {
|
||||
echo -e "${YELLOW}Note:${NC} System update may require restart"
|
||||
|
||||
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 sudo softwareupdate -i -r 2>&1 | tee "$macos_log" | grep -v "^$"; then
|
||||
@@ -322,11 +325,11 @@ _perform_macos_update() {
|
||||
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"
|
||||
fi
|
||||
|
||||
rm -f "$macos_log" 2>/dev/null || true
|
||||
rm -f "$macos_log" 2> /dev/null || true
|
||||
reset_softwareupdate_cache
|
||||
echo ""
|
||||
}
|
||||
|
||||
@@ -108,9 +108,11 @@ setup() {
|
||||
|
||||
run bash --noprofile --norc -c "cd '$PROJECT_ROOT'; printf \$' \\n' | HOME='$HOME' ./mo clean --whitelist"
|
||||
[ "$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"
|
||||
[ "$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