-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall
More file actions
executable file
·294 lines (242 loc) · 7.46 KB
/
install
File metadata and controls
executable file
·294 lines (242 loc) · 7.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
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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
#!/bin/bash
#
# Heidi CLI One-Click Installer
#
# This script will:
# 1. Clone the latest Heidi CLI from main branch
# 2. Build and install it system-wide
# 3. Verify installation
# 4. Clean up temporary files
#
# Usage: ./install
#
set -e # Exit on any error
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
# Print functions
print_header() {
echo -e "${PURPLE}================================${NC}"
echo -e "${PURPLE}🚀 Heidi CLI One-Click Installer${NC}"
echo -e "${PURPLE}================================${NC}"
echo
}
print_success() {
echo -e "${GREEN}✅ $1${NC}"
}
print_info() {
echo -e "${BLUE}ℹ️ $1${NC}"
}
print_warning() {
echo -e "${YELLOW}⚠️ $1${NC}"
}
print_error() {
echo -e "${RED}❌ $1${NC}"
}
print_step() {
echo -e "${CYAN}🔄 $1${NC}"
}
# Check if running as root (for system-wide installation)
check_permissions() {
print_step "Checking permissions..."
if [[ $EUID -eq 0 ]]; then
print_warning "Running as root - installing system-wide"
INSTALL_PREFIX="/usr/local"
PIP_INSTALL_ARGS="--user"
else
print_info "Running as user - installing in user directory"
INSTALL_PREFIX="$HOME/.local"
PIP_INSTALL_ARGS="--user"
# Add ~/.local/bin to PATH if not already there
if [[ ":$PATH:" != *":$HOME/.local/bin:"* ]]; then
export PATH="$HOME/.local/bin:$PATH"
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
print_info "Added ~/.local/bin to PATH"
fi
fi
print_success "Permissions checked - installing to $INSTALL_PREFIX"
}
# Check system requirements
check_requirements() {
print_step "Checking system requirements..."
# Check Python
if ! command -v python3 &> /dev/null; then
print_error "Python 3 is required but not installed"
print_info "Please install Python 3.10 or higher"
exit 1
fi
python_version=$(python3 -c 'import sys; print(".".join(map(str, sys.version_info[:2])))')
required_version="3.10"
if python3 -c "import sys; exit(0 if sys.version_info >= (3, 10) else 1)"; then
print_success "Python $python_version found (>= $required_version)"
else
print_error "Python $python_version found but >= $required_version required"
exit 1
fi
# Check pip
if ! command -v pip3 &> /dev/null && ! command -v pip &> /dev/null; then
print_error "pip is required but not installed"
print_info "Please install pip"
exit 1
fi
# Check git
if ! command -v git &> /dev/null; then
print_error "git is required but not installed"
print_info "Please install git"
exit 1
fi
print_success "All requirements satisfied"
}
# Create temporary directory
create_temp_dir() {
TEMP_DIR=$(mktemp -d)
print_info "Created temporary directory: $TEMP_DIR"
cd "$TEMP_DIR"
}
# Clone Heidi CLI
clone_heidi() {
print_step "Cloning Heidi CLI from main branch..."
REPO_URL="https://github.com/heidi-dang/heidi-cli.git"
if ! git clone "$REPO_URL" heidi-cli; then
print_error "Failed to clone Heidi CLI repository"
exit 1
fi
cd heidi-cli
print_success "Heidi CLI cloned successfully"
# Show current commit info
COMMIT_HASH=$(git rev-parse HEAD)
COMMIT_DATE=$(git log -1 --format="%cd" --date=short)
print_info "Installing commit: $COMMIT_HASH ($COMMIT_DATE)"
}
# Setup virtual environment
setup_venv() {
print_step "Setting up virtual environment..."
if ! python3 -m venv venv; then
print_error "Failed to create virtual environment"
exit 1
fi
source venv/bin/activate
print_success "Virtual environment created and activated"
# Upgrade pip
pip install --upgrade pip
print_success "pip upgraded"
}
# Install dependencies
install_dependencies() {
print_step "Installing dependencies..."
if ! pip install -e .; then
print_error "Failed to install Heidi CLI dependencies"
exit 1
fi
print_success "Dependencies installed"
}
# Build Heidi CLI
build_heidi() {
print_step "Building Heidi CLI..."
# Check if build tools are available
if command -v python3 -m build &> /dev/null; then
# Use modern build system
python3 -m build
print_success "Heidi CLI built with modern build system"
else
# Fallback to setup.py
python3 setup.py build
print_success "Heidi CLI built with setup.py"
fi
}
# Install Heidi CLI
install_heidi() {
print_step "Installing Heidi CLI..."
# Install in development mode with user permissions
if ! pip install -e . $PIP_INSTALL_ARGS; then
print_error "Failed to install Heidi CLI"
exit 1
fi
print_success "Heidi CLI installed successfully"
}
# Verify installation
verify_installation() {
print_step "Verifying installation..."
# Check if heidi command is available
if command -v heidi &> /dev/null; then
print_success "heidi command is available"
# Show version
VERSION=$(heidi --version 2>/dev/null || echo "unknown")
print_success "Heidi CLI version: $VERSION"
# Test basic functionality
if heidi --help &> /dev/null; then
print_success "Heidi CLI help command works"
else
print_warning "Heidi CLI help command failed - installation may have issues"
fi
else
print_error "heidi command not found after installation"
print_info "Try running: export PATH=\"$HOME/.local/bin:\$PATH\""
exit 1
fi
}
# Run post-install setup
post_install_setup() {
print_step "Running post-install setup..."
# Initialize Heidi CLI
if heidi doctor &> /dev/null; then
print_success "Heidi CLI initialization successful"
else
print_warning "Heidi CLI initialization had issues - this is normal for first run"
fi
# Show next steps
echo
print_info "🎉 Installation completed successfully!"
echo
print_info "Next steps:"
echo " 1. Run: heidi setup"
echo " 2. Generate API key: heidi api generate --name \"My Key\""
echo " 3. Start model server: heidi model serve"
echo " 4. View help: heidi --help"
echo
print_info "Documentation: https://github.com/heidi-dang/heidi-cli/blob/main/docs/how-to-use.md"
}
# Cleanup temporary files
cleanup() {
print_step "Cleaning up temporary files..."
if [[ -n "$TEMP_DIR" && -d "$TEMP_DIR" ]]; then
cd /
rm -rf "$TEMP_DIR"
print_success "Temporary files cleaned up"
fi
}
# Error handling
handle_error() {
print_error "Installation failed!"
print_info "Check the error messages above for details"
print_info "You can try running the installer again"
cleanup
exit 1
}
# Main installation function
main() {
print_header
# Set up error handling
trap handle_error ERR
trap cleanup EXIT
# Run installation steps
check_permissions
check_requirements
create_temp_dir
clone_heidi
setup_venv
install_dependencies
build_heidi
install_heidi
verify_installation
post_install_setup
print_success "🎉 Heidi CLI installation completed successfully!"
print_info "You can now use: heidi --version"
}
# Run main function
main "$@"