-
Notifications
You must be signed in to change notification settings - Fork 8
/
make.sh
executable file
·152 lines (121 loc) · 4.11 KB
/
make.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
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
#!/usr/bin/env bash
readonly DIR_SRC="src/dexonline"
readonly URL_DB="https://dexonline.ro/static/download/dex-database.sql.gz"
readonly DIR_DB="db/dex-database.sql.gz"
_clone-src() {
set -x
if [[ ! -d "${DIR_SRC}" ]]; then
git clone https://github.com/dexonline/dexonline/ "${DIR_SRC}"
fi
}
_download-db() {
set -x
if [[ ! -f "${DIR_DB}" ]]; then
wget -O "${DIR_DB}" "${URL_DB}"
fi
}
_setup-selinux() {
set -x
if ! command -v getenforce | grep "Enforcing";
then
sudo chcon -Rt svirt_sandbox_file_t .
fi
}
_update-permissions() {
set -x
if [ "$(uname)" == "Darwin" ]; then
sudo chown -R 33:33 src
sudo chmod -R +a "user:${USER} allow delete,readattr,writeattr,readextattr,writeextattr,readsecurity,writesecurity,chown,list,search,add_file,add_subdirectory,delete_child,file_inherit,directory_inherit" src
else
sudo chown 33:33 -R src
sudo setfacl -R -m "u:33:rwX,u:${USER}:rwX" src
sudo setfacl -dR -m "u:33:rwX,u:${USER}:rwX" src
_setup-selinux
fi
}
_start-containers() {
set -x
docker-compose up -d
}
_setup-database() {
set -x
database="$(docker-compose exec mariadb mysql -uroot -padmin -e "select schema_name from information_schema.schemata where schema_name = 'dexonline'" --silent --silent)"
if [[ -z "${database}" ]]; then
docker-compose exec mariadb mysql -uroot -padmin -e "create database dexonline character set utf8mb4"
docker-compose exec mariadb bash -c "pv /root/db/dex-database.sql.gz | zcat | mysql -uroot -padmin dexonline"
fi
}
_setup-application() {
set -x
# First create Config.php from Config.php.sample...
docker-compose exec httpd bash tools/setup.sh
# ... then customize it...
if [ "$(uname)" == "Darwin" ]; then
sed -i "" "s|DATABASE = 'mysql://root@localhost/dexonline'|DATABASE = 'mysql://root:admin@mariadb/dexonline'|" "${DIR_SRC}/Config.php"
sed -i "" "s|URL_PREFIX = '/dexonline/www/'|URL_PREFIX = '/'|" "${DIR_SRC}/Config.php"
else
sed -i "s|DATABASE = 'mysql://root@localhost/dexonline'|DATABASE = 'mysql://root:admin@mariadb/dexonline'|" "${DIR_SRC}/Config.php"
sed -i "s|URL_PREFIX = '/dexonline/www/'|URL_PREFIX = '/'|" "${DIR_SRC}/Config.php"
fi
docker-compose exec httpd bash -c "touch /var/log/dexonline.log"
docker-compose exec httpd bash -c "chmod 666 /var/log/dexonline.log"
# ... and finally run tools/migration.php, which needs a working database
docker-compose exec httpd bash -c "php tools/migration.php"
}
_sleep() {
set -x
echo "Sleeping 10 seconds..."
sleep 10
}
_setup-firewalld() {
set -x
if command -v firewall-cmd;
then
network=$(docker network ls | grep dexonline | awk -F ' ' '{print $1}')
gateway=$(docker network inspect ${network} | grep Gateway | grep -Po "[\d\.]+")
interface=$(ifconfig | awk -v g="${gateway}" -F ' ' '$1=="inet" && $2==g {print old} {old=$1}' | sed 's/:$//')
sudo firewall-cmd --permanent --zone=trusted --add-interface=${interface}
sudo firewall-cmd --reload
fi
}
_all() {
set -x
_clone-src
_download-db
_update-permissions
_start-containers
_sleep
_setup-firewalld
_setup-database
_setup-application
}
_tasks() {
echo "
Available tasks:
- clone-src:
Clones the 'dexonline/dexonline' repo to '${DIR_SRC}' if it doesn't exist already.
- download-db:
Downloads the database from '${URL_DB}' to '${DIR_DB}' if it doesn't exist already.
- update-permissions:
Sets the necessary permissions to the '${DIR_SRC}' directory.
- start-containers:
Starts the Docker containers.
- sleep:
Pauses the execution of the next tasks for 10 seconds. When running the 'all' task, it is used to wait for the containers to finish starting.
- setup-firewalld:
If firewalld is running on your system then it adds docker's network interface to trusted zone.
- setup-database:
Creates the dexonline database and imports the downloaded data into it, if it doesn't exist.
- setup-application:
Prepares the application for running.
Not specifying a task at all, or running the 'all' task, runs all the
available tasks, in the same order as in the list above.
"
}
if [[ $# -eq 0 ]]; then
_all
else
for task in "$@"; do
eval "_${task}"
done
fi