-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·278 lines (229 loc) · 6.52 KB
/
install.sh
File metadata and controls
executable file
·278 lines (229 loc) · 6.52 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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
#!/bin/bash
set -e
# OpenDerisk Installer Script
# Supports: Linux (x64, arm64), macOS (x64, arm64)
# Usage: curl -fsSL https://raw.githubusercontent.com/derisk-ai/OpenDerisk/main/install.sh | bash
set -u
INSTALL_DIR="${INSTALL_DIR:-$HOME/.openderisk}"
BIN_DIR="${BIN_DIR:-$HOME/.local/bin}"
REPO_URL="https://github.com/derisk-ai/OpenDerisk.git"
VERSION="${VERSION:-latest}"
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
log() {
echo -e "${BLUE}[OpenDerisk]${NC} $1"
}
warn() {
echo -e "${YELLOW}[Warning]${NC} $1"
}
error() {
echo -e "${RED}[Error]${NC} $1" >&2
exit 1
}
success() {
echo -e "${GREEN}[Success]${NC} $1"
}
# Detect OS and architecture
detect_platform() {
local os
local arch
os=$(uname -s | tr '[:upper:]' '[:lower:]')
arch=$(uname -m)
case "$os" in
linux)
os="linux"
;;
darwin)
os="macos"
;;
*)
error "Unsupported operating system: $os"
;;
esac
case "$arch" in
x86_64|amd64)
arch="x64"
;;
aarch64|arm64)
arch="arm64"
;;
*)
error "Unsupported architecture: $arch"
;;
esac
echo "${os}-${arch}"
}
# Check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Install uv if not present
install_uv() {
if command_exists uv; then
log "uv is already installed: $(uv --version)"
return 0
fi
log "Installing uv (Python package manager)..."
curl -LsSf https://astral.sh/uv/install.sh | sh
# Add to PATH for current session
export PATH="$HOME/.local/bin:$PATH"
if ! command_exists uv; then
error "Failed to install uv. Please install manually: https://github.com/astral-sh/uv"
fi
success "uv installed successfully: $(uv --version)"
}
# Install Python 3.10+ if needed
ensure_python() {
local python_version
if command_exists python3; then
python_version=$(python3 --version 2>&1 | cut -d' ' -f2 | cut -d'.' -f1,2)
log "Found Python $python_version"
# Check if version is >= 3.10
if printf '%s\n' "3.10" "$python_version" | sort -V -C; then
success "Python version is compatible (>= 3.10)"
return 0
fi
fi
log "Installing Python 3.10+ via uv..."
uv python install 3.10
success "Python 3.10 installed"
}
# Clone or update repository
clone_repo() {
if [ -d "$INSTALL_DIR/.git" ]; then
log "OpenDerisk already exists at $INSTALL_DIR"
log "Updating to latest version..."
cd "$INSTALL_DIR"
git pull origin main
else
log "Cloning OpenDerisk repository..."
mkdir -p "$(dirname "$INSTALL_DIR")"
git clone --depth 1 "$REPO_URL" "$INSTALL_DIR"
success "Repository cloned to $INSTALL_DIR"
fi
}
# Install OpenDerisk dependencies
install_dependencies() {
log "Installing OpenDerisk dependencies..."
cd "$INSTALL_DIR"
uv sync --all-packages --frozen \
--extra "base" \
--extra "proxy_openai" \
--extra "rag" \
--extra "storage_chromadb" \
--extra "derisks" \
--extra "storage_oss2" \
--extra "client" \
--extra "ext_base"
success "Dependencies installed successfully"
}
# Create wrapper scripts
create_wrappers() {
log "Creating wrapper scripts..."
mkdir -p "$BIN_DIR"
# Create main openderisk command
cat > "$BIN_DIR/openderisk" << 'EOF'
#!/bin/bash
# OpenDerisk Launcher
INSTALL_DIR="${INSTALL_DIR:-$HOME/.openderisk}"
cd "$INSTALL_DIR" || exit 1
exec uv run derisk "$@"
EOF
chmod +x "$BIN_DIR/openderisk"
# Create openderisk-server command
cat > "$BIN_DIR/openderisk-server" << 'EOF'
#!/bin/bash
# OpenDerisk Server Launcher
INSTALL_DIR="${INSTALL_DIR:-$HOME/.openderisk}"
cd "$INSTALL_DIR" || exit 1
exec uv run derisk start webserver "$@"
EOF
chmod +x "$BIN_DIR/openderisk-server"
success "Wrapper scripts created in $BIN_DIR"
}
# Add to shell config
add_to_path() {
local shell_config=""
case "$SHELL" in
*/bash)
shell_config="$HOME/.bashrc"
[ -f "$HOME/.bash_profile" ] && shell_config="$HOME/.bash_profile"
;;
*/zsh)
shell_config="$HOME/.zshrc"
;;
*/fish)
shell_config="$HOME/.config/fish/config.fish"
;;
esac
if [ -n "$shell_config" ] && [ -f "$shell_config" ]; then
if ! grep -q "$BIN_DIR" "$shell_config" 2>/dev/null; then
log "Adding $BIN_DIR to PATH in $shell_config"
echo "export PATH=\"$BIN_DIR:\$PATH\"" >> "$shell_config"
warn "Please restart your shell or run: source $shell_config"
fi
fi
}
# Print usage
print_usage() {
cat << EOF
OpenDerisk Installer
Usage:
curl -fsSL https://raw.githubusercontent.com/derisk-ai/OpenDerisk/main/install.sh | bash
Environment Variables:
INSTALL_DIR Installation directory (default: $HOME/.openderisk)
BIN_DIR Binary directory (default: $HOME/.local/bin)
VERSION Version to install (default: latest)
Options:
--help Show this help message
--version Show version information
After Installation:
openderisk Start OpenDerisk CLI
openderisk-server Start OpenDerisk Server
For more information, visit: https://github.com/derisk-ai/OpenDerisk
EOF
}
# Print version
print_version() {
echo "OpenDerisk Installer v0.1.0"
}
# Main installation
main() {
# Parse arguments
for arg in "$@"; do
case "$arg" in
--help|-h)
print_usage
exit 0
;;
--version|-v)
print_version
exit 0
;;
esac
done
log "Starting OpenDerisk installation..."
log "Platform: $(detect_platform)"
log "Install directory: $INSTALL_DIR"
log "Binary directory: $BIN_DIR"
# Installation steps
install_uv
ensure_python
clone_repo
install_dependencies
create_wrappers
add_to_path
success "OpenDerisk installed successfully!"
echo ""
echo "Getting Started:"
echo " 1. Configure API keys in: $INSTALL_DIR/configs/derisk-proxy-aliyun.toml"
echo " 2. Run: openderisk --help"
echo " 3. Start server: openderisk-server"
echo ""
echo "Documentation: https://github.com/derisk-ai/OpenDerisk"
}
main "$@"