-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·174 lines (152 loc) · 6.47 KB
/
run.sh
File metadata and controls
executable file
·174 lines (152 loc) · 6.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/bin/bash
set -euo pipefail
# ====================================================================
#
# Exo Proxy Fortress - Installer & Runner
#
# ====================================================================
VENV_DIR="venv"
REQUIREMENTS_FILE="requirements.txt"
GUNICORN_CONF="gunicorn_conf.py"
APP_MODULE="app.main:app"
STATE_FILE=".setup_state"
# Allow override with $PYTHON_BIN env var
PYTHON_BIN="${PYTHON_BIN:-python3}"
COLOR_RESET='\e[0m'; COLOR_INFO='\e[1;34m'; COLOR_SUCCESS='\e[1;32m'
COLOR_ERROR='\e[1;31m'; COLOR_WARN='\e[1;33m'; COLOR_HEADER='\e[1;35m'
print_header() { echo -e "\n${COLOR_HEADER}=====================================================${COLOR_RESET}"; \
echo -e "${COLOR_HEADER}$1${COLOR_RESET}"; \
echo -e "${COLOR_HEADER}=====================================================${COLOR_RESET}"; }
print_info() { echo -e "${COLOR_INFO}[INFO]${COLOR_RESET} $*"; }
print_success() { echo -e "${COLOR_SUCCESS}[SUCCESS]${COLOR_RESET} $*"; }
print_error() { echo -e "${COLOR_ERROR}[ERROR]${COLOR_RESET} $*" >&2; }
print_warn() { echo -e "${COLOR_WARN}[WARNING]${COLOR_RESET} $*"; }
clear
print_header " Exo Proxy Fortress Installer & Runner"
print_info "Choose installation method:"
echo " 1) Docker (recommended - isolated environment)"
echo " 2) Native Python (direct installation)"
read -p "Enter your choice (1 or 2): " INSTALL_METHOD
if [[ "$INSTALL_METHOD" == "1" ]]; then
print_info "Selected Docker installation..."
# Check if Docker and Docker Compose are available
if ! command -v docker &>/dev/null; then
print_error "Docker is not installed. Please install Docker first."
exit 1
fi
if ! command -v docker-compose &>/dev/null; then
print_error "Docker Compose is not installed. Please install Docker Compose first."
exit 1
fi
print_success "Docker and Docker Compose are available."
# Check if .env exists, if not run setup wizard
if [[ ! -f ".env" ]]; then
print_header "--- Docker Setup: Server Configuration ---"
"$PYTHON_BIN" setup_wizard.py
if [ $? -ne 0 ]; then
print_error "Setup wizard failed. Aborting."
exit 1
fi
print_success ".env file created."
fi
print_header "--- Starting Exo Proxy Fortress with Docker ---"
print_info "Building and starting containers..."
print_info "This may take a few minutes on first run."
echo
exec docker-compose up --build
else
print_info "Selected native Python installation..."
print_info "Performing initial system checks..."
if ! command -v "$PYTHON_BIN" &>/dev/null || ! "$PYTHON_BIN" -m pip --version &>/dev/null || ! "$PYTHON_BIN" -m venv -h &>/dev/null; then
print_error "Python ($PYTHON_BIN), pip, or venv is missing."
exit 1
fi
print_success "Python ($PYTHON_BIN), pip, and venv are available."
CURRENT_STATE=0
if [[ -f "$STATE_FILE" ]]; then CURRENT_STATE=$(cat "$STATE_FILE"); fi
if [[ "$CURRENT_STATE" -ge 3 ]] && [[ ! -f ".env" ]]; then
print_warn "Setup complete, but '.env' file is missing!"
read -p "Run setup wizard again? (y/n): " REBUILD_CHOICE
if [[ "$REBUILD_CHOICE" =~ ^[Yy]$ ]]; then
print_info "Resetting setup state..."
rm -f "$STATE_FILE"
CURRENT_STATE=0
else
print_info "Aborting."
exit 0
fi
fi
if [[ "$CURRENT_STATE" -lt 3 ]]; then
print_info "Setup state is ${CURRENT_STATE}/3. Starting or resuming installation..."
if [[ "$CURRENT_STATE" -lt 1 ]]; then
print_header "--- [Step 1/3] Creating Python Virtual Environment ---"
"$PYTHON_BIN" -m venv "$VENV_DIR"
echo "1" > "$STATE_FILE"
print_success "Virtual environment created."
fi
source "$VENV_DIR/bin/activate"
if [[ "$CURRENT_STATE" -lt 2 ]]; then
print_header "--- [Step 2/3] Installing Python Dependencies ---"
pip install --no-cache-dir -r "$REQUIREMENTS_FILE"
echo "2" > "$STATE_FILE"
print_success "All dependencies installed."
fi
if [[ "$CURRENT_STATE" -lt 3 ]]; then
print_header "--- [Step 3/3] Server Configuration ---"
"$PYTHON_BIN" setup_wizard.py
if [ $? -ne 0 ]; then
print_error "Setup wizard failed. Aborting."
exit 1
fi
echo "3" > "$STATE_FILE"
print_success ".env file created."
fi
print_header "--- Setup Complete! ---"
print_success "The database will be created automatically on first run."
fi
SERVICE_CREATED=false
if [[ "$(uname)" == "Linux" ]] && command -v systemctl &>/dev/null && [[ ! -f "/etc/systemd/system/exo_proxy.service" ]]; then
print_header "--- Optional: Create a Systemd Service ---"
read -p "Create and enable a systemd service to run on boot? (y/n): " CREATE_SERVICE
if [[ "$CREATE_SERVICE" =~ ^[Yy]$ ]]; then
SERVICE_FILE_PATH="/etc/systemd/system/exo_proxy.service"
print_info "Creating systemd service file..."
PROJECT_DIR=$(pwd)
PORT_TO_USE=$(grep -E '^PROXY_PORT=' .env | cut -d '=' -f2 | tr -d '"' || echo "8080")
SERVICE_FILE_CONTENT=$(cat << EOF
[Unit]
Description=Exo Proxy Fortress Service
After=network.target
[Service]
User=${USER}
Group=$(id -gn ${USER})
WorkingDirectory=${PROJECT_DIR}
Environment="PYTHONPATH=${PROJECT_DIR}"
ExecStart=${PROJECT_DIR}/${VENV_DIR}/bin/gunicorn -c ${PROJECT_DIR}/${GUNICORN_CONF} ${APP_MODULE} --bind 0.0.0.0:${PORT_TO_USE}
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
EOF
)
print_warn "Root privileges are required to install the service."
echo "$SERVICE_FILE_CONTENT" | sudo tee "$SERVICE_FILE_PATH" > /dev/null
sudo systemctl daemon-reload
sudo systemctl enable "exo_proxy.service"
sudo systemctl start "exo_proxy.service"
print_header "--- Service Management ---"
print_success "Service 'exo_proxy' is now running."
print_info "Check status: sudo systemctl status exo_proxy"
SERVICE_CREATED=true
fi
fi
if [ "$SERVICE_CREATED" = false ]; then
print_header "--- Starting Exo Proxy Fortress (Foreground Mode) ---"
source "$VENV_DIR/bin/activate"
export PYTHONPATH=.
PORT_TO_USE=$(grep -E '^PROXY_PORT=' .env | cut -d '=' -f2 | tr -d '"' | tr -d "'" || echo "8080")
print_info "Starting Gunicorn server on http://0.0.0.0:${PORT_TO_USE}"
print_info "Press Ctrl+C to stop the server."
echo
exec gunicorn -c "$GUNICORN_CONF" "$APP_MODULE" --bind "0.0.0.0:${PORT_TO_USE}"
fi