-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinstall.sh
More file actions
242 lines (214 loc) · 6.71 KB
/
install.sh
File metadata and controls
242 lines (214 loc) · 6.71 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
#!/usr/bin/env bash
# Crabcode installer
set -e
REPO="https://github.com/promptfoo/crabcode"
INSTALL_DIR="${CRABCODE_INSTALL_DIR:-$HOME/.local/bin}"
SCRIPT_NAME="crabcode"
ALIAS_NAME="crab"
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
CYAN='\033[0;36m'
NC='\033[0m'
echo -e "${CYAN}Installing crabcode...${NC}"
# Detect OS and package manager
detect_os() {
if [[ "$OSTYPE" == "darwin"* ]]; then
echo "macos"
elif [[ -f /etc/debian_version ]]; then
echo "debian"
elif [[ -f /etc/redhat-release ]]; then
echo "redhat"
elif [[ -f /etc/arch-release ]]; then
echo "arch"
else
echo "unknown"
fi
}
# Install a package using the appropriate package manager
install_package() {
local package="$1"
local os=$(detect_os)
echo -e "${CYAN}Installing $package...${NC}"
case "$os" in
macos)
if command -v brew &>/dev/null; then
brew install "$package"
else
echo -e "${RED}Error: Homebrew not found. Install from https://brew.sh${NC}"
echo "Then run: brew install $package"
return 1
fi
;;
debian)
if command -v apt-get &>/dev/null; then
sudo apt-get update && sudo apt-get install -y "$package"
else
echo -e "${RED}Error: apt-get not found.${NC}"
return 1
fi
;;
redhat)
if command -v dnf &>/dev/null; then
sudo dnf install -y "$package"
elif command -v yum &>/dev/null; then
sudo yum install -y "$package"
else
echo -e "${RED}Error: dnf/yum not found.${NC}"
return 1
fi
;;
arch)
if command -v pacman &>/dev/null; then
sudo pacman -S --noconfirm "$package"
else
echo -e "${RED}Error: pacman not found.${NC}"
return 1
fi
;;
*)
echo -e "${RED}Unknown OS. Please install $package manually.${NC}"
return 1
;;
esac
}
# Check and install dependencies
echo "Checking dependencies..."
# Check git (required, should already be installed)
if ! command -v git &>/dev/null; then
echo -e "${YELLOW}git not found. Installing...${NC}"
install_package git || {
echo -e "${RED}Error: Failed to install git. Please install manually.${NC}"
exit 1
}
fi
# Check tmux
if ! command -v tmux &>/dev/null; then
echo -e "${YELLOW}tmux not found. Installing...${NC}"
install_package tmux || {
echo -e "${RED}Error: Failed to install tmux. Please install manually:${NC}"
echo " brew install tmux # macOS"
echo " apt install tmux # Ubuntu/Debian"
exit 1
}
fi
# Check yq
if ! command -v yq &>/dev/null; then
echo -e "${YELLOW}yq not found. Installing...${NC}"
install_package yq || {
echo -e "${YELLOW}Warning: Failed to install yq. Some features may not work.${NC}"
echo "Install manually:"
echo " brew install yq # macOS"
echo " apt install yq # Ubuntu/Debian"
echo ""
echo "Continuing installation anyway..."
}
fi
# Check zip (optional, for toolkit share)
if ! command -v zip &>/dev/null; then
echo -e "${YELLOW}zip not found. Installing...${NC}"
install_package zip || {
echo -e "${YELLOW}Warning: zip not installed. Toolkit share may not work.${NC}"
}
fi
# Check jq (optional, for Slack integration)
if ! command -v jq &>/dev/null; then
echo -e "${YELLOW}jq not found. Installing...${NC}"
install_package jq || {
echo -e "${YELLOW}Warning: jq not installed. Slack integration may not work.${NC}"
}
fi
echo -e "${GREEN}All dependencies installed.${NC}"
echo ""
# Create install directory
mkdir -p "$INSTALL_DIR"
# Download the script
echo "Downloading crabcode..."
if command -v curl &>/dev/null; then
curl -fsSL "$REPO/raw/main/src/crabcode" -o "$INSTALL_DIR/$SCRIPT_NAME"
elif command -v wget &>/dev/null; then
wget -q "$REPO/raw/main/src/crabcode" -O "$INSTALL_DIR/$SCRIPT_NAME"
else
echo -e "${RED}Error: curl or wget required for download.${NC}"
exit 1
fi
chmod +x "$INSTALL_DIR/$SCRIPT_NAME"
# Create 'crab' symlink
echo "Creating 'crab' alias..."
ln -sf "$INSTALL_DIR/$SCRIPT_NAME" "$INSTALL_DIR/$ALIAS_NAME"
# Add to PATH if needed
add_to_path() {
local shell_profile=""
local export_line="export PATH=\"\$PATH:$INSTALL_DIR\""
# Detect shell and profile file
case "$SHELL" in
*/zsh)
shell_profile="$HOME/.zshrc"
;;
*/bash)
if [[ -f "$HOME/.bash_profile" ]]; then
shell_profile="$HOME/.bash_profile"
else
shell_profile="$HOME/.bashrc"
fi
;;
*)
# Default to .profile for other shells
shell_profile="$HOME/.profile"
;;
esac
# Check if already in the profile
if [[ -f "$shell_profile" ]] && grep -q "$INSTALL_DIR" "$shell_profile" 2>/dev/null; then
echo -e "${GREEN}PATH already configured in $shell_profile${NC}"
return 0
fi
# Add to profile
echo "" >> "$shell_profile"
echo "# Added by crabcode installer" >> "$shell_profile"
echo "$export_line" >> "$shell_profile"
echo -e "${GREEN}Added $INSTALL_DIR to PATH in $shell_profile${NC}"
echo -e "${YELLOW}Run 'source $shell_profile' or open a new terminal to use crab${NC}"
}
# Check if install directory is in PATH
if [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then
echo ""
echo -e "${YELLOW}$INSTALL_DIR is not in your PATH.${NC}"
add_to_path
echo ""
fi
echo ""
echo ' \___/'
echo ' ( •_•) Installation complete!'
echo -e " /)${GREEN}🦀${NC}(\\"
echo ' < >'
echo ""
# Determine if PATH needs reloading and which profile to source
if [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then
# Figure out the right profile file for the message
case "$SHELL" in
*/zsh) _profile="$HOME/.zshrc" ;;
*/bash)
if [[ -f "$HOME/.bash_profile" ]]; then
_profile="$HOME/.bash_profile"
else
_profile="$HOME/.bashrc"
fi
;;
*) _profile="$HOME/.profile" ;;
esac
echo -e "${YELLOW}┌─────────────────────────────────────────────────┐${NC}"
echo -e "${YELLOW}│ ⚠ Run this command before using crab: │${NC}"
echo -e "${YELLOW}│ │${NC}"
echo -e "${YELLOW}│ source $_profile${NC}"
echo -e "${YELLOW}│ │${NC}"
echo -e "${YELLOW}│ Or just open a new terminal window. │${NC}"
echo -e "${YELLOW}└─────────────────────────────────────────────────┘${NC}"
echo ""
echo "Then get started:"
else
echo "Get started:"
fi
echo " crab init # create your config"
echo " crab ws 1 # start your first workspace"
echo " crab cheat # quick reference"
echo ""