-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev.sh
More file actions
executable file
·201 lines (178 loc) · 6.19 KB
/
Copy pathdev.sh
File metadata and controls
executable file
·201 lines (178 loc) · 6.19 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
#!/usr/bin/env bash
#
# dev.sh — One-command development environment for cloud-drive-sync
#
# Usage:
# ./dev.sh Setup + start daemon in demo mode
# ./dev.sh --with-ui Also start the Tauri UI dev server
# ./dev.sh --test Run tests first, then start daemon
#
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
DAEMON_DIR="$SCRIPT_DIR/daemon"
UI_DIR="$SCRIPT_DIR/ui"
VENV="$DAEMON_DIR/.venv"
PYTHON="$VENV/bin/python"
PIP="$VENV/bin/pip"
DEMO_BASE="$HOME/cloud-drive-sync-demo"
DEMO_LOCAL="$DEMO_BASE/local"
DEMO_REMOTE="$DEMO_BASE/remote"
WITH_UI=false
RUN_TESTS=false
DAEMON_PID=""
UI_PID=""
# ── Parse arguments ─────────────────────────────────────────────
for arg in "$@"; do
case "$arg" in
--with-ui) WITH_UI=true ;;
--test) RUN_TESTS=true ;;
-h|--help)
echo "Usage: ./dev.sh [--with-ui] [--test]"
echo ""
echo " --with-ui Also start the Tauri UI dev server"
echo " --test Run tests before starting the daemon"
exit 0
;;
*)
echo "Unknown option: $arg"
echo "Run ./dev.sh --help for usage."
exit 1
;;
esac
done
# ── Cleanup on exit ─────────────────────────────────────────────
cleanup() {
echo ""
echo "Shutting down..."
[ -n "$UI_PID" ] && kill "$UI_PID" 2>/dev/null && echo " Stopped UI (PID $UI_PID)"
[ -n "$DAEMON_PID" ] && kill "$DAEMON_PID" 2>/dev/null && echo " Stopped daemon (PID $DAEMON_PID)"
wait 2>/dev/null
echo "Done."
}
trap cleanup EXIT INT TERM
# ── Check Python version ────────────────────────────────────────
check_python() {
local py=""
for candidate in python3.12 python3.13 python3; do
if command -v "$candidate" &>/dev/null; then
py="$candidate"
break
fi
done
if [ -z "$py" ]; then
echo "ERROR: Python 3.12+ is required but not found."
echo "Install it with your package manager (e.g., sudo dnf install python3.12)"
exit 1
fi
local version
version=$("$py" -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')")
local major minor
major=$(echo "$version" | cut -d. -f1)
minor=$(echo "$version" | cut -d. -f2)
if [ "$major" -lt 3 ] || { [ "$major" -eq 3 ] && [ "$minor" -lt 12 ]; }; then
echo "ERROR: Python 3.12+ required, found $version"
exit 1
fi
echo "$py"
}
# ── Setup venv ──────────────────────────────────────────────────
setup_venv() {
if [ ! -d "$VENV" ]; then
echo "Creating Python virtual environment..."
local py
py=$(check_python)
"$py" -m venv "$VENV"
"$PIP" install --quiet --upgrade pip
"$PIP" install --quiet -e "$DAEMON_DIR[dev]"
echo " Venv created at $VENV"
else
echo " Venv already exists at $VENV"
fi
}
# ── Setup demo directories ──────────────────────────────────────
setup_demo_dirs() {
mkdir -p "$DEMO_LOCAL" "$DEMO_REMOTE"
echo " Demo dirs: $DEMO_LOCAL (local), $DEMO_REMOTE (remote)"
}
# ── Wait for socket ─────────────────────────────────────────────
wait_for_socket() {
local socket_path
socket_path="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}/cloud-drive-sync.sock"
local timeout=15
local elapsed=0
echo -n " Waiting for daemon socket"
while [ ! -S "$socket_path" ] && [ "$elapsed" -lt "$timeout" ]; do
echo -n "."
sleep 0.5
elapsed=$((elapsed + 1))
done
echo ""
if [ -S "$socket_path" ]; then
echo " Daemon socket ready: $socket_path"
return 0
else
echo " WARNING: Daemon socket not found after ${timeout}s"
return 1
fi
}
# ── Main ────────────────────────────────────────────────────────
echo "========================================"
echo " cloud-drive-sync development environment"
echo "========================================"
echo ""
# Step 1: Python environment
echo "[1/4] Setting up Python environment..."
setup_venv
# Step 2: Demo directories
echo "[2/4] Setting up demo directories..."
setup_demo_dirs
# Step 3: Run tests (if requested)
if [ "$RUN_TESTS" = true ]; then
echo "[*] Running tests..."
cd "$DAEMON_DIR"
"$VENV/bin/pytest" -v
cd "$SCRIPT_DIR"
echo ""
fi
# Step 4: Start daemon in demo mode
echo "[3/4] Starting daemon in demo mode..."
"$PYTHON" -m cloud_drive_sync --log-level debug start --foreground --demo &
DAEMON_PID=$!
echo " Daemon PID: $DAEMON_PID"
wait_for_socket || true
# Step 5: Start UI (if requested)
if [ "$WITH_UI" = true ]; then
echo "[4/4] Starting Tauri UI dev server..."
if [ ! -d "$UI_DIR/node_modules" ]; then
echo " Installing npm dependencies..."
cd "$UI_DIR" && npm install && cd "$SCRIPT_DIR"
fi
cd "$UI_DIR" && npm run tauri dev &
UI_PID=$!
cd "$SCRIPT_DIR"
echo " UI PID: $UI_PID"
else
echo "[4/4] Skipping UI (use --with-ui to start)"
fi
# Print banner
echo ""
echo "========================================"
echo " Ready!"
echo "========================================"
echo ""
echo " Daemon: running in demo mode (PID $DAEMON_PID)"
echo " Local: $DEMO_LOCAL"
echo " Remote: $DEMO_REMOTE"
echo " Socket: ${XDG_RUNTIME_DIR:-/run/user/$(id -u)}/cloud-drive-sync.sock"
if [ "$WITH_UI" = true ]; then
echo " UI: http://localhost:1420"
fi
echo ""
echo " Try it:"
echo " echo 'hello' > $DEMO_LOCAL/test.txt"
echo " ls $DEMO_REMOTE/ # should appear after sync"
echo ""
echo " Press Ctrl+C to stop."
echo ""
# Wait for background processes
wait