-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-env.sh
More file actions
executable file
·79 lines (60 loc) · 2.39 KB
/
generate-env.sh
File metadata and controls
executable file
·79 lines (60 loc) · 2.39 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
#!/bin/bash
ENV_PATH=("./docker/.env" "./frontend/.env")
SUPABASE_ENV_PATH="./supabase/functions/.env"
MW_CREDENTIALS_FILE="./docker/MW_CREDENTIALS.txt"
CONTAINER_NAME="mediawiki"
export LANG=C
if [[ -z "$1" ]]; then
echo "❌ No argument provided."
echo "Usage:"
echo " $0 --bot-creds"
echo " $0 --supabase-creds <supabase.log>"
exit 1
fi
if [[ "$1" == "--bot-creds" ]]; then
# Function to check container health
wait_for_container_healthy() {
echo "⌛ Waiting for '$CONTAINER_NAME' service to initialize, Hang Tight!..."
while true; do
# Get container health status
health_status=$(docker inspect --format='{{.State.Health.Status}}' "$CONTAINER_NAME" 2>/dev/null)
if [ "$health_status" = "healthy" ]; then
echo "✅ Initialized '$CONTAINER_NAME'."
return 0
fi
sleep 2
done
}
# Wait for container to be healthy
if ! wait_for_container_healthy; then
exit 1
fi
cp ./supabase/functions/.env.example ./supabase/functions/.env
# Extract MW bot password
MW_BOT_USERNAME=$(awk '/\[en\] Mediawiki BotPassword user:/ { print $NF }' "$MW_CREDENTIALS_FILE")
MW_BOT_PASSWORD=$(awk '/\[en\] Mediawiki BotPassword password:/ { print $NF }' "$MW_CREDENTIALS_FILE")
# Update MW bot password variables
sed -i "s|^MW_BOT_USERNAME=.*|MW_BOT_USERNAME=$MW_BOT_USERNAME|" $SUPABASE_ENV_PATH
sed -i "s|^MW_BOT_PASSWORD=.*|MW_BOT_PASSWORD=$MW_BOT_PASSWORD|" $SUPABASE_ENV_PATH
echo "✅ ./supabase/functions/.env successfully generated"
fi
if [[ "$1" == "--supabase-creds" ]]; then
# Verify log file is passed as an argument
if [ -z "$2" ]; then
echo "❌ Use : $0 supabase.log"
exit 1
fi
LOGFILE="$2"
cp ./docker/.env.example ./docker/.env
cp ./frontend/.env.example ./frontend/.env
# Extract Supabase variables from log file
SUPABASE_PROJECT_URL=$(awk '/API URL:/ { print $NF }' "$LOGFILE")
SUPABASE_SECRET_PROJECT_TOKEN=$(awk '/service_role key:/ { print $NF }' "$LOGFILE")
SUPABASE_ANON_KEY=$(awk '/anon key:/ { print $NF }' "$LOGFILE")
# Replace Supabase variables within .env files
for env in "${ENV_PATH[@]}"; do
sed -i "s|^SUPABASE_PROJECT_URL=.*|SUPABASE_PROJECT_URL=$SUPABASE_PROJECT_URL|" $env
sed -i "s|^SUPABASE_ANON_KEY=.*|SUPABASE_ANON_KEY=$SUPABASE_ANON_KEY|" $env
done
echo "✅ ./docker/.env, ./frontend/.env successfully generated from $LOGFILE"
fi