40 lines
1.3 KiB
Bash
Executable File
40 lines
1.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
|
if [ -f "$SCRIPT_DIR/.env" ]; then
|
|
set -a
|
|
# shellcheck source=/dev/null
|
|
source "$SCRIPT_DIR/.env"
|
|
set +a
|
|
fi
|
|
|
|
APP_PATH="${MATTERMOST_APP_PATH:-/Applications/Mattermost.app}"
|
|
APP_NAME="${MATTERMOST_APP_NAME:-Mattermost}"
|
|
APP_BIN="${MATTERMOST_APP_BIN:-$APP_PATH/Contents/MacOS/Mattermost}"
|
|
PROXY_HOST="${MATTERMOST_MIRROR_LISTEN_HOST:-127.0.0.1}"
|
|
PROXY_PORT="${MATTERMOST_MIRROR_LISTEN_PORT:-8080}"
|
|
LAUNCH_MODE="${MATTERMOST_MIRROR_LAUNCH_MODE:-open}"
|
|
|
|
if [ "$LAUNCH_MODE" = "binary" ]; then
|
|
if [ ! -x "$APP_BIN" ]; then
|
|
echo "Mattermost app binary not found or not executable: $APP_BIN" >&2
|
|
echo "Set MATTERMOST_APP_BIN in scripts/mattermost-proxy/.env if needed." >&2
|
|
exit 1
|
|
fi
|
|
|
|
exec "$APP_BIN" --proxy-server="http://${PROXY_HOST}:${PROXY_PORT}"
|
|
fi
|
|
|
|
if [ ! -d "$APP_PATH" ]; then
|
|
echo "Mattermost app bundle not found: $APP_PATH" >&2
|
|
echo "Set MATTERMOST_APP_PATH in scripts/mattermost-proxy/.env if needed." >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Prefer macOS LaunchServices over invoking the Electron binary directly.
|
|
# Direct binary launch can crash sandboxed Electron apps with Mach rendezvous
|
|
# errors because their expected app/container parent process is missing.
|
|
exec open -n "$APP_PATH" --args --proxy-server="http://${PROXY_HOST}:${PROXY_PORT}"
|