Files
likang 4cba4bcd35
CI / typecheck + test + build (push) Has been cancelled
修改bug
2026-11-13 18:56:31 +08:00

72 lines
2.4 KiB
Bash
Executable File

#!/bin/sh
set -eu
fail() {
printf '%s\n' "PCB backend: $*" >&2
exit 1
}
# Allow diagnostics such as `docker compose run --rm pcb-backend codex --version`.
if [ "${1:-}" != python ] || [ "${2:-}" != -m ] || [ "${3:-}" != uvicorn ]; then
exec "$@"
fi
mkdir -p "$PCB_SESSION_ROOT" "$PCB_CODEX_HOME" "$HOME" "$XDG_RUNTIME_DIR" \
|| fail 'Cannot create runtime directories; check UID/GID 10001:10001 and volume ownership.'
chmod 700 "$XDG_RUNTIME_DIR"
for directory in "$PCB_SESSION_ROOT" "$PCB_CODEX_HOME" "$HOME"; do
probe=$(mktemp "$directory/.pcb-write-check.XXXXXX") \
|| fail "Runtime directory is not writable: $directory; check UID/GID 10001:10001 and read-only mounts."
rm "$probe"
done
if [ ! -e "$PCB_SESSION_ROOT/resources" ] && [ ! -L "$PCB_SESSION_ROOT/resources" ]; then
ln -s /opt/pcb-resources "$PCB_SESSION_ROOT/resources"
fi
[ -r "$PCB_SESSION_ROOT/resources/references/_index.md" ] || fail 'Missing EDA API references.'
[ -r "$PCB_FREEROUTING_JAR" ] || fail 'Missing Freerouting JAR.'
command -v "$PCB_CODEX_BIN" >/dev/null 2>&1 || fail 'Codex CLI not found; check PCB_CODEX_BIN.'
if [ -e "$PCB_EDA_BIN" ] && [ ! -x "$PCB_EDA_BIN" ]; then
fail 'EDA binary is not executable; fix permissions on the host vendor/lceda-pro directory (mounted read-only).'
fi
command -v "$PCB_EDA_BIN" >/dev/null 2>&1 || fail 'Mount the complete Linux EDA directory and check PCB_EDA_BIN.'
command -v "$PCB_BLENDER_BIN" >/dev/null 2>&1 || fail 'Blender not found; check PCB_BLENDER_BIN.'
# Validate credential presence without printing or writing its value.
python -c 'from codex_pcb.rpc import process_config; process_config(False)'
Xvfb "$DISPLAY" -screen 0 1920x1080x24 -nolisten tcp > /tmp/pcb-xvfb.log 2>&1 &
xvfb_pid=$!
app_pid=
cleanup() {
if [ -n "$app_pid" ]; then
kill -TERM "$app_pid" 2>/dev/null || true
wait "$app_pid" 2>/dev/null || true
fi
kill -TERM "$xvfb_pid" 2>/dev/null || true
wait "$xvfb_pid" 2>/dev/null || true
}
trap cleanup EXIT
trap 'exit 143' TERM
trap 'exit 130' INT
ready=0
for attempt in 1 2 3 4 5 6 7 8 9 10; do
kill -0 "$xvfb_pid" 2>/dev/null || fail 'Xvfb exited; inspect /tmp/pcb-xvfb.log.'
if xdpyinfo -display "$DISPLAY" >/dev/null 2>&1; then
ready=1
break
fi
sleep 1
done
[ "$ready" = 1 ] || fail 'Virtual display did not become ready.'
"$@" &
app_pid=$!
set +e
wait "$app_pid"
status=$?
set -e
app_pid=
exit "$status"