1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-04 13:16:47 +00:00
Files
Mole/install.sh
Tw93 f91e89cea9 Enable Homebrew installation support
- Created homebrew-tap repository
- Updated install script to try Homebrew first with fallback
- Enabled Homebrew installation in README
- Simplified user experience with automatic method selection
2025-09-23 14:50:22 +08:00

179 lines
4.7 KiB
Bash
Executable File

#!/bin/bash
# Clean Your Mac - Installation Script
set -e
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
log_info() { echo -e "${BLUE}$1${NC}"; }
log_success() { echo -e "${GREEN}$1${NC}"; }
log_warning() { echo -e "${YELLOW}⚠️ $1${NC}"; }
log_error() { echo -e "${RED}$1${NC}"; }
echo -e "${BLUE}🧹 Installing Clean Mac...${NC}"
# Check system compatibility
if [[ "$OSTYPE" != "darwin"* ]]; then
log_error "This tool only supports macOS"
exit 1
fi
# Check for arguments
FORCE_DIRECT=false
UNINSTALL=false
for arg in "$@"; do
case $arg in
--direct)
FORCE_DIRECT=true
;;
--uninstall)
UNINSTALL=true
;;
--help|-h)
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " --direct Force direct installation (skip Homebrew)"
echo " --uninstall Uninstall clean-mac"
echo " --help Show this help message"
exit 0
;;
esac
done
# Uninstall function
uninstall_clean() {
log_info "Uninstalling Clean Mac..."
# Check if installed via Homebrew
if command -v brew >/dev/null 2>&1 && brew list clean-mac >/dev/null 2>&1; then
brew uninstall clean-mac
log_success "Uninstalled via Homebrew"
elif [[ -f "/usr/local/bin/clean" ]]; then
sudo rm -f "/usr/local/bin/clean"
log_success "Removed from /usr/local/bin"
else
log_warning "Clean Mac is not installed"
fi
exit 0
}
if [[ "$UNINSTALL" == "true" ]]; then
uninstall_clean
fi
# Check if already installed
if command -v clean >/dev/null 2>&1 && [[ "$FORCE_DIRECT" != "true" ]]; then
log_warning "Clean Mac is already installed"
echo " Location: $(which clean)"
echo " Version: $(clean --help | head -1 || echo 'Unknown')"
echo ""
echo "Run with --uninstall to remove, or --direct to reinstall"
exit 0
fi
# Installation methods
install_via_homebrew() {
log_info "Installing via Homebrew..."
if ! command -v brew >/dev/null 2>&1; then
log_error "Homebrew is not installed"
echo "Install Homebrew first: https://brew.sh"
return 1
fi
# Add tap if not already added
if ! brew tap | grep -q "tw93/tap"; then
log_info "Adding tap: tw93/tap"
brew tap tw93/tap
fi
# Install clean-mac
brew install clean-mac
return $?
}
install_direct() {
log_info "Installing directly to /usr/local/bin..."
# Create directory
INSTALL_DIR="/usr/local/bin"
if [[ ! -d "$INSTALL_DIR" ]]; then
log_info "Creating install directory..."
sudo mkdir -p "$INSTALL_DIR"
fi
# Download script
log_info "Downloading latest version..."
TEMP_FILE=$(mktemp)
if ! curl -fsSL https://raw.githubusercontent.com/tw93/clean-mac/main/clean.sh -o "$TEMP_FILE"; then
log_error "Download failed"
rm -f "$TEMP_FILE"
return 1
fi
# Verify download
if [[ ! -s "$TEMP_FILE" ]]; then
log_error "Downloaded file is empty"
rm -f "$TEMP_FILE"
return 1
fi
# Install
log_info "Installing..."
sudo cp "$TEMP_FILE" "$INSTALL_DIR/clean"
sudo chmod +x "$INSTALL_DIR/clean"
rm "$TEMP_FILE"
return 0
}
# Choose installation method
if [[ "$FORCE_DIRECT" == "true" ]]; then
install_direct
INSTALL_SUCCESS=$?
else
# Try Homebrew first, fallback to direct
if command -v brew >/dev/null 2>&1; then
log_info "Trying Homebrew installation..."
install_via_homebrew
INSTALL_SUCCESS=$?
if [[ $INSTALL_SUCCESS -ne 0 ]]; then
log_warning "Homebrew installation failed, using direct installation..."
install_direct
INSTALL_SUCCESS=$?
fi
else
log_info "Homebrew not found, using direct installation..."
install_direct
INSTALL_SUCCESS=$?
fi
fi
# Verify installation
if [[ $INSTALL_SUCCESS -eq 0 ]] && command -v clean >/dev/null 2>&1; then
log_success "Installation completed successfully!"
echo ""
echo -e "${GREEN}Usage:${NC}"
echo -e " ${BLUE}clean${NC} - User-level cleanup (no password required)"
echo -e " ${BLUE}clean --system${NC} - Deep system cleanup (password required)"
echo -e " ${BLUE}clean --help${NC} - Show help message"
echo ""
echo -e "${GREEN}Try it now:${NC} clean"
else
log_error "Installation failed"
echo ""
echo "You may need to:"
echo "1. Restart your terminal"
echo "2. Add /usr/local/bin to your PATH:"
echo " export PATH=\"/usr/local/bin:\$PATH\""
echo "3. Run the installer with --direct flag"
exit 1
fi