-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·101 lines (81 loc) · 2.76 KB
/
setup.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
#!/bin/bash
# https://github.com/janis-rullis/shell-scripts
# Do a complete docker cleanup if there is only 1 dockerized project. Can be set - `./setup.sh 1`.
ONLY_PROJECT=false
if [[ -n $1 ]]; then
ONLY_PROJECT=true
fi
function init() {
# TODO: Add some notification about causes when executed multiple times.
echo "Define error reporting level, file seperator, and init direcotry."
set -e # set -o xtrace;
# https://unix.stackexchange.com/a/164548 You can preserve newlines in the .env.
IFS=$''
DIR=$PWD
# ROOT_DIR="$(dirname "${DIR}")"
ENV_FILE=".env"
}
function checkRequirements() {
echo "Checking if the '.env' file exists ..."
# #17 https://github.com/janis-rullis/shell-scripts/blob/master/learn-basics/if-conditions.sh#L124
if [[ ! -r $ENV_FILE ]]; then
echo "'.env' file is missing!"
echo -e "* Copy the .env.example to .env.\n* Open .env and fill values in FILL_THIS."
exit
fi
}
function stopDocker() {
echo "Remove any possible past clutter."
sudo rm db/mysql/* -R && touch db/mysql/.gitkeep
echo "Stop any running container from this project"
docker-compose down --remove-orphans
if [[ $ONLY_PROJECT = true ]]; then
echo "Remove any dangling part."
echo y | docker network prune
echo y | docker image prune
echo y | docker volume prune
fi
}
function initDb() {
docker-compose up -d lm1-mysql
}
function readEnvVariables() {
echo "Reading .env variables..."
ENV_VARS=$(cat ${ENV_FILE})
DB_PW=$(echo "${ENV_VARS}" | grep MYSQL_PASSWORD= | cut -d '=' -f2)
# https://superuser.com/questions/1225134/why-does-the-base64-of-a-string-contain-n/1225139
SECRET=$(openssl rand -hex 32 | tr -d "\n")
}
# #5 Dockerize the lm1-symfony5.
function setSymfEnv() {
echo "Setting up the 'lm1-symfony5' container."
echo "Go into 'symfony5' direcotry..."
cd symfony5
echo "Copying '.env.example' to '.env'..."
cp .env.example .env
echo "Fill variables collected from the master '.env'..."
sed -i -e "s/FILL_DB_PASSWORD/$DB_PW/g" .env
sed -i -e "s/FILL_APP_SECRET/\"${SECRET}\"/g" .env
echo "Setting up the '.env.test'..."
cp .env .env.test
sed -i -e "s/APP_ENV=dev/APP_ENV=test/g" .env.test
sed -i -e "s/lm1?serverVersion/lm1_testing?serverVersion/g" .env.test
echo "Add .env.test specific values ..."
echo -e "\nKERNEL_CLASS='App\Kernel'\nSYMFONY_DEPRECATIONS_HELPER=999999" >>.env.test
cd "${DIR}";
echo "'.env' is ready."
echo "Initialize a clean API container first ..."
docker-compose build --no-cache lm1-symfony5
docker-compose down --remove-orphans
}
init
checkRequirements
initDb
stopDocker
readEnvVariables
setSymfEnv
echo "Setup is completed."
echo "Starting the project.."
echo "If this is the first time then it will download and setup Docker containers."
chmod a+x start.sh
./start.sh