Skip to content

Commit 1516aca

Browse files
committed
feat: Add curl|bash install script
- Auto-detect OS (darwin/linux) and architecture (amd64/arm64) - Download latest release from GitHub - Install to /usr/local/bin with sudo if needed - Colorful output with success/error messages
1 parent 37beb8d commit 1516aca

1 file changed

Lines changed: 111 additions & 0 deletions

File tree

install.sh

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#!/bin/bash
2+
#
3+
# Install script for dev-cleaner
4+
# Usage: curl -fsSL https://raw.githubusercontent.com/thanhdevapp/mac-dev-cleaner-cli/dev-mvp/install.sh | bash
5+
#
6+
7+
set -e
8+
9+
REPO="thanhdevapp/mac-dev-cleaner-cli"
10+
INSTALL_DIR="/usr/local/bin"
11+
BINARY_NAME="dev-cleaner"
12+
13+
# Colors
14+
RED='\033[0;31m'
15+
GREEN='\033[0;32m'
16+
YELLOW='\033[1;33m'
17+
NC='\033[0m' # No Color
18+
19+
echo -e "${GREEN}📦 Installing dev-cleaner...${NC}"
20+
21+
# Detect OS
22+
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
23+
case $OS in
24+
darwin) OS="darwin" ;;
25+
linux) OS="linux" ;;
26+
*)
27+
echo -e "${RED}❌ Unsupported OS: $OS${NC}"
28+
echo "dev-cleaner currently supports macOS and Linux only."
29+
exit 1
30+
;;
31+
esac
32+
33+
# Detect architecture
34+
ARCH=$(uname -m)
35+
case $ARCH in
36+
x86_64) ARCH="amd64" ;;
37+
arm64|aarch64) ARCH="arm64" ;;
38+
*)
39+
echo -e "${RED}❌ Unsupported architecture: $ARCH${NC}"
40+
exit 1
41+
;;
42+
esac
43+
44+
echo " OS: $OS"
45+
echo " Arch: $ARCH"
46+
47+
# Get latest release version
48+
echo -e "${YELLOW}🔍 Fetching latest version...${NC}"
49+
LATEST=$(curl -sL https://api.github.com/repos/$REPO/releases/latest 2>/dev/null | grep '"tag_name"' | sed -E 's/.*"([^"]+)".*/\1/')
50+
51+
if [ -z "$LATEST" ]; then
52+
echo -e "${YELLOW}⚠️ Could not fetch latest release, using dev build...${NC}"
53+
# Fallback to dev build from artifacts
54+
echo -e "${RED}❌ No releases available yet. Please build from source:${NC}"
55+
echo " git clone https://github.com/$REPO.git"
56+
echo " cd mac-dev-cleaner-cli"
57+
echo " go build -o dev-cleaner ."
58+
echo " sudo mv dev-cleaner /usr/local/bin/"
59+
exit 1
60+
fi
61+
62+
echo " Version: $LATEST"
63+
64+
# Construct download URL
65+
# Format: dev-cleaner_v1.0.0_darwin_arm64.tar.gz
66+
VERSION_NUM=${LATEST#v}
67+
DOWNLOAD_URL="https://github.com/$REPO/releases/download/$LATEST/dev-cleaner_${VERSION_NUM}_${OS}_${ARCH}.tar.gz"
68+
69+
echo -e "${YELLOW}📥 Downloading from: $DOWNLOAD_URL${NC}"
70+
71+
# Create temp directory
72+
TMP_DIR=$(mktemp -d)
73+
trap "rm -rf $TMP_DIR" EXIT
74+
75+
# Download and extract
76+
if ! curl -sL "$DOWNLOAD_URL" | tar xz -C "$TMP_DIR" 2>/dev/null; then
77+
echo -e "${RED}❌ Failed to download release${NC}"
78+
echo "URL: $DOWNLOAD_URL"
79+
exit 1
80+
fi
81+
82+
# Check if binary exists
83+
if [ ! -f "$TMP_DIR/$BINARY_NAME" ]; then
84+
echo -e "${RED}❌ Binary not found in archive${NC}"
85+
ls -la "$TMP_DIR"
86+
exit 1
87+
fi
88+
89+
# Install binary
90+
echo -e "${YELLOW}🔧 Installing to $INSTALL_DIR...${NC}"
91+
if [ -w "$INSTALL_DIR" ]; then
92+
mv "$TMP_DIR/$BINARY_NAME" "$INSTALL_DIR/"
93+
chmod +x "$INSTALL_DIR/$BINARY_NAME"
94+
else
95+
echo " (requires sudo)"
96+
sudo mv "$TMP_DIR/$BINARY_NAME" "$INSTALL_DIR/"
97+
sudo chmod +x "$INSTALL_DIR/$BINARY_NAME"
98+
fi
99+
100+
# Verify installation
101+
if command -v $BINARY_NAME &> /dev/null; then
102+
echo ""
103+
echo -e "${GREEN}✅ Successfully installed dev-cleaner!${NC}"
104+
echo ""
105+
$BINARY_NAME --version
106+
echo ""
107+
echo "Run 'dev-cleaner scan' to get started"
108+
else
109+
echo -e "${YELLOW}⚠️ Installed but not in PATH${NC}"
110+
echo "Add $INSTALL_DIR to your PATH or run: $INSTALL_DIR/$BINARY_NAME"
111+
fi

0 commit comments

Comments
 (0)