mirror of
https://github.com/smittix/intercept.git
synced 2026-07-29 11:08:10 -07:00
fix: convert start.sh line endings from CRLF to LF
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,150 +1,150 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# INTERCEPT - Production Startup Script
|
# INTERCEPT - Production Startup Script
|
||||||
#
|
#
|
||||||
# Starts INTERCEPT with gunicorn + gevent for production use.
|
# Starts INTERCEPT with gunicorn + gevent for production use.
|
||||||
# Falls back to Flask dev server if gunicorn is not installed.
|
# Falls back to Flask dev server if gunicorn is not installed.
|
||||||
#
|
#
|
||||||
# Usage:
|
# Usage:
|
||||||
# ./start.sh # Default: 0.0.0.0:5050
|
# ./start.sh # Default: 0.0.0.0:5050
|
||||||
# ./start.sh -p 8080 # Custom port
|
# ./start.sh -p 8080 # Custom port
|
||||||
# ./start.sh --https # HTTPS with self-signed cert
|
# ./start.sh --https # HTTPS with self-signed cert
|
||||||
# ./start.sh --debug # Debug mode (Flask dev server)
|
# ./start.sh --debug # Debug mode (Flask dev server)
|
||||||
# ./start.sh --check-deps # Check dependencies and exit
|
# ./start.sh --check-deps # Check dependencies and exit
|
||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
# ── Defaults (can be overridden by env vars or CLI flags) ────────────────────
|
# ── Defaults (can be overridden by env vars or CLI flags) ────────────────────
|
||||||
HOST="${INTERCEPT_HOST:-0.0.0.0}"
|
HOST="${INTERCEPT_HOST:-0.0.0.0}"
|
||||||
PORT="${INTERCEPT_PORT:-5050}"
|
PORT="${INTERCEPT_PORT:-5050}"
|
||||||
DEBUG=0
|
DEBUG=0
|
||||||
HTTPS=0
|
HTTPS=0
|
||||||
CHECK_DEPS=0
|
CHECK_DEPS=0
|
||||||
|
|
||||||
# ── Parse CLI arguments ─────────────────────────────────────────────────────
|
# ── Parse CLI arguments ─────────────────────────────────────────────────────
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-p|--port)
|
-p|--port)
|
||||||
PORT="$2"
|
PORT="$2"
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
-H|--host)
|
-H|--host)
|
||||||
HOST="$2"
|
HOST="$2"
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
-d|--debug)
|
-d|--debug)
|
||||||
DEBUG=1
|
DEBUG=1
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--https)
|
--https)
|
||||||
HTTPS=1
|
HTTPS=1
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--check-deps)
|
--check-deps)
|
||||||
CHECK_DEPS=1
|
CHECK_DEPS=1
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-h|--help)
|
-h|--help)
|
||||||
echo "Usage: start.sh [OPTIONS]"
|
echo "Usage: start.sh [OPTIONS]"
|
||||||
echo ""
|
echo ""
|
||||||
echo "Options:"
|
echo "Options:"
|
||||||
echo " -p, --port PORT Port to listen on (default: 5050)"
|
echo " -p, --port PORT Port to listen on (default: 5050)"
|
||||||
echo " -H, --host HOST Host to bind to (default: 0.0.0.0)"
|
echo " -H, --host HOST Host to bind to (default: 0.0.0.0)"
|
||||||
echo " -d, --debug Run in debug mode (Flask dev server)"
|
echo " -d, --debug Run in debug mode (Flask dev server)"
|
||||||
echo " --https Enable HTTPS with self-signed certificate"
|
echo " --https Enable HTTPS with self-signed certificate"
|
||||||
echo " --check-deps Check dependencies and exit"
|
echo " --check-deps Check dependencies and exit"
|
||||||
echo " -h, --help Show this help message"
|
echo " -h, --help Show this help message"
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Unknown option: $1" >&2
|
echo "Unknown option: $1" >&2
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
# ── Export for config.py ─────────────────────────────────────────────────────
|
# ── Export for config.py ─────────────────────────────────────────────────────
|
||||||
export INTERCEPT_HOST="$HOST"
|
export INTERCEPT_HOST="$HOST"
|
||||||
export INTERCEPT_PORT="$PORT"
|
export INTERCEPT_PORT="$PORT"
|
||||||
|
|
||||||
# ── Dependency check (delegate to intercept.py) ─────────────────────────────
|
# ── Dependency check (delegate to intercept.py) ─────────────────────────────
|
||||||
if [[ "$CHECK_DEPS" -eq 1 ]]; then
|
if [[ "$CHECK_DEPS" -eq 1 ]]; then
|
||||||
exec python intercept.py --check-deps
|
exec python intercept.py --check-deps
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# ── Debug mode always uses Flask dev server ──────────────────────────────────
|
# ── Debug mode always uses Flask dev server ──────────────────────────────────
|
||||||
if [[ "$DEBUG" -eq 1 ]]; then
|
if [[ "$DEBUG" -eq 1 ]]; then
|
||||||
echo "[INTERCEPT] Starting in debug mode (Flask dev server)..."
|
echo "[INTERCEPT] Starting in debug mode (Flask dev server)..."
|
||||||
export INTERCEPT_DEBUG=1
|
export INTERCEPT_DEBUG=1
|
||||||
exec python intercept.py --host "$HOST" --port "$PORT" --debug
|
exec python intercept.py --host "$HOST" --port "$PORT" --debug
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# ── HTTPS certificate generation ────────────────────────────────────────────
|
# ── HTTPS certificate generation ────────────────────────────────────────────
|
||||||
CERT_DIR="certs"
|
CERT_DIR="certs"
|
||||||
CERT_FILE="$CERT_DIR/intercept.crt"
|
CERT_FILE="$CERT_DIR/intercept.crt"
|
||||||
KEY_FILE="$CERT_DIR/intercept.key"
|
KEY_FILE="$CERT_DIR/intercept.key"
|
||||||
|
|
||||||
if [[ "$HTTPS" -eq 1 ]]; then
|
if [[ "$HTTPS" -eq 1 ]]; then
|
||||||
if [[ ! -f "$CERT_FILE" || ! -f "$KEY_FILE" ]]; then
|
if [[ ! -f "$CERT_FILE" || ! -f "$KEY_FILE" ]]; then
|
||||||
echo "[INTERCEPT] Generating self-signed SSL certificate..."
|
echo "[INTERCEPT] Generating self-signed SSL certificate..."
|
||||||
mkdir -p "$CERT_DIR"
|
mkdir -p "$CERT_DIR"
|
||||||
openssl req -x509 -newkey rsa:2048 \
|
openssl req -x509 -newkey rsa:2048 \
|
||||||
-keyout "$KEY_FILE" -out "$CERT_FILE" \
|
-keyout "$KEY_FILE" -out "$CERT_FILE" \
|
||||||
-days 365 -nodes \
|
-days 365 -nodes \
|
||||||
-subj '/CN=intercept/O=INTERCEPT/C=US' 2>/dev/null
|
-subj '/CN=intercept/O=INTERCEPT/C=US' 2>/dev/null
|
||||||
echo "[INTERCEPT] SSL certificate generated: $CERT_FILE"
|
echo "[INTERCEPT] SSL certificate generated: $CERT_FILE"
|
||||||
else
|
else
|
||||||
echo "[INTERCEPT] Using existing SSL certificate: $CERT_FILE"
|
echo "[INTERCEPT] Using existing SSL certificate: $CERT_FILE"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# ── Detect gunicorn + gevent ─────────────────────────────────────────────────
|
# ── Detect gunicorn + gevent ─────────────────────────────────────────────────
|
||||||
HAS_GUNICORN=0
|
HAS_GUNICORN=0
|
||||||
HAS_GEVENT=0
|
HAS_GEVENT=0
|
||||||
|
|
||||||
if python -c "import gunicorn" 2>/dev/null; then
|
if python -c "import gunicorn" 2>/dev/null; then
|
||||||
HAS_GUNICORN=1
|
HAS_GUNICORN=1
|
||||||
fi
|
fi
|
||||||
if python -c "import gevent" 2>/dev/null; then
|
if python -c "import gevent" 2>/dev/null; then
|
||||||
HAS_GEVENT=1
|
HAS_GEVENT=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# ── Start the server ─────────────────────────────────────────────────────────
|
# ── Start the server ─────────────────────────────────────────────────────────
|
||||||
if [[ "$HAS_GUNICORN" -eq 1 && "$HAS_GEVENT" -eq 1 ]]; then
|
if [[ "$HAS_GUNICORN" -eq 1 && "$HAS_GEVENT" -eq 1 ]]; then
|
||||||
echo "[INTERCEPT] Starting production server (gunicorn + gevent)..."
|
echo "[INTERCEPT] Starting production server (gunicorn + gevent)..."
|
||||||
echo "[INTERCEPT] Listening on ${HOST}:${PORT}"
|
echo "[INTERCEPT] Listening on ${HOST}:${PORT}"
|
||||||
|
|
||||||
export INTERCEPT_USE_GEVENT=1
|
export INTERCEPT_USE_GEVENT=1
|
||||||
|
|
||||||
GUNICORN_ARGS=(
|
GUNICORN_ARGS=(
|
||||||
-k gevent
|
-k gevent
|
||||||
-w 1
|
-w 1
|
||||||
--timeout 300
|
--timeout 300
|
||||||
--worker-connections 1000
|
--worker-connections 1000
|
||||||
--bind "${HOST}:${PORT}"
|
--bind "${HOST}:${PORT}"
|
||||||
--access-logfile -
|
--access-logfile -
|
||||||
--error-logfile -
|
--error-logfile -
|
||||||
)
|
)
|
||||||
|
|
||||||
if [[ "$HTTPS" -eq 1 ]]; then
|
if [[ "$HTTPS" -eq 1 ]]; then
|
||||||
GUNICORN_ARGS+=(--certfile "$CERT_FILE" --keyfile "$KEY_FILE")
|
GUNICORN_ARGS+=(--certfile "$CERT_FILE" --keyfile "$KEY_FILE")
|
||||||
echo "[INTERCEPT] HTTPS enabled"
|
echo "[INTERCEPT] HTTPS enabled"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exec gunicorn "${GUNICORN_ARGS[@]}" app:app
|
exec gunicorn "${GUNICORN_ARGS[@]}" app:app
|
||||||
else
|
else
|
||||||
if [[ "$HAS_GUNICORN" -eq 0 ]]; then
|
if [[ "$HAS_GUNICORN" -eq 0 ]]; then
|
||||||
echo "[INTERCEPT] gunicorn not found — falling back to Flask dev server"
|
echo "[INTERCEPT] gunicorn not found — falling back to Flask dev server"
|
||||||
fi
|
fi
|
||||||
if [[ "$HAS_GEVENT" -eq 0 ]]; then
|
if [[ "$HAS_GEVENT" -eq 0 ]]; then
|
||||||
echo "[INTERCEPT] gevent not found — falling back to Flask dev server"
|
echo "[INTERCEPT] gevent not found — falling back to Flask dev server"
|
||||||
fi
|
fi
|
||||||
echo "[INTERCEPT] Install with: pip install gunicorn gevent"
|
echo "[INTERCEPT] Install with: pip install gunicorn gevent"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
FLASK_ARGS=(--host "$HOST" --port "$PORT")
|
FLASK_ARGS=(--host "$HOST" --port "$PORT")
|
||||||
if [[ "$HTTPS" -eq 1 ]]; then
|
if [[ "$HTTPS" -eq 1 ]]; then
|
||||||
FLASK_ARGS+=(--https)
|
FLASK_ARGS+=(--https)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exec python intercept.py "${FLASK_ARGS[@]}"
|
exec python intercept.py "${FLASK_ARGS[@]}"
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user