#!/usr/bin/env bash # The service on Linux, for working on the app: console mode with its own state directory and # socket, a local sing-box Shadowsocks server as a demo outbound, and the zapret presets of a # built release (tools/package.sh) when there is one. In the dev shell: # # tools/dev-service.sh [STATE_DIR] (Ctrl-C stops it all) # cargo run -p ps-gui -- --socket "$XDG_RUNTIME_DIR/proxy-suite-dev.sock" # # The socket is not in STATE_DIR: a Unix socket's path is limited to about 100 bytes. set -euo pipefail cd "$(dirname "$0")/.." STATE=$(realpath -m "${1:-${TMPDIR:-/tmp}/proxy-suite-dev}") mkdir -p "$STATE" SOCK=${SOCK:-${XDG_RUNTIME_DIR:-/tmp}/proxy-suite-dev.sock} free_port() { python3 -c 'import socket; s=socket.socket(); s.bind(("127.0.0.1",0)); print(s.getsockname()[1])'; } # Chosen once and kept, as the configuration that names them is. if [ ! -f "$STATE/ports" ]; then echo "SS=$(free_port) PROXY=$(free_port) CLASH=$(free_port) TEST=$(free_port)" >"$STATE/ports" fi . "$STATE/ports" KEY=a2tra2tra2tra2tra2traw== cat >"$STATE/server.json" </dev/null || true' EXIT # A configuration on the first run; after that, whatever the app made of it. if [ ! -f "$STATE/config.json" ]; then cat >"$STATE/config.json" </dev/null | tail -1 || true) if [ -n "$release" ] && [ ! -e "$STATE/bin/zapret" ]; then mkdir -p "$STATE/bin" && cp -r "$release" "$STATE/bin/zapret" fi cargo build -q -p ps-service target/debug/proxy-suite-service --console --state-dir "$STATE" --socket "$SOCK" & SERVICE=$! echo "the service: $SOCK (state in $STATE)" wait $SERVICE