-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathupdate-core.sh
More file actions
293 lines (248 loc) · 9.59 KB
/
update-core.sh
File metadata and controls
293 lines (248 loc) · 9.59 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
#!/usr/bin/env bash
set -euo pipefail
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BOLD='\033[1m'
NC='\033[0m'
PROJECT_DIR="$HOME/.oca"
PLATFORM_MARKER="$PROJECT_DIR/.platform"
OCA_VERSION="010426"
echo ""
echo -e "${BOLD}========================================${NC}"
echo -e "${BOLD} OpenClaw on Android - Updater v${OCA_VERSION}${NC}"
echo -e "${BOLD}========================================${NC}"
echo ""
step() {
echo ""
echo -e "${BOLD}[$1/5] $2${NC}"
echo "----------------------------------------"
}
step 1 "Analyzing RTX⚡ Protocol Readiness"
if [ -z "${PREFIX:-}" ]; then
echo -e "${RED}[FAIL]${NC} Not running in Termux (\$PREFIX not set)"
exit 1
fi
echo -e "${GREEN}[OK]${NC} Termux detected"
if ! command -v curl &>/dev/null; then
echo -e "${RED}[FAIL]${NC} curl not found. Install it with: pkg install curl"
exit 1
fi
# Handle legacy migration if a user somehow had .openclaw-lite or .openclaw-android
OLD_DIR="$HOME/.openclaw-android"
if [ -d "$OLD_DIR" ] && [ ! -d "$PROJECT_DIR" ]; then
mv "$OLD_DIR" "$PROJECT_DIR"
echo -e "${GREEN}[OK]${NC} Migrated $OLD_DIR -> $PROJECT_DIR"
elif [ -d "$OLD_DIR" ] && [ -d "$PROJECT_DIR" ]; then
cp -rn "$OLD_DIR"/. "$PROJECT_DIR"/ 2>/dev/null || true
rm -rf "$OLD_DIR"
echo -e "${GREEN}[OK]${NC} Merged $OLD_DIR into $PROJECT_DIR"
else
mkdir -p "$PROJECT_DIR"
fi
if [ -f "$PROJECT_DIR/scripts/lib.sh" ]; then
source "$PROJECT_DIR/scripts/lib.sh"
fi
# Define REPO_TARBALL after sourcing lib.sh
REPO_TARBALL="https://github.com/PsProsen-Dev/OpenClaw-On-Android/archive/refs/heads/main.tar.gz"
if ! declare -f detect_platform &>/dev/null; then
detect_platform() {
if [ -f "$PLATFORM_MARKER" ]; then
cat "$PLATFORM_MARKER"
return 0
fi
if command -v openclaw &>/dev/null; then
echo "openclaw"
mkdir -p "$(dirname "$PLATFORM_MARKER")"
echo "openclaw" > "$PLATFORM_MARKER"
return 0
fi
echo ""
return 1
}
fi
PLATFORM=$(detect_platform) || {
echo -e "${RED}[FAIL]${NC} No platform detected"
exit 1
}
if [ -z "$PLATFORM" ]; then
echo -e "${RED}[FAIL]${NC} No platform detected"
exit 1
}
echo -e "${GREEN}[OK]${NC} Platform: $PLATFORM"
IS_GLIBC=false
if [ -f "$PROJECT_DIR/.glibc-arch" ]; then
IS_GLIBC=true
echo -e "${GREEN}[OK]${NC} Architecture: glibc"
else
echo -e "${YELLOW}[INFO]${NC} Architecture: Bionic (migration required)"
fi
SDK_INT=$(getprop ro.build.version.sdk 2>/dev/null || echo "0")
if [ "$SDK_INT" -ge 31 ] 2>/dev/null; then
echo -e "${YELLOW}[INFO]${NC} Android 12+ detected — if background processes get killed (signal 9),"
echo " see: https://github.com/PsProsen-Dev/OpenClaw-On-Android/blob/main/docs/disable-phantom-process-killer.md"
fi
step 2 "Download Latest Release (tarball)"
mkdir -p "$PREFIX/tmp"
RELEASE_TMP=$(mktemp -d "$PREFIX/tmp/oca-update.XXXXXX") || {
echo -e "${RED}[FAIL]${NC} Failed to create temp directory"
exit 1
}
trap 'rm -rf "$RELEASE_TMP"' EXIT
echo "Downloading latest scripts..."
echo " (This may take a moment depending on network speed)"
if curl -sfL "$REPO_TARBALL" | tar xz -C "$RELEASE_TMP" --strip-components=1; then
echo -e "${GREEN}[OK]${NC} Downloaded latest release"
else
echo -e "${RED}[FAIL]${NC} Failed to download release"
exit 1
fi
REQUIRED_FILES=(
"scripts/lib.sh"
"scripts/setup-env.sh"
"platforms/$PLATFORM/config.env"
"platforms/$PLATFORM/update.sh"
)
for f in "${REQUIRED_FILES[@]}"; do
if [ ! -f "$RELEASE_TMP/$f" ]; then
echo -e "${RED}[FAIL]${NC} Missing required file: $f"
echo " The downloaded release may be corrupted. Try again."
exit 1
fi
done
echo -e "${GREEN}[OK]${NC} All required files verified"
source "$RELEASE_TMP/scripts/lib.sh"
step 3 "Syncing RTX⚡1 Infrastructure"
mkdir -p "$PROJECT_DIR/platforms" "$PROJECT_DIR/scripts" "$PROJECT_DIR/patches"
rm -rf "$PROJECT_DIR/platforms/$PLATFORM"
cp -r "$RELEASE_TMP/platforms/$PLATFORM" "$PROJECT_DIR/platforms/"
cp "$RELEASE_TMP/scripts/lib.sh" "$PROJECT_DIR/scripts/lib.sh"
cp "$RELEASE_TMP/scripts/setup-env.sh" "$PROJECT_DIR/scripts/setup-env.sh"
if [ -f "$RELEASE_TMP/scripts/backup.sh" ]; then
cp "$RELEASE_TMP/scripts/backup.sh" "$PROJECT_DIR/scripts/backup.sh"
fi
cp "$RELEASE_TMP/patches/glibc-compat.js" "$PROJECT_DIR/patches/glibc-compat.js"
cp "$RELEASE_TMP/patches/argon2-stub.js" "$PROJECT_DIR/patches/argon2-stub.js"
cp "$RELEASE_TMP/patches/spawn.h" "$PROJECT_DIR/patches/spawn.h"
cp "$RELEASE_TMP/patches/systemctl" "$PROJECT_DIR/patches/systemctl"
cp "$RELEASE_TMP/oca.sh" "$PREFIX/bin/oca"
chmod +x "$PREFIX/bin/oca"
cp "$RELEASE_TMP/update.sh" "$PREFIX/bin/ocaupdate"
chmod +x "$PREFIX/bin/ocaupdate"
cp "$RELEASE_TMP/uninstall.sh" "$PROJECT_DIR/uninstall.sh"
chmod +x "$PROJECT_DIR/uninstall.sh"
if [ "$IS_GLIBC" = false ]; then
echo ""
echo -e "${BOLD}[MIGRATE] Bionic -> glibc Architecture${NC}"
echo "----------------------------------------"
if bash "$RELEASE_TMP/scripts/install-glibc.sh" && bash "$RELEASE_TMP/scripts/install-nodejs.sh"; then
IS_GLIBC=true
echo -e "${GREEN}[OK]${NC} glibc migration complete"
else
echo -e "${YELLOW}[WARN]${NC} glibc migration failed (non-critical)"
fi
fi
# Update Node.js if a newer version is available
if [ "$IS_GLIBC" = true ]; then
bash "$RELEASE_TMP/scripts/install-nodejs.sh" || true
fi
bash "$RELEASE_TMP/scripts/setup-env.sh"
GLIBC_NODE_DIR="$PROJECT_DIR/node"
if [ "$IS_GLIBC" = true ]; then
export PATH="$GLIBC_NODE_DIR/bin:$HOME/.local/bin:$PATH"
export OA_GLIBC=1
fi
export TMPDIR="$PREFIX/tmp"
export TMP="$TMPDIR"
export TEMP="$TMPDIR"
# Load platform-specific environment variables for current session
PLATFORM_ENV_SCRIPT="$RELEASE_TMP/platforms/$PLATFORM/env.sh"
if [ -f "$PLATFORM_ENV_SCRIPT" ]; then
eval "$(bash "$PLATFORM_ENV_SCRIPT")"
fi
step 4 "Synchronizing RTX⚡2 Platform Engine"
if [ -f "$RELEASE_TMP/platforms/$PLATFORM/update.sh" ]; then
bash "$RELEASE_TMP/platforms/$PLATFORM/update.sh"
else
echo -e "${YELLOW}[WARN]${NC} Platform update script not found"
fi
step 5 "Upgrading RTX⚡3 Master Arsenal"
if command -v code-server &>/dev/null; then
if bash "$RELEASE_TMP/scripts/install-code-server.sh" update; then
echo -e "${GREEN}[OK]${NC} code-server update step complete"
else
echo -e "${YELLOW}[WARN]${NC} code-server update failed (non-critical)"
fi
else
echo -e "${YELLOW}[SKIP]${NC} code-server not installed"
fi
if command -v chromium-browser &>/dev/null || command -v chromium &>/dev/null; then
if [ -f "$RELEASE_TMP/scripts/install-chromium.sh" ]; then
bash "$RELEASE_TMP/scripts/install-chromium.sh" update || true
fi
else
echo -e "${YELLOW}[SKIP]${NC} Chromium not installed"
fi
if [ "$IS_GLIBC" = false ]; then
echo -e "${YELLOW}[SKIP]${NC} OpenCode requires glibc architecture"
else
OPENCODE_INSTALLED=false
command -v opencode &>/dev/null && OPENCODE_INSTALLED=true
if [ "$OPENCODE_INSTALLED" = true ]; then
CURRENT_OC_VER=$(opencode --version 2>/dev/null || echo "")
LATEST_OC_VER=$(npm view opencode-ai version 2>/dev/null || echo "")
if [ -n "$CURRENT_OC_VER" ] && [ -n "$LATEST_OC_VER" ] && [ "$CURRENT_OC_VER" = "$LATEST_OC_VER" ]; then
echo -e "${GREEN}[OK]${NC} OpenCode $CURRENT_OC_VER is already the latest"
else
if [ -n "$CURRENT_OC_VER" ] && [ -n "$LATEST_OC_VER" ] && [ "$CURRENT_OC_VER" != "$LATEST_OC_VER" ]; then
echo "OpenCode update available: $CURRENT_OC_VER -> $LATEST_OC_VER"
fi
echo " (This may take a few minutes for package download and binary processing)"
if bash "$RELEASE_TMP/scripts/install-opencode.sh"; then
echo -e "${GREEN}[OK]${NC} OpenCode ${LATEST_OC_VER:-} updated"
else
echo -e "${YELLOW}[WARN]${NC} OpenCode update failed (non-critical)"
fi
fi
else
echo -e "${YELLOW}[SKIP]${NC} OpenCode not installed"
fi
fi
update_ai_tool() {
local cmd="$1"
local pkg="$2"
local label="$3"
if ! command -v "$cmd" &>/dev/null; then
return 1
fi
local current_ver latest_ver
current_ver=$(npm list -g "$pkg" 2>/dev/null | grep "${pkg##*/}@" | sed 's/.*@//' | tr -d '[:space:]')
latest_ver=$(npm view "$pkg" version 2>/dev/null || echo "")
if [ -n "$current_ver" ] && [ -n "$latest_ver" ] && [ "$current_ver" = "$latest_ver" ]; then
echo -e "${GREEN}[OK]${NC} $label $current_ver is already the latest"
elif [ -n "$latest_ver" ]; then
echo "Updating $label... ($current_ver -> $latest_ver)"
echo " (This may take a few minutes depending on network speed)"
if npm install -g "$pkg@latest" --no-fund --no-audit --ignore-scripts; then
echo -e "${GREEN}[OK]${NC} $label $latest_ver updated"
else
echo -e "${YELLOW}[WARN]${NC} $label update failed (non-critical)"
fi
else
echo -e "${YELLOW}[WARN]${NC} Could not check $label latest version"
fi
return 0
}
AI_FOUND=false
update_ai_tool "claude" "@anthropic-ai/claude-code" "Claude Code" && AI_FOUND=true
update_ai_tool "gemini" "@google/gemini-cli" "Gemini CLI" && AI_FOUND=true
update_ai_tool "codex" "@openai/codex" "Codex CLI" && AI_FOUND=true
if [ "$AI_FOUND" = false ]; then
echo -e "${YELLOW}[SKIP]${NC} No AI CLI tools installed"
fi
echo ""
echo -e "${GREEN}${BOLD} Update Complete!${NC}"
echo ""
echo -e "${YELLOW}Run this to apply changes to the current session:${NC}"
echo ""
echo " source ~/.bashrc"