-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·104 lines (89 loc) · 2.46 KB
/
install.sh
File metadata and controls
executable file
·104 lines (89 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/bin/bash
set -euo pipefail
REPO="igl/smplcli"
INSTALL_DIR="$HOME/.smplcli"
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NC='\033[0m' # No Color
info() { echo -e "${GREEN}[smplcli]${NC} $1"; }
warn() { echo -e "${YELLOW}[smplcli]${NC} $1"; }
error() {
echo -e "${RED}[smplcli]${NC} $1" >&2
exit 1
}
# Check for jq dependency
if ! command -v jq &>/dev/null; then
error "jq is required but not installed.
Install it with:
macOS: brew install jq
Ubuntu: sudo apt install jq
Arch: sudo pacman -S jq"
fi
# Check for curl
if ! command -v curl &>/dev/null; then
error "curl is required but not installed."
fi
# Get latest release tag from GitHub API
info "Fetching latest release..."
set +e
API_RESPONSE=$(curl -fsSL "https://api.github.com/repos/$REPO/releases/latest" 2>&1)
CURL_EXIT=$?
set -e
if [ $CURL_EXIT -ne 0 ]; then
warn "Failed to fetch release info: $API_RESPONSE"
warn "Installing from main branch..."
DOWNLOAD_URL="https://raw.githubusercontent.com/$REPO/main/cli.sh"
else
LATEST_TAG=$(echo "$API_RESPONSE" | jq -r '.tag_name // empty' 2>/dev/null)
if [ -z "$LATEST_TAG" ]; then
warn "No releases found. Installing from main branch..."
DOWNLOAD_URL="https://raw.githubusercontent.com/$REPO/main/cli.sh"
else
info "Found release: $LATEST_TAG"
DOWNLOAD_URL="https://raw.githubusercontent.com/$REPO/$LATEST_TAG/cli.sh"
fi
fi
# Create install directory
mkdir -p "$INSTALL_DIR"
# Download cli.sh
info "Downloading cli.sh..."
if ! curl -fsSL "$DOWNLOAD_URL" -o "$INSTALL_DIR/cli.sh"; then
error "Failed to download cli.sh"
fi
chmod +x "$INSTALL_DIR/cli.sh"
# Determine shell rc file
detect_shell_rc() {
local shell_name
shell_name=$(basename "$SHELL")
case "$shell_name" in
zsh) echo "$HOME/.zshrc" ;;
bash)
# Prefer .bashrc, fall back to .bash_profile on macOS
if [ -f "$HOME/.bashrc" ]; then
echo "$HOME/.bashrc"
else
echo "$HOME/.bash_profile"
fi
;;
*) echo "$HOME/.profile" ;;
esac
}
RC_FILE=$(detect_shell_rc)
SOURCE_LINE="source \"\$HOME/.smplcli/cli.sh\""
# Add source line if not already present
if ! grep -qF ".smplcli/cli.sh" "$RC_FILE" 2>/dev/null; then
info "Adding source line to $RC_FILE..."
{
echo ""
echo "# smplcli - unified task runner"
echo "$SOURCE_LINE"
} >>"$RC_FILE"
else
info "Source line already exists in $RC_FILE"
fi
info "Installation complete!"
echo ""
echo "To use cli immediately, run: source $INSTALL_DIR/cli.sh"
echo "Or open a new terminal (cli will be available automatically)."