-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·59 lines (50 loc) · 1.74 KB
/
Copy pathrun.sh
File metadata and controls
executable file
·59 lines (50 loc) · 1.74 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
#!/bin/zsh
set -euo pipefail
cd "$(dirname "$0")"
PYTHON_BIN="/opt/homebrew/bin/python3.13"
APP_HOST="${APP_HOST:-127.0.0.1}"
APP_PORT="${APP_PORT:-8000}"
PROJECT_ROOT="$(pwd -P)"
PROJECT_HASH="$(printf "%s" "$PROJECT_ROOT" | shasum -a 256 | cut -c1-12)"
APP_ENV_DIR="${APP_ENV_DIR:-$HOME/.cache/storagex-venv-$PROJECT_HASH}"
APP_REQUIRED_FILES=(
"pyproject.toml"
"uv.lock"
"server/app.py"
"static/index.html"
"static/app.js"
"static/styles.css"
)
if [[ ! -x "$PYTHON_BIN" ]]; then
echo "Python 3.13 was not found at $PYTHON_BIN" >&2
exit 1
fi
for required_file in "${APP_REQUIRED_FILES[@]}"; do
if [[ ! -e "$required_file" ]]; then
echo "Required project file is missing: $required_file" >&2
exit 1
fi
if ls -ldO "$required_file" 2>/dev/null | grep -q 'dataless'; then
echo "Project file is offloaded by iCloud and not fully local: $required_file" >&2
echo "In Finder, right-click the storagex folder and choose 'Download Now', or move the project out of iCloud-managed Documents." >&2
exit 1
fi
done
EXISTING_PID="$(lsof -tiTCP:"$APP_PORT" -sTCP:LISTEN 2>/dev/null || true)"
if [[ -n "$EXISTING_PID" ]]; then
EXISTING_COMMAND="$(ps -p "$EXISTING_PID" -o command= 2>/dev/null || true)"
if [[ "$EXISTING_COMMAND" == *"uvicorn server.app:app"* ]]; then
kill "$EXISTING_PID" 2>/dev/null || true
sleep 1
if ps -p "$EXISTING_PID" >/dev/null 2>&1; then
kill -9 "$EXISTING_PID" 2>/dev/null || true
fi
else
echo "Port $APP_PORT is already in use by another process:" >&2
echo "$EXISTING_COMMAND" >&2
exit 1
fi
fi
mkdir -p "$APP_ENV_DIR"
UV_PROJECT_ENVIRONMENT="$APP_ENV_DIR" uv sync --python "$PYTHON_BIN" --dev
exec "$APP_ENV_DIR/bin/uvicorn" server.app:app --host "$APP_HOST" --port "$APP_PORT"