-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_db.template.sh
52 lines (36 loc) · 1.2 KB
/
setup_db.template.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
49
50
51
52
#!/bin/bash
MYSQL_ROOT_PASSWORD=REPLACE_WITH_MYSQL_ROOT_PASSWORD
MYSQL_BOT_PASSWORD=REPLACE_WITH_MYSQL_PASSWORD
echo 'Setting up db'
docker run --rm -v $PWD/db-data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD \
-e MYSQL_USER=bot \
-e MYSQL_PASSWORD=$MYSQL_BOT_PASSWORD \
-e MYSQL_DATABASE=bot \
-e MYSQL_HOST=db \
mariadb:10.7 &> log &
pid=$!
while true; do
n=$(grep 'mariadb.org binary distribution' log | wc -l)
if [ $n = 2 ]; then
break
fi
sleep 0.5
done
kill -QUIT $pid
wait $pid
echo 'Loading db data'
docker run --name mysql-tmp --rm -v $PWD/db-data:/var/lib/mysql mariadb:10.7 &> log &
pid=$!
while true; do
n=$(grep 'mariadb.org binary distribution' log | wc -l)
if [ $n = 1 ]; then
break
fi
sleep 0.5
done
docker exec -i mysql-tmp mysql -u bot -p$MYSQL_BOT_PASSWORD bot < db.sql
docker exec -i mysql-tmp mysql -u bot -p$MYSQL_BOT_PASSWORD bot -e "INSERT INTO bot_config(name, value) values('channel_id','REPLACE_WITH_CHANNEL_ID')"
docker exec -i mysql-tmp mysql -u bot -p$MYSQL_BOT_PASSWORD bot -e "INSERT INTO bot_config(name, value) values('admin_user_id','REPLACE_WITH_ADMIN_USER_ID')"
kill -QUIT $pid
wait $pid