-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathclauder_update_check.sh
More file actions
executable file
Β·265 lines (222 loc) Β· 8.55 KB
/
Copy pathclauder_update_check.sh
File metadata and controls
executable file
Β·265 lines (222 loc) Β· 8.55 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
#!/bin/bash
# Script to check for clauder updates and handle the update process
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
DARK_GRAY='\033[90m'
NC='\033[0m' # No Color
# Function to print colored output
print_status() {
local color=$1
local message=$2
echo -e "${color}${message}${NC}"
}
# Function to check if we're in a git repository
check_git_repo() {
local dir="$1"
git -C "$dir" rev-parse --is-inside-work-tree >/dev/null 2>&1
}
# Function to check for updates
check_for_updates() {
local clauder_dir="$1"
local original_dir="$2"
local update_needed_var="$3" # Variable name to set
if ! check_git_repo "$clauder_dir"; then
print_status $YELLOW "β οΈ Clauder directory is not a git repository. Skipping update check."
eval "$update_needed_var=false"
return 0
fi
# Change to clauder directory
cd "$clauder_dir"
# Fetch latest changes
print_status $BLUE "π Checking for updates..."
# Display directory information after the checking message
print_status $DARK_GRAY "Clauder directory: $clauder_dir"
print_status $DARK_GRAY "Project directory: $original_dir"
git fetch origin main > /dev/null 2>&1 || {
print_status $RED "β Failed to fetch updates from remote repository"
cd "$original_dir"
eval "$update_needed_var=false"
return 0
}
# Check if local is behind remote
local local_commit=$(git rev-parse HEAD)
local remote_commit=$(git rev-parse origin/main)
if [[ "$local_commit" != "$remote_commit" ]]; then
print_status $YELLOW "π Update available for clauder!"
print_status $BLUE "Local: $(git rev-parse --short HEAD)"
print_status $BLUE "Remote: $(git rev-parse --short origin/main)"
cd "$original_dir"
eval "$update_needed_var=true"
return 0
else
print_status $GREEN "β
Clauder is up to date"
print_status $DARK_GRAY "Current commit: $(git rev-parse --short HEAD)"
cd "$original_dir"
eval "$update_needed_var=false"
return 0
fi
}
# Function to perform update
perform_update() {
local clauder_dir="$1"
local original_dir="$2"
print_status $BLUE "π Updating clauder..."
# Change to clauder directory
cd "$clauder_dir"
# Pull latest changes
git pull origin main || {
print_status $RED "β Failed to pull latest changes"
return 0
}
print_status $GREEN "β
Successfully pulled latest changes"
# Reinstall clauder
print_status $BLUE "π§ Reinstalling clauder..."
bash ./clauder_install.sh || {
print_status $RED "β Failed to reinstall clauder"
return 0
}
print_status $GREEN "β
Clauder reinstalled successfully"
# Return to original directory
cd "$original_dir"
# Ask for user approval before activating
echo
print_status $YELLOW "π UPDATE COMPLETE: Would you like to activate the latest version of clauder in the current project? (y/n)"
print_status $DARK_GRAY "Current project: $original_dir"
read -r activate_response
case "$activate_response" in
[yY]|[yY][eE][sS])
print_status $BLUE "π§ Activating clauder in current directory..."
# Ensure we're in the original directory where the user ran the command
cd "$original_dir"
# Call the activate script directly instead of relying on alias
bash "$clauder_dir/clauder_activate.sh" "$original_dir" || {
print_status $RED "β Failed to activate clauder"
return 0
}
print_status $GREEN "β
Clauder updated and activated successfully!"
;;
[nN]|[nN][oO])
print_status $BLUE "Skipping activation."
print_status $YELLOW "β οΈ Clauder was updated but the latest version was not applied to this project."
print_status $BLUE "You can re-run 'clauder_activate' to apply the latest changes."
;;
*)
print_status $RED "Invalid response. Skipping activation."
print_status $YELLOW "β οΈ Clauder was updated but the latest version was not applied to this project."
print_status $BLUE "You can re-run 'clauder_activate' to apply the latest changes."
;;
esac
return 0
}
# Function to check target .claude/.clauderrc file
check_target_clauderrc() {
local clauder_dir="$1"
local target_dir="$2"
local clauderrc_file="$target_dir/.claude/.clauderrc"
# Check if .claude/.clauderrc exists
if [[ ! -f "$clauderrc_file" ]]; then
print_status $YELLOW "β οΈ No .claude/.clauderrc found in target project"
return 1 # Needs activation
fi
# Get current clauder commit
local current_clauder_commit=""
if [[ -d "$clauder_dir/.git" ]]; then
current_clauder_commit=$(cd "$clauder_dir" && git rev-parse HEAD 2>/dev/null)
fi
if [[ -z "$current_clauder_commit" ]]; then
print_status $YELLOW "β οΈ Could not determine clauder commit ID"
return 1 # Needs activation
fi
# Read the commit ID from .clauderrc
local target_commit=""
if [[ -f "$clauderrc_file" ]]; then
target_commit=$(cat "$clauderrc_file" 2>/dev/null | tr -d '\n\r')
fi
if [[ -z "$target_commit" ]]; then
print_status $YELLOW "β οΈ .claude/.clauderrc is empty or unreadable"
return 1 # Needs activation
fi
# Compare commit IDs
if [[ "$target_commit" != "$current_clauder_commit" ]]; then
print_status $YELLOW "π Target project has different clauder version"
print_status $BLUE "Target: $(echo "$target_commit" | cut -c1-8)"
print_status $BLUE "Current: $(echo "$current_clauder_commit" | cut -c1-8)"
return 1 # Needs activation
fi
print_status $GREEN "β
Target project is up to date with current clauder version"
return 0 # No activation needed
}
# Function to prompt for activation
prompt_for_activation() {
local clauder_dir="$1"
local target_dir="$2"
echo
print_status $YELLOW "Would you like to activate the current clauder version in this project? (y/n)"
print_status $DARK_GRAY "This will backup existing .claude configuration and apply the latest clauder settings."
read -r response
case "$response" in
[yY]|[yY][eE][sS])
print_status $BLUE "π§ Activating clauder in current directory..."
# Call the activate script directly
bash "$clauder_dir/clauder_activate.sh" "$target_dir" || {
print_status $RED "β Failed to activate clauder"
return 1
}
print_status $GREEN "β
Clauder activated successfully!"
return 0
;;
[nN]|[nN][oO])
print_status $BLUE "Skipping activation. Continuing with current configuration..."
return 0
;;
*)
print_status $RED "Invalid response. Skipping activation."
return 0
;;
esac
}
# Function to prompt user for update
prompt_for_update() {
local clauder_dir="$1"
local original_dir="$2"
echo
print_status $YELLOW "Would you like to update clauder? (y/n)"
read -r response
case "$response" in
[yY]|[yY][eE][sS])
perform_update "$clauder_dir" "$original_dir"
return 0
;;
[nN]|[nN][oO])
print_status $BLUE "Skipping update. Continuing with current version..."
return 0
;;
*)
print_status $RED "Invalid response. Skipping update."
return 0
;;
esac
}
# Main function
main() {
# Capture the original directory BEFORE any changes
local original_dir="$(pwd)"
local clauder_dir="${CLAUDER_DIR:-$(dirname "$(realpath "$0")")}"
# Check for updates and get the result
local update_needed=false
check_for_updates "$clauder_dir" "$original_dir" "update_needed"
# Only prompt for update if an update is actually needed
if [ "$update_needed" = true ]; then
prompt_for_update "$clauder_dir" "$original_dir"
fi
# Check if target project needs activation (regardless of whether update was needed)
if ! check_target_clauderrc "$clauder_dir" "$original_dir"; then
prompt_for_activation "$clauder_dir" "$original_dir"
fi
}
# Run main function
main "$@"