-
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·218 lines (180 loc) · 6.95 KB
/
install.sh
File metadata and controls
executable file
·218 lines (180 loc) · 6.95 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
#!/bin/bash
set -e # Exit on any error
# Color definitions for output formatting
readonly RED='\033[0;31m'
readonly GREEN='\033[0;32m'
readonly YELLOW='\033[1;33m'
readonly BLUE='\033[0;34m'
readonly MAGENTA='\033[0;35m'
readonly CYAN='\033[0;36m'
readonly WHITE='\033[1;37m'
readonly NC='\033[0m' # No Color
# Global variables
readonly CONTEXTKIT_DIR="$HOME/.ContextKit"
readonly GITHUB_REPO="https://github.com/FlineDev/ContextKit.git"
INSTALL_TYPE="install"
###########################################
# Utility Functions
###########################################
# Print colored status messages
print_status() {
local color=$1
shift
echo -e "${color}$*${NC}"
}
print_error() {
print_status "$RED" "❌ ERROR: $*" >&2
}
print_success() {
print_status "$GREEN" "✅ $*"
}
print_warning() {
print_status "$YELLOW" "⚠️ WARNING: $*"
}
print_info() {
print_status "$CYAN" "ℹ️ $*"
}
print_step() {
print_status "$BLUE" "🔄 $*"
}
print_header() {
echo
print_status "$MAGENTA" "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
print_status "$WHITE" " $*"
print_status "$MAGENTA" "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo
}
###########################################
# Execution Flow (main)
###########################################
## Step 1: Clone or update ContextKit repository
clone_or_update_repository() {
print_step "Step 1: Setting up ContextKit repository..."
if [[ -d "$CONTEXTKIT_DIR/.git" ]]; then
# Existing git repository - update it
print_info "Existing ContextKit installation detected - updating..."
cd "$CONTEXTKIT_DIR"
if ! git pull origin main; then
print_error "Failed to update ContextKit repository"
print_info "Repository: $GITHUB_REPO"
exit 1
fi
INSTALL_TYPE="update"
print_success "ContextKit repository updated successfully"
elif [[ -d "$CONTEXTKIT_DIR" ]]; then
# Directory exists but not a git repo - remove and clone fresh
print_warning "Existing ContextKit directory found (not a git repository)"
print_info "Removing corrupted installation and cloning fresh..."
if [[ "$CONTEXTKIT_DIR" == *"ContextKit"* ]]; then
rm -rf "$CONTEXTKIT_DIR" # Safe: only removes ContextKit directories
fi
if ! git clone --depth 1 --quiet "$GITHUB_REPO" "$CONTEXTKIT_DIR"; then
print_error "Failed to clone ContextKit repository"
print_info "Repository: $GITHUB_REPO"
exit 1
fi
print_success "ContextKit repository cloned successfully"
else
# Fresh installation
print_info "Installing ContextKit for the first time..."
if ! git clone --depth 1 --quiet "$GITHUB_REPO" "$CONTEXTKIT_DIR"; then
print_error "Failed to clone ContextKit repository"
print_info "Repository: $GITHUB_REPO"
exit 1
fi
print_success "ContextKit repository cloned successfully"
fi
print_info "ContextKit repository ready at: $CONTEXTKIT_DIR"
}
## Step 2: Install global ContextKit commands
install_global_commands() {
print_step "Step 2: Installing global ContextKit commands..."
# Create Claude Code commands directory if needed
local claude_commands_dir="$HOME/.claude/commands"
if [[ ! -d "$claude_commands_dir" ]]; then
print_info "Creating Claude Code commands directory..."
if ! mkdir -p "$claude_commands_dir" 2>/dev/null; then
print_warning "Cannot create $claude_commands_dir"
print_info "You may need to run Claude Code first, then re-run this installer"
return 0
fi
fi
# Create ctxk commands directory and copy ONLY proj commands globally
local commands_dir="$CONTEXTKIT_DIR/Templates/Commands"
local ctxk_commands_dir="$claude_commands_dir/ctxk"
if [[ ! -d "$commands_dir/proj" ]]; then
print_error "Proj commands directory not found: $commands_dir/proj"
exit 1
fi
# Create ctxk directory structure
if ! mkdir -p "$ctxk_commands_dir"; then
print_error "Failed to create ctxk commands directory"
exit 1
fi
if ! cp -R "$commands_dir/proj" "$ctxk_commands_dir"/; then
print_error "Failed to copy proj commands"
exit 1
fi
print_success "Global ContextKit project management commands installed"
print_info "Project commands (/ctxk:proj:*) available in Claude Code globally"
}
## Step 3: Display success message and next steps
display_completion() {
print_step "Step 3: Installation complete!"
if [[ "$INSTALL_TYPE" == "update" ]]; then
print_header "🧠 ContextKit Update Successful!"
else
print_header "🧠 ContextKit Installation Successful!"
fi
print_success "ContextKit ${INSTALL_TYPE}d successfully!"
echo
print_status "$WHITE" "Next steps:"
print_info "1. Navigate to your project directory"
print_info "2. Run 'claude' to start Claude Code "
print_info "3. Run '/ctxk:proj:init' to initialize ContextKit workflow commands in your project"
echo
print_status "$GREEN" "🚀 Ready for intelligent development workflows!"
echo
}
###########################################
# Error Handling and Cleanup
###########################################
cleanup_on_error() {
print_error "Installation failed - cleaning up..."
# Only remove if we created it in this session
if [[ -n "$CONTEXTKIT_CREATED" && -d "$CONTEXTKIT_DIR" ]]; then
print_info "Removing incomplete installation..."
if [[ "$CONTEXTKIT_DIR" == *"ContextKit"* ]]; then
rm -rf "$CONTEXTKIT_DIR" # Safe: only removes ContextKit directories
fi 2>/dev/null || true
fi
print_error "Please check the error messages above and try again"
print_info "For support: https://github.com/FlineDev/ContextKit/issues"
exit 1
}
# Set trap for cleanup on error
trap cleanup_on_error ERR
###########################################
# Main Execution
###########################################
main() {
print_header "🧠 ContextKit Global Installation"
echo
print_info "Installing ContextKit - Context Engineering System"
print_info "Repository: https://github.com/FlineDev/ContextKit"
echo
# Mark if we're creating ContextKit directory (for cleanup)
if [[ ! -d "$CONTEXTKIT_DIR" ]]; then
export CONTEXTKIT_CREATED=true
fi
# Execute installation steps
clone_or_update_repository
install_global_commands
display_completion
# Clear cleanup flag - successful installation
unset CONTEXTKIT_CREATED
}
# Only execute main if script is run directly (not sourced)
if [[ "${BASH_SOURCE[0]}" == "${0}" ]] || [[ "${0}" == "bash" ]] || [[ "${0}" == "sh" ]]; then
main "$@"
fi