-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path02-deploy.sh
236 lines (203 loc) · 11.9 KB
/
02-deploy.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#!/bin/bash
BLACK=$(tput setaf 0)
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
YELLOW=$(tput setaf 3)
LIME_YELLOW=$(tput setaf 190)
POWDER_BLUE=$(tput setaf 153)
BLUE=$(tput setaf 4)
MAGENTA=$(tput setaf 5)
CYAN=$(tput setaf 6)
WHITE=$(tput setaf 7)
BRIGHT=$(tput bold)
NORMAL=$(tput sgr0)
BLINK=$(tput blink)
REVERSE=$(tput smso)
UNDERLINE=$(tput smul)
FOLDER_WORK=$(pwd)
FOLDER_OPT="/opt"
uDocker=$1
echo ""
echo " ======================================================================"
echo -e " ====== \e[1;91mMTIE MIGUEL MARTINEZ${NORMAL} ======"
echo -e " == =="
echo -e " == \e[39m ░░ ░░ ${NORMAL} =="
echo -e " == \e[39m ░░ ░░ ░░ ${NORMAL} =="
echo -e " == \e[39m ░░ ${NORMAL} =="
echo -e " == =="
echo -e " == \e[96m ██████████████ ${NORMAL} =="
echo -e " == \e[96m ██░░░░░░░░░░░░░░████ ${NORMAL} =="
echo -e " == \e[96m ██░░░░░░░░░░░░░░░░░░░░██ ${NORMAL} =="
echo -e " == \e[96m ██░░░░░░░░░░░░░░░░░░░░░░██ ██ ██ ${NORMAL} =="
echo -e " == \e[96m ██░░░░░░░░░░░░░░░░░░░░░░██ ██░░██░░██ ${NORMAL} =="
echo -e " == \e[96m ██░░░░░░ ██░░░░░░░░░░░░██ ██░░░░░░██ ${NORMAL} =="
echo -e " == \e[96m ██░░░░░░████░░░░░░░░░░░░██ ██░░░░░░██ ${NORMAL} =="
echo -e " == \e[96m ██░░░░░░░░░░░░░░░░░░░░░░░░██ ██░░██ ${NORMAL} =="
echo -e " == \e[96m ██ ░░░░░░░░░░░░░░░░████░░░░██ ${NORMAL} =="
echo -e " == \e[96m ██ ██░░░░ ░░░░░░░░░░██ ${NORMAL} =="
echo -e " == \e[96m ████████████░░████████████████ ${NORMAL} =="
echo -e " == \e[96m ████ ████ ${NORMAL} =="
echo -e " == =="
echo -e " == ███╗ ███╗███╗ ███╗███╗ ███╗██╗ ██╗ =="
echo -e " == ████╗ ████║████╗ ████║████╗ ████║██║ ██║ =="
echo -e " == ██╔████╔██║██╔████╔██║██╔████╔██║██║ ██║ =="
echo -e " == ██║╚██╔╝██║██║╚██╔╝██║██║╚██╔╝██║╚██╗ ██╔╝ =="
echo -e " == ██║ ╚═╝ ██║██║ ╚═╝ ██║██║ ╚═╝ ██║ ╚████╔╝ =="
echo -e " == ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═══╝ =="
echo -e " == =="
echo -e " ====== \e[1;91mTRAEFIK AND PORTAINER DEPLOYMENT${NORMAL} ======"
echo -e " ======================================================================"
echo ""
echo ""
echo -e "${YELLOW}-> Do you want to initialize the project deployment? [Y/n]:? ${NORMAL}\c "
read condicion
echo ""
while [ $condicion != "Y" ] && [ $condicion != "n" ]; do
echo -e "${RED}-> ERROR: Not a valid option${NORMAL}" >&2;
echo ""
echo -e "${YELLOW}-> Do you want to initialize the project deployment? [Y/n]:? ${NORMAL}\c"
read condicion
done
if [ $condicion == "n" ]; then
echo ""
echo " ========================================================================="
echo -e " ${YELLOW}Thanks, come back soon!${NORMAL} "
echo -e " \e[91mMTIE MIGUEL MARTINEZ${NORMAL} "
echo " ========================================================================="
exit 1
fi
echo ""
echo -e "${YELLOW}-> Want to move the core folder to ${FOLDER_OPT} ? [Y/n]:? ${NORMAL}\c "
read mv_core
echo ""
while [ $mv_core != "Y" ] && [ $mv_core != "n" ]; do
echo -e "${RED}-> ERROR: Not a valid option${NORMAL}" >&2;
echo ""
echo -e "${YELLOW}-> Want to move the core folder to ${FOLDER_OPT} ? [Y/n]:? ${NORMAL}\c"
read mv_core
done
if [ $mv_core == "Y" ]; then
FOLDER_WORK=$FOLDER_OPT
echo -e " ${GREEN}Moving core folder to ${FOLDER_WORK}!${NORMAL} "
mv core /opt
fi
echo ""
echo " ========================================================================="
echo -e " ${RED}Traefik${NORMAL} "
echo -e " ${YELLOW}Mail configuration for SSL${NORMAL} "
echo ""
echo -e "${YELLOW}-> Please enter a valid email address? [tucorreo@mail.com]: ${NORMAL}\c "
read eTraefik
regex='^(([A-Za-z0-9]+((\.|\-|\_|\+)?[A-Za-z0-9]?)*[A-Za-z0-9]+)|[A-Za-z0-9]+)@(([A-Za-z0-9]+)+((\.|\-|\_)?([A-Za-z0-9]+)+)*)+\.([A-Za-z]{2,})+$'
while [[ ! ("${eTraefik}" =~ $regex) ]]; do
echo -e "${RED}-> ERROR: It is not a valid email address${NORMAL}" >&2;
echo ""
echo -e "${YELLOW}-> Please enter a valid email address? [tucorreo@mail.com]: ${NORMAL}\c"
read eTraefik
done
echo ""
echo -e " ${GREEN}Saving mail in:${NORMAL} "
echo -e " \e[91m$FOLDER_WORK/traefik-data/traefik.yml${NORMAL} "
sed -i 's/USER_EMAIL_LETSENCRYPT/'$eTraefik'/g' $FOLDER_WORK/core/traefik-data/traefik.yml
echo ""
echo " ========================================================================="
echo -e " ${GREEN}Installing apache2-utils${NORMAL} "
apt install -y apache2-utils
echo ""
echo " ========================================================================="
echo -e " ${RED}Traefik${NORMAL} "
echo -e " ${YELLOW}Username and Password Generation${NORMAL} "
echo ""
echo -e "${YELLOW}-> Enter the username for Traefik: ${NORMAL}\c "
read uTraefix
echo ""
echo -e "${YELLOW}-> Enter the password for the Traefik user: ${NORMAL}\c "
read -s pTraefix
gPassword=$(htpasswd -nb $uTraefix $pTraefix)
echo $gPassword
sed -i 's/USER_BASIC_AUTH/'${gPassword}'/g' $FOLDER_WORK/core/traefik-data/configurations/dynamic.yml
echo ""
echo " ========================================================================="
echo -e " ${RED}Traefik${NORMAL} "
echo -e " ${YELLOW}Assignment of permissions 600 to the file${NORMAL} "
echo -e " ${GREEN}${FOLDER_WORK}/core/traefik-data/acme.json${NORMAL} "
echo " ========================================================================="
chmod 600 $FOLDER_WORK/core/traefik-data/acme.json
echo ""
echo " ========================================================================="
echo -e " ${CYAN}Docker${NORMAL} "
echo -e " ${YELLOW}Assigning user and permissions to the project folder${NORMAL} "
echo -e " ${GREEN}${FOLDER_WORK}/core${NORMAL} "
echo " ========================================================================="
if [ -z "$uDocker" ]
then
echo ""
echo -e "${GREEN}-> Enter the username to manage docker: ${NORMAL}\c "
read uDocker
fi
chown -R $uDocker:$uDocker $FOLDER_WORK/core
echo ""
echo " ======================================================================"
echo -e " ====== ${GREEN}Congratulations!!!${NORMAL} ======"
echo -e " ====== ${YELLOW}All folders and configurations${NORMAL} ======"
echo -e " ====== ${YELLOW}are already made!${NORMAL} ======"
echo -e " ====== \e[91mMTIE MIGUEL MARTINEZ${NORMAL} ======"
echo " ======================================================================"
echo ""
echo -e "${YELLOW}-> You want to run docker compose ? [Y/n]:? ${NORMAL}\c "
read compose
echo ""
while [ $compose != "Y" ] && [ $compose != "n" ]; do
echo -e "${RED}-> ERROR: Not a valid option${NORMAL}" >&2;
echo ""
echo -e "${YELLOW}-> You want to run docker compose ? [Y/n]:? ${NORMAL}\c"
read compose
done
if [ $compose == "n" ]; then
echo -e " ======================================================================"
echo -e " ${GREEN}Thank you!!!${NORMAL}"
echo -e " ${CYAN}Now you can manually run the file${NORMAL}"
echo -e " "
echo -e " ${YELLOW}- docker-compose.yml${NORMAL}"
echo -e " "
echo -e " ${CYAN}located in the${NORMAL}"
echo -e " "
echo -e " ${YELLOW}- ${FOLDER_WORK}/core${NORMAL}"
echo -e " "
echo -e " ${CYAN}folder with the following command inside the core folder${NORMAL}"
echo -e " "
echo -e " ${YELLOW}> docker compose up -d${NORMAL}"
echo -e " "
echo -e " ${CYAN}if you want to run docker compose from this location run the following${NORMAL}"
echo -e " "
echo -e " ${YELLOW}> docker compose -f ${FOLDER_WORK}/core/docker-compose.yml up -d${NORMAL}"
echo " ======================================================================"
exit 1
fi
echo ""
echo -e "${YELLOW}-> Enter the domain or subdomain name for Traefik [mydomain.com or subdomain.mydomain.com]:? ${NORMAL}\c "
read domainTraefik
sed -i 's/DOMAIN_TRAEFIK/'${domainTraefik}'/g' $FOLDER_WORK/core/docker-compose.yml
echo ""
echo -e "${YELLOW}-> Enter the domain or subdomain name for Portainer [mydomain.com or subdomain.mydomain.com]:? ${NORMAL}\c "
read domainPortainer
sed -i 's/DOMAIN_PORTAINER/'${domainPortainer}'/g' $FOLDER_WORK/core/docker-compose.yml
echo ""
echo -e " ======================================================================"
echo -e " ${GREEN}Running: docker compose -f ${FOLDER_WORK}/core/docker-compose.yml up -d${NORMAL} "
docker compose -f ${FOLDER_WORK}/core/docker-compose.yml up -d
echo -e " ======================================================================"
echo -e " ====== ${GREEN}CONGRATULATIONS!!!${NORMAL} ======"
echo -e " ====== ${CYAN}You have successfully installed the project${NORMAL} ======"
echo -e " ====== ======"
echo -e " ====== ${YELLOW}MTIE MIGUEL MARTINEZ${NORMAL} ======"
echo -e " ====== ${CYAN}WebSite - mmartinezdev.com${NORMAL} ======"
echo -e " ====== ${RED}YouTube - ElTresM${NORMAL} ======"
echo -e " ======================================================================"
echo -e " "
echo -e " ======================================================================"
echo -e " ====== ${GREEN}Login con el usuario ${uDocker}!!!${NORMAL} ======"
echo -e " ======================================================================"
echo -e " "
login $uDocker
# docker compose ps