-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·311 lines (256 loc) · 8.64 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·311 lines (256 loc) · 8.64 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
#!/bin/bash
# Benchmarkinator Setup Script
# This script sets up the initial configuration for Benchmarkinator
set -e
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
print_status() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
generate_password() {
local length=$1
openssl rand -base64 $length | tr -d "=+/" | cut -c1-$length
}
generate_api_key() {
openssl rand -hex 32
}
set_env_var() {
local key=$1
local value=$2
local escaped_value=${value//\\/\\\\}
escaped_value=${escaped_value//&/\\&}
escaped_value=${escaped_value//|/\\|}
sed -i "s|^${key}=.*|${key}=${escaped_value}|" .env
}
display_host_for_url() {
local bind_address=$1
if [ "$bind_address" = "127.0.0.1" ] || [ -z "$bind_address" ]; then
echo "localhost"
elif [ "$bind_address" = "0.0.0.0" ]; then
local addresses
addresses=$(hostname -I 2>/dev/null || true)
for address in $addresses; do
if [[ "$address" != 127.* ]] && [[ "$address" != "::1" ]]; then
echo "$address"
return
fi
done
hostname -f 2>/dev/null || echo "localhost"
else
echo "$bind_address"
fi
}
if [ -f ".env" ]; then
print_error ".env file already exists!"
print_warning "If you want to reconfigure, please delete the existing .env file first."
exit 1
fi
print_status "Starting Benchmarkinator setup..."
if [ ! -f "env.example" ]; then
print_error "env.example file not found!"
print_error "Please run this script from the benchmarkinator root directory."
exit 1
fi
print_status "Creating .env file from env.example..."
cp env.example .env
print_status "Generating secure random passwords and API key..."
MYSQL_PASSWORD=$(generate_password 32)
MYSQL_ROOT_PASSWORD=$(generate_password 32)
API_KEY=$(generate_api_key)
WEBPASSWORD=$(generate_password 16)
print_status "Updating .env file with generated credentials..."
set_env_var "MYSQL_PASSWORD" "$MYSQL_PASSWORD"
set_env_var "MYSQL_ROOT_PASSWORD" "$MYSQL_ROOT_PASSWORD"
set_env_var "API_KEY" "$API_KEY"
set_env_var "WEBPASSWORD" "$WEBPASSWORD"
print_success "Generated secure credentials:"
echo " MySQL Password: $MYSQL_PASSWORD"
echo " MySQL Root Password: $MYSQL_ROOT_PASSWORD"
echo " API Key: $API_KEY"
echo " Web Password: $WEBPASSWORD"
echo ""
print_status "Network and Public Access Configuration"
echo "MySQL host port [3306]:"
read -r mysql_port
mysql_port=${mysql_port:-3306}
set_env_var "MYSQL_PORT" "$mysql_port"
echo "API host port [12345]:"
read -r api_port
api_port=${api_port:-12345}
set_env_var "API_PORT" "$api_port"
echo "Admin UI bind address [0.0.0.0]:"
read -r admin_bind_address
admin_bind_address=${admin_bind_address:-0.0.0.0}
set_env_var "ADMIN_BIND_ADDRESS" "$admin_bind_address"
echo "Admin UI port [8001]:"
read -r admin_port
admin_port=${admin_port:-8001}
set_env_var "ADMIN_PORT" "$admin_port"
echo "Public UI bind address [0.0.0.0]:"
read -r public_bind_address
public_bind_address=${public_bind_address:-0.0.0.0}
set_env_var "PUBLIC_BIND_ADDRESS" "$public_bind_address"
echo "Public UI port [8002]:"
read -r public_port
public_port=${public_port:-8002}
set_env_var "PUBLIC_PORT" "$public_port"
echo "Will either UI be served through HTTPS by a reverse proxy such as BunkerWeb? (y/n)"
read -r use_https_proxy
if [[ $use_https_proxy =~ ^[Yy]$ ]]; then
set_env_var "AUTH_COOKIE_SECURE" "true"
else
set_env_var "AUTH_COOKIE_SECURE" "false"
fi
allowed_origins=""
echo "Allow direct browser access to the raw API from another origin? [n]:"
echo "Choose 'n' for normal admin/public or HAProxy use."
read -r add_origin
while [[ $add_origin =~ ^[Yy]$ ]]; do
echo "Enter allowed origin, for example https://admin.example.com:"
read -r origin
if [ -n "$origin" ]; then
if [ -n "$allowed_origins" ]; then
allowed_origins="${allowed_origins},${origin}"
else
allowed_origins="$origin"
fi
print_status "Added origin: $origin"
else
print_warning "Blank origin skipped."
fi
echo "Add another allowed origin? (y/n)"
read -r add_origin
done
set_env_var "ALLOWED_ORIGINS" "$allowed_origins"
if [[ $use_https_proxy =~ ^[Yy]$ ]] && [ -z "$allowed_origins" ]; then
print_status "ALLOWED_ORIGINS left blank."
fi
ADMIN_URL_HOST=$(display_host_for_url "$admin_bind_address")
PUBLIC_URL_HOST=$(display_host_for_url "$public_bind_address")
echo ""
print_status "Hardware Data Configuration"
echo "Do you want to load hardware data? (y/n)"
read -r load_hardware
if [[ $load_hardware =~ ^[Yy]$ ]]; then
print_status "Setting LOAD_HARDWARE_DATA=true"
set_env_var "LOAD_HARDWARE_DATA" "true"
echo ""
echo "What hardware era would you like to load?"
echo "1) retro (up to 2005)"
echo "2) retroextended (up to 2008)"
echo "3) modern (current hardware)"
echo ""
echo "Please select (1/2/3):"
read -r era_choice
case $era_choice in
1)
hardware_era="retro"
;;
2)
hardware_era="retroextended"
;;
3)
hardware_era="modern"
;;
*)
print_warning "Invalid selection. Defaulting to 'retro'."
hardware_era="retro"
;;
esac
print_status "Setting HARDWARE_ERA=$hardware_era"
set_env_var "HARDWARE_ERA" "$hardware_era"
else
print_status "Hardware data loading disabled"
set_env_var "LOAD_HARDWARE_DATA" "false"
fi
echo ""
print_status "Backup Configuration"
echo "Do you want to enable automatic database backups? (y/n)"
read -r enable_backups
if [[ $enable_backups =~ ^[Yy]$ ]]; then
print_status "Setting up automatic backups..."
if [ ! -f "backup.sh" ]; then
print_error "backup.sh not found! Please ensure backup.sh exists in the current directory."
exit 1
fi
chmod +x backup.sh
mkdir -p backups
cron_job="0 2 * * * $(pwd)/backup.sh"
if crontab -l 2>/dev/null | grep -q "backup.sh"; then
print_warning "Backup cron job already exists. Skipping cron setup."
else
(crontab -l 2>/dev/null; echo "$cron_job") | crontab -
print_success "Added nightly backup cron job (runs at 2:00 AM daily)"
fi
print_success "Automatic backups enabled!"
print_status "Backups will be stored in: $(pwd)/backups"
print_status "Default retention: 30 days"
else
print_status "Automatic backups disabled"
fi
echo ""
print_status "Building Docker containers..."
if docker compose build; then
print_success "Docker containers built successfully!"
else
print_error "Failed to build Docker containers!"
print_warning "You can try building manually later with: docker compose build"
fi
echo ""
print_success "Setup completed successfully!"
echo ""
print_status "Your admin credentials:"
echo " Username: admin"
echo " Password: $WEBPASSWORD"
echo ""
print_warning "IMPORTANT: Save your generated credentials securely!"
echo "To change the admin password, edit WEBPASSWORD in .env and rebuild containers."
echo ""
# Ask if user wants to start the application
print_status "Application Startup"
echo "Do you want to start the Benchmarkinator application now? (y/n)"
read -r start_app
if [[ $start_app =~ ^[Yy]$ ]]; then
print_status "Starting Benchmarkinator services..."
if docker compose up -d; then
print_success "Services started successfully!"
echo ""
print_status "Application is now running:"
echo " Admin UI: http://$ADMIN_URL_HOST:$admin_port"
echo " Public UI: http://$PUBLIC_URL_HOST:$public_port"
echo " API: http://localhost:$api_port"
echo ""
print_status "Login credentials:"
echo " Username: admin"
echo " Password: $WEBPASSWORD"
echo ""
print_status "To stop the services: docker compose down"
print_status "To view logs: docker compose logs -f"
else
print_error "Failed to start services!"
print_warning "You can try starting manually later with: docker compose up -d"
fi
else
print_status "Application not started."
echo ""
print_status "To start later:"
echo "1. Start services: docker compose up -d"
echo "2. Access admin UI: http://$ADMIN_URL_HOST:$admin_port"
echo "3. Access public UI: http://$PUBLIC_URL_HOST:$public_port"
echo "4. Login with: admin / $WEBPASSWORD"
fi
echo ""
print_status "To view your credentials later:"
echo " grep -E '^(MYSQL_PASSWORD|MYSQL_ROOT_PASSWORD|API_KEY|WEBPASSWORD)=' .env"