-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·611 lines (515 loc) · 20.9 KB
/
deploy.sh
File metadata and controls
executable file
·611 lines (515 loc) · 20.9 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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
#!/bin/bash
# TizenClaw Build, Deploy & Run Script
# Automates: gbs build → sdb push → rpm install → service restart
#
# Usage:
# ./deploy.sh # Full pipeline (build + deploy)
# ./deploy.sh -s # Skip build, deploy only
# ./deploy.sh -n # Use --noinit for faster rebuild
# ./deploy.sh --dry-run # Print commands without executing
# ./deploy.sh -d <serial> # Target a specific sdb device
# ./deploy.sh --test # Build + deploy + run E2E smoke tests
#
# See ./scripts/deploy.sh --help for all options.
set -euo pipefail
# ─────────────────────────────────────────────
# Constants
# ─────────────────────────────────────────────
PROJECT_DIR="$(cd "$(dirname "$0")" && pwd)"
PKG_NAME="tizenclaw"
GBS_BUILD_LOG="/tmp/gbs_build_output.log"
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
CYAN='\033[0;36m'
BOLD='\033[1m'
NC='\033[0m'
# ─────────────────────────────────────────────
# Defaults
# ─────────────────────────────────────────────
ARCH=""
ARCH_EXPLICIT=false
NOINIT=false
INCREMENTAL=false
SKIP_BUILD=false
DRY_RUN=false
DEVICE_SERIAL=""
WITH_NGROK=false
RUN_TESTS=false
WITH_ASSETS=false
RAG_PROJECT_DIR=""
# ─────────────────────────────────────────────
# Logging helpers
# ─────────────────────────────────────────────
log() { echo -e "${CYAN}[DEPLOY]${NC} $*"; }
ok() { echo -e "${GREEN}[ OK ]${NC} $*"; }
warn() { echo -e "${YELLOW}[ WARN ]${NC} $*"; }
fail() { echo -e "${RED}[ FAIL ]${NC} $*"; exit 1; }
header() { echo -e "\n${BOLD}══════════════════════════════════════════${NC}"; echo -e "${BOLD} $*${NC}"; echo -e "${BOLD}══════════════════════════════════════════${NC}"; }
# ─────────────────────────────────────────────
# sdb wrapper (supports -s <serial>)
# ─────────────────────────────────────────────
sdb_cmd() {
if [ -n "${DEVICE_SERIAL}" ]; then
sdb -s "${DEVICE_SERIAL}" "$@"
else
sdb "$@"
fi
}
sdb_shell() {
sdb_cmd shell "$@"
}
# ─────────────────────────────────────────────
# Auto-detect device architecture via sdb
# ─────────────────────────────────────────────
detect_arch() {
# If user explicitly specified arch via -a, skip auto-detection
if [ "${ARCH_EXPLICIT}" = true ]; then
log "Using explicit architecture: ${ARCH}"
return 0
fi
log "Auto-detecting device architecture via sdb..."
local sdb_cap_cmd=(sdb)
if [ -n "${DEVICE_SERIAL}" ]; then
sdb_cap_cmd=(sdb -s "${DEVICE_SERIAL}")
fi
local cpu_arch
cpu_arch=$("${sdb_cap_cmd[@]}" capability 2>/dev/null | grep '^cpu_arch:' | cut -d':' -f2 || true)
if [ -z "${cpu_arch}" ]; then
warn "Could not detect device architecture. Falling back to x86_64"
ARCH="x86_64"
return 0
fi
# Map sdb cpu_arch to GBS-compatible architecture name
case "${cpu_arch}" in
armv7) ARCH="armv7l" ;;
*) ARCH="${cpu_arch}" ;;
esac
ok "Detected device architecture: ${ARCH} (cpu_arch: ${cpu_arch})"
}
# ─────────────────────────────────────────────
# Dry-run wrapper
# ─────────────────────────────────────────────
run() {
if [ "${DRY_RUN}" = true ]; then
echo -e " ${YELLOW}[DRY-RUN]${NC} $*"
return 0
fi
"$@"
}
# ─────────────────────────────────────────────
# Usage
# ─────────────────────────────────────────────
usage() {
cat <<EOF
${BOLD}TizenClaw Build, Deploy & Run${NC}
${CYAN}Usage:${NC}
$(basename "$0") [options]
${CYAN}Options:${NC}
-a, --arch <arch> Build architecture (default: auto-detect via sdb)
-n, --noinit Skip build-env init (faster rebuild)
-i, --incremental Use --incremental and --skip-srcrpm for fast iterative build
-s, --skip-build Skip GBS build, deploy existing RPM
-t, --test Run E2E smoke tests after deployment
--with-assets Also build and deploy tizenclaw-assets
-w, --with-ngrok Auto-download and push ngrok binary to the device
-d, --device <serial> Target a specific sdb device
--dry-run Print commands without executing
-h, --help Show this help
${CYAN}Examples:${NC}
$(basename "$0") # Full build + deploy + run
$(basename "$0") -n # Quick rebuild + deploy + run
$(basename "$0") -i -n # Fastest iterative rebuild + deploy + run
$(basename "$0") -s # Deploy existing RPM + run
$(basename "$0") -t # Build + deploy + run E2E tests
$(basename "$0") --with-assets # Build + deploy including tizenclaw-assets
$(basename "$0") -w # Deploy and install ngrok binary
$(basename "$0") --dry-run # Preview all steps
$(basename "$0") -a aarch64 # Build for ARM64 target
$(basename "$0") -d emulator-26101 # Target specific device
EOF
exit 0
}
# ─────────────────────────────────────────────
# Argument parsing
# ─────────────────────────────────────────────
parse_args() {
while [[ $# -gt 0 ]]; do
case "$1" in
-a|--arch) ARCH="$2"; ARCH_EXPLICIT=true; shift 2 ;;
-n|--noinit) NOINIT=true; shift ;;
-i|--incremental) INCREMENTAL=true; shift ;;
-s|--skip-build) SKIP_BUILD=true; shift ;;
-t|--test) RUN_TESTS=true; shift ;;
--with-assets) WITH_ASSETS=true; shift ;;
-w|--with-ngrok) WITH_NGROK=true; shift ;;
-d|--device) DEVICE_SERIAL="$2"; shift 2 ;;
--dry-run) DRY_RUN=true; shift ;;
-h|--help) usage ;;
*) fail "Unknown option: $1 (use --help)" ;;
esac
done
}
# ─────────────────────────────────────────────
# Step 0: Pre-flight checks
# ─────────────────────────────────────────────
check_prerequisites() {
header "Pre-flight Checks"
if [ "${SKIP_BUILD}" = false ]; then
if ! command -v gbs &>/dev/null; then
if [ "${DRY_RUN}" = true ]; then
warn "gbs not found (ignored in dry-run)"
else
fail "gbs not found. Install Tizen GBS first."
fi
else
ok "gbs found"
fi
fi
if ! command -v sdb &>/dev/null; then
if [ "${DRY_RUN}" = true ]; then
warn "sdb not found (ignored in dry-run)"
else
fail "sdb not found. Install Tizen sdb first."
fi
else
ok "sdb found"
fi
log "Architecture : ${ARCH}"
log "Project dir : ${PROJECT_DIR}"
log "Skip build : ${SKIP_BUILD}"
log "Incremental : ${INCREMENTAL}"
log "No-init : ${NOINIT}"
log "Dry-run : ${DRY_RUN}"
if [ -n "${DEVICE_SERIAL}" ]; then
log "Device : ${DEVICE_SERIAL}"
fi
}
# ─────────────────────────────────────────────
# Step 1: GBS Build
# ─────────────────────────────────────────────
do_build() {
if [ "${SKIP_BUILD}" = true ]; then
log "Skipping build (--skip-build)"
return 0
fi
header "Step 1/4: GBS Build"
local gbs_args=("-A" "${ARCH}" "--include-all")
if [ "${INCREMENTAL}" = true ]; then
gbs_args+=("--incremental" "--skip-srcrpm")
log "Using --incremental & --skip-srcrpm (fast iterative build)"
fi
if [ "${NOINIT}" = true ]; then
gbs_args+=("--noinit")
log "Using --noinit (skipping build-env initialization)"
fi
log "Running: gbs build ${gbs_args[*]}"
cd "${PROJECT_DIR}"
if [ "${DRY_RUN}" = true ]; then
echo -e " ${YELLOW}[DRY-RUN]${NC} gbs build ${gbs_args[*]}"
ok "GBS build succeeded"
return 0
fi
# Run gbs build and capture output for RPMS path extraction
if gbs build "${gbs_args[@]}" 2>&1 | tee "${GBS_BUILD_LOG}"; then
ok "GBS build succeeded"
else
fail "GBS build failed. Check the build log: ${GBS_BUILD_LOG}"
fi
# Extract RPMS directory from gbs build output
RPMS_DIR=$(grep -A1 'generated RPM packages can be found from local repo:' "${GBS_BUILD_LOG}" \
| tail -1 | sed 's/^[[:space:]]*//')
if [ -n "${RPMS_DIR}" ]; then
ok "RPMS directory: ${RPMS_DIR}"
else
warn "Could not parse RPMS path from build output"
fi
}
# ─────────────────────────────────────────────
# Step 1.5: Build tizenclaw-assets (if present)
# ─────────────────────────────────────────────
RAG_RPM_FILES=()
do_build_rag() {
if [ "${SKIP_BUILD}" = true ] || [ "${WITH_ASSETS}" = false ]; then
return 0
fi
# Auto-detect tizenclaw-assets project
if [ -z "${RAG_PROJECT_DIR}" ]; then
RAG_PROJECT_DIR="${PROJECT_DIR}/../tizenclaw-assets"
fi
if [ ! -f "${RAG_PROJECT_DIR}/CMakeLists.txt" ]; then
log "tizenclaw-assets project not found at ${RAG_PROJECT_DIR} (skipping)"
return 0
fi
header "Step 1.5: Build tizenclaw-assets"
local rag_abs_dir
rag_abs_dir=$(cd "${RAG_PROJECT_DIR}" && pwd)
log "RAG project: ${rag_abs_dir}"
local gbs_args=("-A" "${ARCH}" "--include-all")
if [ "${NOINIT}" = true ]; then
gbs_args+=("--noinit")
fi
log "Running: gbs build ${gbs_args[*]} (tizenclaw-assets)"
if [ "${DRY_RUN}" = true ]; then
echo -e " ${YELLOW}[DRY-RUN]${NC} cd ${rag_abs_dir} && gbs build ${gbs_args[*]}"
ok "tizenclaw-assets build (dry-run)"
return 0
fi
local rag_log="/tmp/gbs_assets_build_output.log"
if (cd "${rag_abs_dir}" && gbs build "${gbs_args[@]}" 2>&1 | tee "${rag_log}"); then
ok "tizenclaw-assets build succeeded"
else
warn "tizenclaw-assets build failed (non-fatal, continuing without RAG)"
return 0
fi
# Find RAG RPMs
local rag_rpms_dir
rag_rpms_dir=$(grep -A1 'generated RPM packages can be found from local repo:' "${rag_log}" \
| tail -1 | sed 's/^[[:space:]]*//')
if [ -n "${rag_rpms_dir}" ] && [ -d "${rag_rpms_dir}" ]; then
mapfile -t RAG_RPM_FILES < <(find "${rag_rpms_dir}" -maxdepth 1 \
-name "tizenclaw-assets*.rpm" \
! -name "*-debuginfo-*" \
! -name "*-debugsource-*" \
2>/dev/null | sort)
for rpm in "${RAG_RPM_FILES[@]}"; do
ok "RAG RPM: $(basename "${rpm}")"
done
fi
}
# ─────────────────────────────────────────────
# Step 2: Find the built RPM
# ─────────────────────────────────────────────
RPM_FILES=()
RPMS_DIR=""
find_rpm() {
header "Step 2/4: Locating RPM"
# If RPMS_DIR was not set by do_build (e.g. --skip-build or --dry-run),
# try to find it from the last build log or fall back to searching GBS-ROOT
if [ -z "${RPMS_DIR}" ]; then
# Try last build log first
if [ -f "${GBS_BUILD_LOG}" ]; then
RPMS_DIR=$(grep -A1 'generated RPM packages can be found from local repo:' "${GBS_BUILD_LOG}" \
| tail -1 | sed 's/^[[:space:]]*//')
fi
# Fall back to searching under ~/GBS-ROOT
if [ -z "${RPMS_DIR}" ]; then
local gbs_root="${HOME}/GBS-ROOT"
RPMS_DIR=$(find "${gbs_root}" -type d -path "*/${ARCH}/RPMS" 2>/dev/null | head -1 || true)
fi
fi
if [ "${DRY_RUN}" = true ]; then
if [ -z "${RPMS_DIR}" ]; then
RPMS_DIR="${HOME}/GBS-ROOT/local/repos/tizen/${ARCH}/RPMS"
fi
RPM_FILES=("${RPMS_DIR}/${PKG_NAME}-1.0.0-1.${ARCH}.rpm" "${RPMS_DIR}/${PKG_NAME}-rag-1.0.0-1.${ARCH}.rpm")
log "[DRY-RUN] Assuming RPMs: ${RPM_FILES[*]}"
return 0
fi
if [ -z "${RPMS_DIR}" ] || [ ! -d "${RPMS_DIR}" ]; then
fail "RPMS directory not found: ${RPMS_DIR:-unknown}\n Have you run a GBS build first?"
fi
log "Searching in: ${RPMS_DIR}"
# Find all matching RPMs (exclude unittests, debuginfo, debugsource)
mapfile -t RPM_FILES < <(find "${RPMS_DIR}" -maxdepth 1 \
-name "${PKG_NAME}*.rpm" \
! -name "*-unittests-*" \
! -name "*-debuginfo-*" \
! -name "*-debugsource-*" \
2>/dev/null | sort)
if [ ${#RPM_FILES[@]} -eq 0 ]; then
fail "No ${PKG_NAME} RPMs found in ${RPMS_DIR}/\n Run a build first or remove --skip-build"
fi
for rpm in "${RPM_FILES[@]}"; do
local rpm_size=$(du -h "${rpm}" | cut -f1)
ok "Found: $(basename "${rpm}") (${rpm_size})"
done
}
# ─────────────────────────────────────────────
# Step 3: Deploy via sdb
# ─────────────────────────────────────────────
do_deploy() {
header "Step 3/4: Deploy to Device"
# 3-1. Check device connectivity
log "Checking device connectivity..."
if [ "${DRY_RUN}" = false ]; then
local device_list
device_list=$(sdb devices 2>/dev/null | tail -n +2 | grep -v "^$" || true)
if [ -z "${device_list}" ]; then
fail "No sdb devices connected.\n Start a Tizen Emulator or connect a device."
fi
local device_count
device_count=$(echo "${device_list}" | wc -l)
if [ "${device_count}" -gt 1 ] && [ -z "${DEVICE_SERIAL}" ]; then
warn "Multiple devices detected. Use -d <serial> to specify one."
echo "${device_list}"
fail "Ambiguous target device"
fi
ok "Device connected"
echo " ${device_list}"
else
log "[DRY-RUN] sdb devices"
fi
# 3-2. Root access
log "Acquiring root access..."
run sdb_cmd root on
ok "Root access granted"
# 3-3. Remount filesystem
log "Remounting root filesystem as read-write..."
run sdb_shell mount -o remount,rw /
ok "Filesystem remounted (rw)"
# 3-4. Push and Install RPMs
for rpm in "${RPM_FILES[@]}"; do
local rpm_basename=$(basename "${rpm}")
log "Pushing ${rpm_basename} to device:/tmp/"
run sdb_cmd push "${rpm}" /tmp/
ok "RPM transferred: ${rpm_basename}"
log "Installing ${rpm_basename}..."
run sdb_shell rpm -Uvh --force "/tmp/${rpm_basename}"
ok "RPM installed: ${rpm_basename}"
log "Cleaning up /tmp/${rpm_basename}..."
run sdb_shell rm -f "/tmp/${rpm_basename}"
# Register the webview app to the Tizen app framework if it was just installed
if [[ "${rpm_basename}" == *"tizenclaw-webview"* ]]; then
log "Preloading registry for org.tizen.tizenclew-webview..."
run sdb_shell tpk-backend --preload -y org.tizen.tizenclew-webview
ok "App registered to registry"
fi
done
# Deploy RAG RPMs (if built)
for rpm in "${RAG_RPM_FILES[@]}"; do
local rpm_basename=$(basename "${rpm}")
log "Pushing ${rpm_basename} to device:/tmp/"
run sdb_cmd push "${rpm}" /tmp/
ok "RAG RPM transferred: ${rpm_basename}"
log "Installing ${rpm_basename}..."
run sdb_shell rpm -Uvh --force "/tmp/${rpm_basename}"
ok "RAG RPM installed: ${rpm_basename}"
log "Cleaning up /tmp/${rpm_basename}..."
run sdb_shell rm -f "/tmp/${rpm_basename}"
done
ok "All RPMs processed"
# 3-5. Auto-download and install ngrok if requested
if [ "${WITH_NGROK}" = true ]; then
log "Auto-installing ngrok..."
local ngrok_arch
case "${ARCH}" in
x86_64) ngrok_arch="amd64" ;;
aarch64) ngrok_arch="arm64" ;;
armv7l) ngrok_arch="arm" ;;
*) fail "Unsupported architecture for ngrok: ${ARCH}" ;;
esac
local ngrok_url="https://bin.equinox.io/c/bNyj1mQVY4c/ngrok-v3-stable-linux-${ngrok_arch}.tgz"
local local_tgz="/tmp/ngrok-${ngrok_arch}.tgz"
if [ "${DRY_RUN}" = false ]; then
log "Downloading ${ngrok_url}..."
curl -sL "${ngrok_url}" -o "${local_tgz}" || fail "Failed to download ngrok"
log "Extracting ngrok..."
tar -xzf "${local_tgz}" -C /tmp || fail "Failed to extract ngrok"
log "Pushing ngrok to device:/usr/bin/ngrok..."
run sdb_cmd push /tmp/ngrok /tmp/ngrok
run sdb_shell mv /tmp/ngrok /usr/bin/ngrok
run sdb_shell chmod +x /usr/bin/ngrok
log "Cleaning up local /tmp files..."
rm -f "${local_tgz}" /tmp/ngrok
ok "ngrok installed to /usr/bin/ngrok"
else
log "[DRY-RUN] Download ${ngrok_url} and push to /usr/bin/ngrok"
fi
fi
}
# ─────────────────────────────────────────────
# Step 4: Restart service & verify
# ─────────────────────────────────────────────
do_restart_and_run() {
header "Step 4/4: Restart & Run TizenClaw"
# 4-1. Daemon reload
log "Reloading systemd daemon..."
run sdb_shell systemctl daemon-reload
ok "Daemon reloaded"
# 4-2. Restart service
log "Restarting tizenclaw service..."
run sdb_shell systemctl restart tizenclaw
ok "Service restarted"
# 4-3. Wait briefly for startup
if [ "${DRY_RUN}" = false ]; then
sleep 2
fi
# 4-4. Check service status
log "Checking service status..."
echo ""
if [ "${DRY_RUN}" = false ]; then
sdb_shell systemctl status tizenclaw -l --no-pager || true
else
log "[DRY-RUN] sdb shell systemctl status tizenclaw -l"
fi
echo ""
# 4-5. Show recent logs
log "Recent journal logs:"
echo ""
if [ "${DRY_RUN}" = false ]; then
sdb_shell journalctl -u tizenclaw -n 20 --no-pager 2>/dev/null || true
else
log "[DRY-RUN] sdb shell journalctl -u tizenclaw -n 20 --no-pager"
fi
}
# ─────────────────────────────────────────────
# Step 5 (optional): E2E Smoke Test
# ─────────────────────────────────────────────
do_e2e_tests() {
if [ "${RUN_TESTS}" = false ]; then
return 0
fi
header "Step 5/5: E2E Smoke Test"
local test_script="${PROJECT_DIR}/test/e2e/test_smoke.sh"
if [ ! -f "${test_script}" ]; then
warn "E2E test script not found: ${test_script}"
return 1
fi
local test_args=()
if [ -n "${DEVICE_SERIAL}" ]; then
test_args+=("-d" "${DEVICE_SERIAL}")
fi
log "Running: ${test_script} ${test_args[*]:-}"
if [ "${DRY_RUN}" = true ]; then
echo -e " ${YELLOW}[DRY-RUN]${NC} bash ${test_script} ${test_args[*]:-}"
return 0
fi
if bash "${test_script}" "${test_args[@]+"${test_args[@]}"}"; then
ok "E2E smoke tests passed!"
else
fail "E2E smoke tests failed. See output above."
fi
}
# ─────────────────────────────────────────────
# Summary
# ─────────────────────────────────────────────
show_summary() {
echo ""
header "Deploy Complete!"
ok "TizenClaw has been deployed and started successfully."
echo ""
log "Useful commands:"
log " Logs (follow): sdb shell journalctl -u tizenclaw -f"
log " Status: sdb shell systemctl status tizenclaw -l"
log " Stop: sdb shell systemctl stop tizenclaw"
log " Restart: sdb shell systemctl restart tizenclaw"
echo ""
}
# ─────────────────────────────────────────────
# Main
# ─────────────────────────────────────────────
main() {
parse_args "$@"
detect_arch
check_prerequisites
do_build
do_build_rag
find_rpm
do_deploy
do_restart_and_run
do_e2e_tests
show_summary
}
main "$@"