-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.sh
48 lines (33 loc) · 1.12 KB
/
init.sh
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
#!/bin/bash
# used for the cron job
printenv >> /etc/environment &
database_path="/backend/config/database.db"
config_json_path="/backend/config/config.json"
config_sample_json_path="/backend/config_sample/config_sample.json"
echo "Waiting for the backend to become available on port 1323..."
while ! curl -s http://localhost:1323/api > /dev/null; do
sleep 1
done
if [ -e "$config_json_path" ]; then
echo "Config file already exists, skipping copy"
curl -X GET http://localhost:1323/api/update \
-H "X-API-Key: ${API_KEY}"
else
echo "Config file doesn't exist, creating it"
cp "$config_sample_json_path" "$config_json_path"
fi
if [[ -z "${API_KEY}" ]]; then
echo "Error: API_KEY environment variable is not set."
exit 1
fi
if [ -e "$database_path" ]; then
echo "Database already exists, skipping user initialization"
else
echo "Database file doesn't exist, running user initialization"
sqlite3 "$database_path" "VACUUM;"
echo "Database created"
curl -X GET http://localhost:1323/api/initdb \
-H "X-API-Key: ${API_KEY}"
fi
curl -X GET http://localhost:1323/api/collectStats \
-H "X-API-Key: ${API_KEY}"