diff --git a/Formula/clean-mac.rb b/Formula/clean-mac.rb deleted file mode 100644 index 4821f97..0000000 --- a/Formula/clean-mac.rb +++ /dev/null @@ -1,30 +0,0 @@ -class CleanMac < Formula - desc "Clean Mac - Deep Clean Your Mac with One Click" - homepage "https://github.com/tw93/clean-mac" - url "https://github.com/tw93/clean-mac/archive/refs/tags/v1.0.0.tar.gz" - sha256 "8274af48615205ab3ce4b75c9b2e898a53b4d49972cd7757fe8b6fe27603a5ab" - license "MIT" - head "https://github.com/tw93/clean-mac.git", branch: "main" - - def install - bin.install "clean.sh" => "clean" - end - - test do - # Test that the script is executable and shows help - assert_match "Clean Mac", shell_output("#{bin}/clean --help", 0) - end - - def caveats - <<~EOS - Clean Mac has been installed! - - Usage: - clean - User-level cleanup (no password required) - clean --system - Deep system cleanup (password required) - clean --help - Show help message - - For Apple Silicon Macs, the tool includes M-series specific optimizations. - EOS - end -end \ No newline at end of file diff --git a/Formula/mole.rb b/Formula/mole.rb new file mode 100644 index 0000000..773a4c7 --- /dev/null +++ b/Formula/mole.rb @@ -0,0 +1,14 @@ +class Mole < Formula + desc "Mole - Clean your Mac" + homepage "https://github.com/tw93/mole" + license "MIT" + head "https://github.com/tw93/mole.git", branch: "main" + + def install + bin.install "mole" + end + + test do + assert_match "Mole", shell_output("#{bin}/mole --help", 0) + end +end diff --git a/README.md b/README.md index 32666e5..2fb1a8e 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ ## Installation ```bash -curl -fsSL https://raw.githubusercontent.com/tw93/clean-mac/main/install.sh | bash +curl -fsSL https://raw.githubusercontent.com/tw93/mole/main/install.sh | bash ``` ## Usage @@ -86,7 +86,7 @@ If Mole has been helpful to you: - **Star this repository** and share with fellow Mac users - **Report issues** or suggest new cleanup targets -- I have two cats, if you think Clean helps you, you can feed them canned food 🥩🍤 +- I have two cats. If Mole helps you, you can feed them canned food 🥩🍤 ## License diff --git a/bin/uninstall.sh b/bin/uninstall.sh index 029c386..1becbf8 100755 --- a/bin/uninstall.sh +++ b/bin/uninstall.sh @@ -34,7 +34,7 @@ should_preserve_bundle() { # Help information show_help() { - echo "Clean Mac - Interactive App Uninstaller" + echo "Mole - Interactive App Uninstaller" echo "========================================" echo "" echo "Description: Interactive tool to uninstall applications and clean their data" @@ -394,7 +394,7 @@ trap cleanup EXIT INT TERM # Main function main() { - echo "🗑️ Clean Mac - Interactive App Uninstaller" + echo "🗑️ Mole - Interactive App Uninstaller" echo "============================================" echo @@ -444,4 +444,4 @@ main() { } # Run main function -main "$@" \ No newline at end of file +main "$@" diff --git a/install.sh b/install.sh index cbfba45..dfbde04 100755 --- a/install.sh +++ b/install.sh @@ -19,7 +19,8 @@ log_error() { echo -e "${RED}❌ $1${NC}"; } # Default installation directory INSTALL_DIR="/usr/local/bin" -CONFIG_DIR="$HOME/.config/clean" +CONFIG_DIR="$HOME/.config/mole" +SOURCE_DIR="" show_help() { cat << 'EOF' @@ -31,7 +32,7 @@ USAGE: OPTIONS: --prefix PATH Install to custom directory (default: /usr/local/bin) - --config PATH Config directory (default: ~/.config/clean) + --config PATH Config directory (default: ~/.config/mole) --uninstall Uninstall mole --help, -h Show this help @@ -47,6 +48,54 @@ The installer will: EOF } +# Resolve the directory containing source files (supports curl | bash) +resolve_source_dir() { + # 1) If script is on disk, use its directory + if [[ -n "${BASH_SOURCE[0]:-}" && -f "${BASH_SOURCE[0]}" ]]; then + local script_dir + script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + if [[ -f "$script_dir/mole" || -d "$script_dir/bin" || -d "$script_dir/lib" ]]; then + SOURCE_DIR="$script_dir" + return 0 + fi + fi + + # 2) If CLEAN_SOURCE_DIR env is provided, honor it + if [[ -n "${CLEAN_SOURCE_DIR:-}" && -d "$CLEAN_SOURCE_DIR" ]]; then + SOURCE_DIR="$CLEAN_SOURCE_DIR" + return 0 + fi + + # 3) Fallback: fetch repository to a temp directory (works for curl | bash) + local tmp + tmp="$(mktemp -d)" + trap 'rm -rf "$tmp"' EXIT + + echo "Fetching Mole source..." + if command -v curl >/dev/null 2>&1; then + # Download main branch tarball + if curl -fsSL -o "$tmp/mole.tar.gz" "https://github.com/tw93/mole/archive/refs/heads/main.tar.gz"; then + tar -xzf "$tmp/mole.tar.gz" -C "$tmp" + # Extracted folder name: mole-main + if [[ -d "$tmp/mole-main" ]]; then + SOURCE_DIR="$tmp/mole-main" + return 0 + fi + fi + fi + + # 4) Fallback to git if available + if command -v git >/dev/null 2>&1; then + if git clone --depth=1 https://github.com/tw93/mole.git "$tmp/mole" >/dev/null 2>&1; then + SOURCE_DIR="$tmp/mole" + return 0 + fi + fi + + log_error "Failed to fetch source files. Ensure curl or git is available." + exit 1 +} + # Parse command line arguments parse_args() { while [[ $# -gt 0 ]]; do @@ -125,40 +174,39 @@ create_directories() { install_files() { log_info "Installing mole files..." - # Get the directory where this script is located - SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + resolve_source_dir # Copy main executable - if [[ -f "$SCRIPT_DIR/mole" ]]; then + if [[ -f "$SOURCE_DIR/mole" ]]; then if [[ "$INSTALL_DIR" == "/usr/local/bin" ]] && [[ ! -w "$INSTALL_DIR" ]]; then - sudo cp "$SCRIPT_DIR/mole" "$INSTALL_DIR/mole" + sudo cp "$SOURCE_DIR/mole" "$INSTALL_DIR/mole" sudo chmod +x "$INSTALL_DIR/mole" else - cp "$SCRIPT_DIR/mole" "$INSTALL_DIR/mole" + cp "$SOURCE_DIR/mole" "$INSTALL_DIR/mole" chmod +x "$INSTALL_DIR/mole" fi log_success "Main executable installed to $INSTALL_DIR/mole" else - log_error "mole executable not found in $SCRIPT_DIR" + log_error "mole executable not found in ${SOURCE_DIR:-unknown}" exit 1 fi # Copy configuration and modules - if [[ -d "$SCRIPT_DIR/bin" ]]; then - cp -r "$SCRIPT_DIR/bin"/* "$CONFIG_DIR/bin/" + if [[ -d "$SOURCE_DIR/bin" ]]; then + cp -r "$SOURCE_DIR/bin"/* "$CONFIG_DIR/bin/" chmod +x "$CONFIG_DIR/bin"/* log_success "Modules copied to $CONFIG_DIR/bin" fi - if [[ -d "$SCRIPT_DIR/lib" ]]; then - cp -r "$SCRIPT_DIR/lib"/* "$CONFIG_DIR/lib/" + if [[ -d "$SOURCE_DIR/lib" ]]; then + cp -r "$SOURCE_DIR/lib"/* "$CONFIG_DIR/lib/" log_success "Libraries copied to $CONFIG_DIR/lib" fi # Copy other files if they exist for file in README.md LICENSE; do - if [[ -f "$SCRIPT_DIR/$file" ]]; then - cp "$SCRIPT_DIR/$file" "$CONFIG_DIR/" + if [[ -f "$SOURCE_DIR/$file" ]]; then + cp "$SOURCE_DIR/$file" "$CONFIG_DIR/" fi done @@ -271,4 +319,4 @@ main() { # Run installation parse_args "$@" -main \ No newline at end of file +main diff --git a/mole b/mole index faf67df..10aef4c 100755 --- a/mole +++ b/mole @@ -38,7 +38,7 @@ COMMANDS: mole uninstall # Remove applications completely mole --help # Show this help message -For more information, visit: https://github.com/tw93/clean-mac +For more information, visit: https://github.com/tw93/mole EOF } @@ -60,7 +60,7 @@ show_main_menu() { show_menu_option 1 "Clean System - Remove junk files and optimize" "$([[ $selected -eq 1 ]] && echo true || echo false)" show_menu_option 2 "Uninstall Apps - Completely remove applications" "$([[ $selected -eq 2 ]] && echo true || echo false)" show_menu_option 3 "Help & Information - Usage guide and tips" "$([[ $selected -eq 3 ]] && echo true || echo false)" - show_menu_option 4 "Exit - Close Clean" "$([[ $selected -eq 4 ]] && echo true || echo false)" + show_menu_option 4 "Exit - Close Mole" "$([[ $selected -eq 4 ]] && echo true || echo false)" if [[ "$redraw_full" == "true" ]]; then echo "" @@ -166,4 +166,4 @@ main() { esac } -main "$@" \ No newline at end of file +main "$@"