| #!/usr/bin/env bash |
| set -euo pipefail |
|
|
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| SELF_PATH="$(readlink -f "${BASH_SOURCE[0]}")" |
|
|
| if [[ -d "$SCRIPT_DIR/polyguard-rl" ]]; then |
| APP_DIR="$SCRIPT_DIR/polyguard-rl" |
| else |
| APP_DIR="$SCRIPT_DIR" |
| fi |
|
|
| run_service() { |
| local service="${1:-}" |
| local title script |
|
|
| case "$service" in |
| env) |
| title="PolyGuard Backend Env" |
| script="scripts/run_env_local.sh" |
| ;; |
| api) |
| title="PolyGuard Backend API" |
| script="scripts/run_api_local.sh" |
| ;; |
| ui|frontend) |
| title="PolyGuard Frontend" |
| script="scripts/run_ui_local.sh" |
| ;; |
| *) |
| echo "Unknown service: ${service:-<empty>}" |
| echo "Expected one of: env, api, ui" |
| exit 1 |
| ;; |
| esac |
|
|
| cd "$APP_DIR" |
| echo "[$title] Starting from $APP_DIR" |
| echo "[$title] Running: bash $script" |
| echo |
|
|
| set +e |
| bash "$script" |
| local status=$? |
| set -e |
|
|
| echo |
| echo "[$title] exited with status $status." |
| if [[ -t 0 ]]; then |
| read -r -p "Press Enter to close this terminal..." _ |
| fi |
| exit "$status" |
| } |
|
|
| launch_terminal() { |
| local service="$1" |
| local title="$2" |
|
|
| if command -v gnome-terminal >/dev/null 2>&1; then |
| gnome-terminal --title="$title" -- bash "$SELF_PATH" --run-service "$service" & |
| elif command -v kgx >/dev/null 2>&1; then |
| kgx --title "$title" -- bash "$SELF_PATH" --run-service "$service" & |
| elif command -v konsole >/dev/null 2>&1; then |
| konsole --workdir "$APP_DIR" -p tabtitle="$title" -e bash "$SELF_PATH" --run-service "$service" & |
| elif command -v xfce4-terminal >/dev/null 2>&1; then |
| xfce4-terminal --title="$title" --working-directory="$APP_DIR" --execute bash "$SELF_PATH" --run-service "$service" & |
| elif command -v mate-terminal >/dev/null 2>&1; then |
| mate-terminal --title="$title" --working-directory="$APP_DIR" -- bash "$SELF_PATH" --run-service "$service" & |
| elif command -v xterm >/dev/null 2>&1; then |
| xterm -T "$title" -e bash "$SELF_PATH" --run-service "$service" & |
| else |
| echo "No supported terminal emulator found." |
| echo |
| echo "Open three terminals manually and run:" |
| echo " cd \"$APP_DIR\" && bash scripts/run_env_local.sh" |
| echo " cd \"$APP_DIR\" && bash scripts/run_api_local.sh" |
| echo " cd \"$APP_DIR\" && bash scripts/run_ui_local.sh" |
| exit 1 |
| fi |
| } |
|
|
| usage() { |
| cat <<EOF |
| Usage: bash run_all_terminals.sh [--no-env] [--no-api] [--no-ui] |
| |
| Starts PolyGuard services in separate terminal windows: |
| - backend env service: scripts/run_env_local.sh |
| - backend API service: scripts/run_api_local.sh |
| - frontend UI: scripts/run_ui_local.sh |
| EOF |
| } |
|
|
| if [[ "${1:-}" == "--run-service" ]]; then |
| run_service "${2:-}" |
| fi |
|
|
| START_ENV="true" |
| START_API="true" |
| START_UI="true" |
|
|
| for arg in "$@"; do |
| case "$arg" in |
| --no-env) START_ENV="false" ;; |
| --no-api) START_API="false" ;; |
| --no-ui|--no-frontend) START_UI="false" ;; |
| -h|--help) |
| usage |
| exit 0 |
| ;; |
| *) |
| echo "Unknown flag: $arg" |
| usage |
| exit 1 |
| ;; |
| esac |
| done |
|
|
| if [[ ! -d "$APP_DIR/scripts" ]]; then |
| echo "Could not find PolyGuard scripts directory at: $APP_DIR/scripts" |
| exit 1 |
| fi |
|
|
| echo "Starting services from: $APP_DIR" |
|
|
| if [[ "$START_ENV" == "true" ]]; then |
| launch_terminal "env" "PolyGuard Backend Env" |
| fi |
|
|
| if [[ "$START_API" == "true" ]]; then |
| launch_terminal "api" "PolyGuard Backend API" |
| fi |
|
|
| if [[ "$START_UI" == "true" ]]; then |
| launch_terminal "ui" "PolyGuard Frontend" |
| fi |
|
|
| echo "Launch commands sent. Check the newly opened terminal windows." |
|
|