Files
simtrace-analyser/start.sh
T
catarrh 65c8ab215b README: two explicit install paths; Windows launchers pass --db and quote paths
- the Install section now leads with the release artifacts (the wheel via
  pipx/pip, the direct release URL, `gh release download` for the
  version-agnostic case, and the source archive) and keeps the git clone as
  the development path.  It finally names the launchers (./start.sh,
  start.bat): a clone needs no install, but the README never said how to start
  it while the Running section only showed the console script that an install
  provides.
- Windows: the USB section now says the .bat launchers mirror the shell ones
  and call the `python` command (Python 3 must be on PATH); the Install section
  carries the same note.
- start.bat: --db/DB was parsed and then never passed to the server; it is
  passed now, and --gsmtap-port is sent only for gsmtap capture (as start.sh
  already did).  Both .bat files passed values unquoted and stripped the
  quotes of pass-through options, so paths with spaces broke
  (--db "C:\My Data\...", --web-dir, --pcap, --output); values are quoted now
  and pass-through keeps the original quoting (argument assembly through
  delayed expansion).
- the launcher usage comments include the `disabled` capture mode.
- verified the argument assembly with Wine cmd.exe and an echo harness: the
  quoted paths survive, --db arrives, --gsmtap-port appears only for gsmtap;
  547 Python + 80 Node tests.
2026-10-20 23:15:54 +03:00

77 lines
2.5 KiB
Bash
Executable File

#!/bin/bash
# simtrace-analyser-server startup script
#
# Usage: ./start.sh [--capture gsmtap|direct|disabled] [--port PORT] [--db PATH] [--gsmtap-port PORT]
#
# Options set via environment variables act as defaults; CLI flags override them.
set -euo pipefail
shopt -s nullglob
PROJECT_DIR="$(cd "$(dirname "$0")" && pwd)"
CAPTURE="${CAPTURE:-gsmtap}"
PORT="${PORT:-8081}"
DB="${DB:-}"
GSMTAP_PORT="${GSMTAP_PORT:-4729}"
while [[ $# -gt 0 ]]; do
case "$1" in
--capture) CAPTURE="$2"; shift 2 ;;
--port) PORT="$2"; shift 2 ;;
--db) DB="$2"; shift 2 ;;
--gsmtap-port) GSMTAP_PORT="$2"; shift 2 ;;
*) EXTRA_ARGS+=("$1"); shift ;;
esac
done
if [[ "$CAPTURE" == "direct" ]]; then
bad_perms=0
for devdir in /sys/bus/usb/devices/*/; do
[[ -f "${devdir}busnum" ]] || continue
[[ -f "${devdir}devnum" ]] || continue
[[ -f "${devdir}uevent" ]] || continue
vid=$(grep -oP 'PRODUCT=\K[a-f0-9]+' "${devdir}uevent" 2>/dev/null || true)
[[ "$vid" == "1d50" ]] || continue
busnum=$(<"${devdir}busnum")
devnum=$(<"${devdir}devnum")
node=$(printf '/dev/bus/usb/%03d/%03d' "$busnum" "$devnum")
if [[ ! -e "$node" ]]; then
continue
fi
if [[ -w "$node" ]]; then
break
fi
bad_perms=1
echo "Permission denied on $node" >&2
done
if [[ $bad_perms -eq 1 ]]; then
echo "" >&2
echo "Install the udev rule (then reconnect the device):" >&2
echo "──────────────────────────────────────────────────" >&2
echo " sudo cp '$PROJECT_DIR/70-simtrace2-pysniff.rules' /etc/udev/rules.d/" >&2
echo " sudo udevadm control --reload-rules" >&2
echo " sudo udevadm trigger" >&2
echo "──────────────────────────────────────────────────" >&2
exit 3
fi
fi
ARGS=()
ARGS+=(--capture "$CAPTURE")
ARGS+=(--port "$PORT")
[[ -n "$DB" ]] && ARGS+=(--db "$DB")
[[ "$CAPTURE" == "gsmtap" ]] && ARGS+=(--gsmtap-port "$GSMTAP_PORT")
ARGS+=("${EXTRA_ARGS[@]}")
echo "Starting simtrace-analyser-server..." >&2
echo "PWA (simtrace-analyser) will be served at http://127.0.0.1:$PORT/" >&2
exec env PYTHONPATH="$PROJECT_DIR" python3 -m simtrace_analyser "${ARGS[@]}"