-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
367 lines (292 loc) · 10.4 KB
/
setup.sh
File metadata and controls
367 lines (292 loc) · 10.4 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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
#!/bin/bash
# DialogChain Universal Installer & Project Creator
# Main installation script
# Usage: curl -sSL https://install.dialogchain.io | bash
set -euo pipefail
# =============================================================================
# Configuration and Constants
# =============================================================================
readonly DIALOGCHAIN_VERSION="0.1.0"
readonly INSTALL_DIR="${DIALOGCHAIN_HOME:-$HOME/.dialogchain}"
readonly BIN_DIR="$INSTALL_DIR/bin"
readonly CONFIG_DIR="$INSTALL_DIR/config"
readonly TEMPLATES_DIR="$INSTALL_DIR/templates"
readonly LOG_FILE="$INSTALL_DIR/install.log"
# Colors for output
readonly RED='\033[0;31m'
readonly GREEN='\033[0;32m'
readonly YELLOW='\033[0;33m'
readonly BLUE='\033[0;34m'
readonly PURPLE='\033[0;35m'
readonly CYAN='\033[0;36m'
readonly NC='\033[0m' # No Color
# System detection
OS=""
ARCH=""
PACKAGE_MANAGER=""
# =============================================================================
# Utility Functions
# =============================================================================
log() {
echo "$(date '+%Y-%m-%d %H:%M:%S') - $*" | tee -a "$LOG_FILE" >/dev/null
}
info() {
echo -e "${BLUE}[INFO]${NC} $*"
log "INFO: $*"
}
success() {
echo -e "${GREEN}[SUCCESS]${NC} $*"
log "SUCCESS: $*"
}
warning() {
echo -e "${YELLOW}[WARNING]${NC} $*"
log "WARNING: $*"
}
error() {
echo -e "${RED}[ERROR]${NC} $*" >&2
log "ERROR: $*"
}
fatal() {
error "$*"
exit 1
}
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# =============================================================================
# Source additional modules
# =============================================================================
# Download and source system detection module
curl -sSL "https://raw.githubusercontent.com/dialogchain/installer/main/modules/system_detection.sh" > /tmp/system_detection.sh
source /tmp/system_detection.sh
# Download and source dependency installation module
curl -sSL "https://raw.githubusercontent.com/dialogchain/installer/main/modules/dependencies.sh" > /tmp/dependencies.sh
source /tmp/dependencies.sh
# Download and source CLI generation module
curl -sSL "https://raw.githubusercontent.com/dialogchain/installer/main/modules/cli_generator.sh" > /tmp/cli_generator.sh
source /tmp/cli_generator.sh
# =============================================================================
# Main Installation Flow
# =============================================================================
show_logo() {
echo -e "${PURPLE}"
cat << 'LOGO'
____ _ _ _____ _ _
| _ \(_) | | / ____| | (_)
| |_) |_ __ _| | ___ ___| | | |__ __ _ _ _ __
| _ <| |/ _` | |/ _ \ / __| | | '_ \ / _` | | '_ \
| |_) | | (_| | | (_) | (__| |____| | | | (_| | | | | |
|____/|_|\__,_|_|\___/ \___|\_____|_| |_|\__,_|_|_| |_|
Multi-Language Pipeline Engine for Modern Integration
LOGO
echo -e "${NC}"
}
create_directory_structure() {
info "Creating DialogChain directory structure..."
mkdir -p "$INSTALL_DIR"/{bin,config,templates,logs,projects,cache}
mkdir -p "$TEMPLATES_DIR"/{examples,processors,triggers,outputs}
# Create log file
touch "$LOG_FILE"
success "Directory structure created at $INSTALL_DIR"
}
update_shell_profile() {
info "Updating shell profile..."
local shell_profile=""
if [[ -n "${BASH_VERSION:-}" ]]; then
shell_profile="$HOME/.bashrc"
elif [[ -n "${ZSH_VERSION:-}" ]]; then
shell_profile="$HOME/.zshrc"
else
shell_profile="$HOME/.profile"
fi
# Add DialogChain to PATH
if ! grep -q "DIALOGCHAIN_HOME" "$shell_profile" 2>/dev/null; then
cat >> "$shell_profile" << EOF
# DialogChain Configuration
export DIALOGCHAIN_HOME="$INSTALL_DIR"
export PATH="\$DIALOGCHAIN_HOME/bin:\$PATH"
EOF
success "Added DialogChain to PATH in $shell_profile"
fi
# Source the profile for current session
export DIALOGCHAIN_HOME="$INSTALL_DIR"
export PATH="$INSTALL_DIR/bin:$PATH"
}
verify_installation() {
info "Verifying installation..."
local errors=0
# Check directories
for dir in "$INSTALL_DIR" "$BIN_DIR" "$CONFIG_DIR" "$TEMPLATES_DIR"; do
if [[ ! -d "$dir" ]]; then
error "Directory missing: $dir"
((errors++))
fi
done
# Check CLI
if [[ ! -x "$BIN_DIR/dialogchain" ]]; then
error "DialogChain CLI not executable"
((errors++))
fi
# Check dependencies
local required_commands=("curl" "git" "python3" "pip")
for cmd in "${required_commands[@]}"; do
if ! command_exists "$cmd"; then
error "Missing required command: $cmd"
((errors++))
fi
done
if [[ $errors -eq 0 ]]; then
success "Installation verification passed"
return 0
else
error "Installation verification failed with $errors errors"
return 1
fi
}
show_completion_message() {
cat << EOF
${GREEN}╔════════════════════════════════════════════════════════════════╗
║ DialogChain Installation Complete! ║
╚════════════════════════════════════════════════════════════════╝${NC}
${BLUE}Installation Summary:${NC}
📁 Installation Directory: $INSTALL_DIR
🔧 CLI Tool: $BIN_DIR/dialogchain
📚 Templates: $TEMPLATES_DIR/examples/
📖 Logs: $LOG_FILE
${BLUE}Quick Start:${NC}
1. Create a new project:
${CYAN}dialogchain create my-first-pipeline${NC}
2. Navigate to the project:
${CYAN}cd ~/.dialogchain/projects/my-first-pipeline${NC}
3. Start development mode:
${CYAN}dialogchain dev pipeline.yaml${NC}
${BLUE}Available Commands:${NC}
• ${CYAN}dialogchain create <name>${NC} - Create new pipeline project
• ${CYAN}dialogchain templates${NC} - List available templates
• ${CYAN}dialogchain examples${NC} - Show example configurations
• ${CYAN}dialogchain doctor${NC} - Check system health
• ${CYAN}dialogchain help${NC} - Show detailed help
${BLUE}System Information:${NC}
• Operating System: $OS ($ARCH)
• Package Manager: $PACKAGE_MANAGER
• Rust: $(command_exists rustc && rustc --version | cut -d' ' -f2 || echo "Not installed")
• Python: $(python3 --version 2>/dev/null || echo "Not installed")
• Node.js: $(node --version 2>/dev/null || echo "Not installed")
• Go: $(go version 2>/dev/null | cut -d' ' -f3 || echo "Not installed")
• Docker: $(docker --version 2>/dev/null | cut -d' ' -f3 | tr -d ',' || echo "Not installed")
${YELLOW}Next Steps:${NC}
1. Restart your terminal or run: ${CYAN}source ~/.bashrc${NC}
2. Verify installation: ${CYAN}dialogchain doctor${NC}
3. Check out examples: ${CYAN}dialogchain examples${NC}
4. Read documentation: ${CYAN}https://dialogchain.io/docs${NC}
${GREEN}Happy pipeline building! 🚀${NC}
EOF
}
main() {
show_logo
info "Starting DialogChain installation..."
info "This installer will set up DialogChain and all required dependencies"
# Check if running as root (not recommended)
if [[ $EUID -eq 0 ]]; then
warning "Running as root is not recommended. Consider running as a regular user."
read -p "Continue anyway? (y/N): " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 1
fi
fi
# Create log directory early
mkdir -p "$(dirname "$LOG_FILE")"
# System detection
detect_system
# Create directory structure
create_directory_structure
# Install dependencies
info "Installing system dependencies (this may take a few minutes)..."
install_system_dependencies
# Install language runtimes
install_rust
install_go
# Setup language environments
install_python_deps &
PYTHON_PID=$!
install_node_deps &
NODE_PID=$!
# Setup container runtime
setup_docker &
DOCKER_PID=$!
# Install DialogChain CLI
install_dialogchain_cli
# Create templates
create_templates
# Wait for background processes
info "Waiting for language environments to complete..."
wait $PYTHON_PID
wait $NODE_PID
wait $DOCKER_PID
# Update shell profile
update_shell_profile
# Verify installation
if verify_installation; then
success "DialogChain installed successfully!"
# Run doctor check
run_doctor_check
# Show completion message
show_completion_message
else
fatal "Installation failed. Check $LOG_FILE for details."
fi
}
# =============================================================================
# Entry Point
# =============================================================================
case "${1:-install}" in
"install"|"")
main "$@"
;;
"doctor")
detect_system
run_doctor_check
;;
"uninstall")
if [[ -d "$INSTALL_DIR" ]]; then
read -p "Remove DialogChain installation at $INSTALL_DIR? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
rm -rf "$INSTALL_DIR"
success "DialogChain uninstalled"
fi
else
info "DialogChain not found at $INSTALL_DIR"
fi
;;
"help"|"-h"|"--help")
cat << 'HELP'
DialogChain Installer
USAGE:
curl -sSL https://install.dialogchain.io | bash [COMMAND]
COMMANDS:
install Install DialogChain (default)
doctor Run system health check
uninstall Remove DialogChain installation
help Show this help
ENVIRONMENT VARIABLES:
DIALOGCHAIN_HOME Installation directory (default: ~/.dialogchain)
EXAMPLES:
# Standard installation
curl -sSL https://install.dialogchain.io | bash
# Custom installation directory
DIALOGCHAIN_HOME=/opt/dialogchain curl -sSL https://install.dialogchain.io | bash
# Check system compatibility
curl -sSL https://install.dialogchain.io | bash -s doctor
For more information, visit: https://dialogchain.io/docs/installation
HELP
;;
*)
error "Unknown command: $1"
echo "Run with 'help' for usage information"
exit 1
;;
esac
# Cleanup temporary files
rm -f /tmp/system_detection.sh /tmp/dependencies.sh /tmp/cli_generator.sh