-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.sh
executable file
·163 lines (128 loc) · 4.16 KB
/
start.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
153
154
155
156
157
158
159
160
161
162
163
#!/bin/bash
. xdocker/utils.sh
cat <<EOF
${green}${bold}
____ _
__ _| _ \ ___ ___| | _____ _ __
\ \/ / | | |/ _ \ / __| |/ / _ \ '__|
> <| |_| | (_) | (__| < __/ |
/_/\_\____/ \___/ \___|_|\_\___|_|
${normal}
EOF
if ! (( $(program_is_installed gem) )); then
echo "${red}Please before install ${fawn}\"gem\"${normal}"
exit 0
fi
if ! (( $(program_is_installed docker-sync) )); then
echo "${red}Please before run command: ${fawn}\"sudo gem install docker-sync\"${normal}"
exit 0
fi
function update_database_parameters {
DATABASE_URL="mysql:\/\/$DATABASE_USER:$DATABASE_PASSWORD@$DATABASE_HOST:$DATABASE_PORT\/$DATABASE_NAME"
sed -i.bak 's/^DATABASE_HOST.*/DATABASE_HOST='${DATABASE_HOST}'/g' .env
sed -i.bak 's/^DATABASE_NAME.*/DATABASE_NAME='${DATABASE_NAME}'/g' .env
sed -i.bak 's/^DATABASE_USER.*/DATABASE_USER='${DATABASE_USER}'/g' .env
sed -i.bak 's/^DATABASE_PASSWORD.*/DATABASE_PASSWORD='${DATABASE_PASSWORD}'/g' .env
sed -i.bak 's/^DATABASE_PORT.*/DATABASE_PORT='${DATABASE_PORT}'/g' .env
sed -i bak 's/^DATABASE_URL.*/DATABASE_URL="'${DATABASE_URL}'"/g' .env
rm -f .*bak
}
function update_env_file {
if [ ! -f ".env" ]; then
cat ./.env.dist >> ./.env
fi
if cat .env | grep -iq "^NAME"; then
sed -i.bak 's/^NAME.*/NAME='${NAME}'/g' .env
else
echo -e "\n###< xDocker ###\nNAME=$NAME" >> .env
fi
if cat .env | grep -iq "^HOST"; then
sed -i.bak 's/^HOST.*/HOST='${HOST}'/g' .env
else
echo "HOST=$HOST" >> .env
fi
if cat .env | grep -iq "^DEFAULT_DOCKER_PORT"; then
sed -i.bak 's/^DEFAULT_DOCKER_PORT.*/DEFAULT_DOCKER_PORT='${DEFAULT_PORT}':80/g' .env
else
echo -e "DEFAULT_DOCKER_PORT=$DEFAULT_PORT:80\n###< xDocker ###" >> .env
fi
$(update_database_parameters)
}
NAME=$(basename "$PWD")
DEFAULT_PORT=$(getport 9090)
HOST="$NAME.local"
DATABASE_HOST="mysql"
DATABASE_NAME="$NAME"
DATABASE_USER="$NAME"
DATABASE_PASSWORD="$NAME"
DATABASE_PORT="3306"
$(update_env_file)
if [ "$1" = "--dpu" ]; then
echo "Default database host: ${cyan}${DATABASE_HOST}${fawn}"
read USER_DATABASE_HOST
if [[ ${USER_DATABASE_HOST} ]]; then
DATABASE_HOST=${USER_DATABASE_HOST}
else
echo "${DATABASE_HOST}"
fi
echo "${normal}Default database name: ${cyan}${DATABASE_NAME}${fawn}"
read USER_DATABASE_NAME
if [[ ${USER_DATABASE_NAME} ]]; then
DATABASE_NAME=${USER_DATABASE_NAME}
else
echo "${DATABASE_NAME}"
fi
echo "${normal}Default database user: ${cyan}${DATABASE_USER}${fawn}"
read USER_DATABASE_USER
if [[ ${USER_DATABASE_USER} ]]; then
DATABASE_USER=${USER_DATABASE_USER}
else
echo "${DATABASE_USER}"
fi
echo "${normal}Default database password: ${cyan}${DATABASE_PASSWORD}${fawn}"
read USER_DATABASE_PASSWORD
if [[ ${USER_DATABASE_PASSWORD} ]]; then
DATABASE_PASSWORD=${USER_DATABASE_PASSWORD}
else
echo "${DATABASE_PASSWORD}"
fi
echo "${normal}"
$(update_database_parameters)
fi
echo "NGINX Proxy starting."
docker-compose -f docker-compose-proxy.yml -p proxy up -d
echo "NGINX Proxy started."
printf "\n"
echo "Preparing app..."
docker_sync_volume_create
docker-compose up -d
docker-sync start
echo "Project ready..."
printf "\n"
HAS_VENDOR=0
[[ -d "./vendor" ]] && HAS_VENDOR=1
MESSAGE="After composer installation is finished, you can run the project from ${bold}$HOST${normal}"
if [[ $HAS_VENDOR -eq 1 ]]; then
MESSAGE="You can run the project from ${bold}$HOST${normal}"
fi
cat <<EOF
${green}============ Project Ready ===========
--- ENV Variables ---
NAME=${NAME}
HOST=${HOST}
DEFAULT_DOCKER_PORT=${DEFAULT_PORT}
DATABASE_HOST=${DATABASE_HOST}
DATABASE_NAME=${DATABASE_NAME}
DATABASE_USER=${DATABASE_USER}
DATABASE_PASSWORD=${DATABASE_PASSWORD}
DATABASE_PORT=${DATABASE_PORT}
DATABASE_URL="mysql://$DATABASE_USER:$DATABASE_PASSWORD@$DATABASE_HOST:$DATABASE_PORT/$DATABASE_NAME"
--- ENV Variables ---
$(host_update ${HOST})
${MESSAGE}
${fawn}Good coding, good luck!${normal}
${green}============ Project Ready ===========${normal}
EOF
if [[ $HAS_VENDOR -eq 0 ]]; then
run_composer_run
fi