-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
275 lines (244 loc) · 9.32 KB
/
install.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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#!/bin/bash
clear
echo ""
echo "====================================================================="
echo "| |"
echo "| full-stack-proxy-nginx-yii-for-everyone-with-docker-compose |"
echo "| by Erdal ALTIN |"
echo "| |"
echo "====================================================================="
sleep 2
# Uninstall old versions
echo "Older versions of Docker were called docker, docker.io, or docker-engine. If these are installed, uninstall them"
sudo apt-get remove docker docker-engine docker.io containerd runc
echo ""
echo "Done ✓"
echo "============================================"
# install start
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg lsb-release
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(grep -Po 'UBUNTU_CODENAME=\K[^;]*' /etc/os-release) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
Installed=`sudo apt-cache policy docker-ce | sed -n '2p' | cut -c 14-`
Candidate=`sudo apt-cache policy docker-ce | sed -n '3p' | cut -c 14-`
if [[ "$Installed" != "$Candidate" ]]; then
sudo apt-get install docker-ce docker-ce-cli containerd.io
elif [[ "$Installed" == "$Candidate" ]]; then
echo ""
echo 'docker currently version already installed.'
fi
echo ""
echo "Done ✓"
echo "============================================"
##########
# Run Docker without sudo rights
##########
echo ""
echo ""
echo "============================================"
echo "| Running Docker without sudo rights..."
echo "============================================"
echo ""
sleep 2
sudo groupadd docker
sudo usermod -aG docker ${USER}
# su - ${USER} &
echo ""
echo "Done ✓"
echo "============================================"
##########
# Install Docker Compose
##########
echo ""
echo ""
echo "============================================"
echo "| Installing Docker Compose v2.12.2..."
echo "============================================"
echo ""
sleep 2
sudo mkdir -p /usr/local/lib/docker/cli-plugins
sudo curl -SL "https://github.com/docker/compose/releases/download/v2.12.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/lib/docker/cli-plugins/docker-compose
sudo chmod +x /usr/local/lib/docker/cli-plugins/docker-compose
# permission for Docker daemon socket
sudo chmod 666 /var/run/docker.sock
echo ""
echo "Done ✓"
echo "============================================"
##########
# Setup project variables
##########
echo ""
echo ""
echo "============================================"
echo "| Please enter project related variables..."
echo "============================================"
echo ""
sleep 2
# set your domain name
domain_name=""
read -p 'Enter Domain Name(e.g. : example.com): ' domain_name
[ -z $domain_name ] && domain_name="NULL"
host -N 0 $domain_name 2>&1 > /dev/null
while [ $? -ne 0 ]
do
echo "Try again"
read -p 'Enter Domain Name(e.g. : example.com): ' domain_name
[ -z $domain_name ] && domain_name="NULL"
host -N 0 $domain_name 2>&1 > /dev/null
done
echo "Ok."
# set parameters in env.example file
email=""
regex="^[a-zA-Z0-9\._-]+\@[a-zA-Z0-9._-]+\.[a-zA-Z]+\$"
read -p 'Enter Email Address for letsencrypt ssl(e.g. : [email protected]): ' email
while [ -z $email ] || [[ ! $email =~ $regex ]]
do
echo "Try again"
read -p 'Enter Email Address for letsencrypt ssl(e.g. : [email protected]): ' email
sleep 1
done
echo "Ok."
db_username=""
db_regex="^[0-9a-zA-Z\$_]{6,}$"
read -p 'Enter Database Username(at least 6 characters): ' db_username
while [[ ! $db_username =~ $db_regex ]]
do
echo "Try again (can only contain numerals 0-9, basic Latin letters, both lowercase and uppercase, dollar sign and underscore)"
read -p 'Enter Database Username(at least 6 characters): ' db_username
sleep 1
done
echo "Ok."
db_password=""
password_regex="^[a-zA-Z0-9\._-]{6,}$"
read -p 'Enter Database Password(at least 6 characters): ' db_password
while [[ ! $db_password =~ $password_regex ]]
do
echo "Try again (can only contain numerals 0-9, basic Latin letters, both lowercase and uppercase, dot, underscore and minus sign)"
read -p 'Enter Database Password(at least 6 characters): ' db_password
sleep 1
done
echo "Ok."
db_name=""
read -p 'Enter Database Name(at least 6 characters): ' db_name
while [[ ! $db_name =~ $db_regex ]]
do
echo "Try again (can only contain numerals 0-9, basic Latin letters, both lowercase and uppercase, dollar sign and underscore)"
read -p 'Enter Database Name(at least 6 characters): ' db_name
sleep 1
done
echo "Ok."
mysql_root_password=""
read -p 'Enter MariaDb/Mysql Root Password(at least 6 characters): ' mysql_root_password
while [[ ! $mysql_root_password =~ $password_regex ]]
do
echo "Try again (can only contain numerals 0-9, basic Latin letters, both lowercase and uppercase, dot, underscore and minus sign)"
read -p 'Enter MariaDb/Mysql Root Password(at least 6 characters): ' mysql_root_password
sleep 1
done
echo "Ok."
pma_username=""
read -p 'Enter PhpMyAdmin Username(at least 6 characters): ' pma_username
while [[ ! $pma_username =~ $db_regex ]]
do
echo "Try again (can only contain numerals 0-9, basic Latin letters, both lowercase and uppercase, dollar sign and underscore)"
read -p 'Enter PhpMyAdmin Username(at least 6 characters): ' pma_username
sleep 1
done
echo "Ok."
pma_password=""
read -p 'Enter PhpMyAdmin Password(at least 6 characters): ' pma_password
while [[ ! $pma_password =~ $password_regex ]]
do
echo "Try again (can only contain numerals 0-9, basic Latin letters, both lowercase and uppercase, dot, underscore and minus sign)"
read -p 'Enter PhpMyAdmin Password(at least 6 characters): ' pma_password
sleep 1
done
echo "Ok."
local_timezone_regex="^[a-zA-Z0-9/+-_]{1,}$"
read -p 'Enter container local Timezone(default : America/Los_Angeles, to see the other timezones, https://docs.diladele.com/docker/timezones.html): ' local_timezone
: ${local_timezone:=America/Los_Angeles}
while [[ ! $local_timezone =~ $local_timezone_regex ]]
do
echo "Try again (can only contain numerals 0-9, basic Latin letters, both lowercase and uppercase, positive, minus sign and underscore)"
read -p 'Enter container local Timezone(default : America/Los_Angeles, to see the other local timezones, https://docs.diladele.com/docker/timezones.html): ' local_timezone
sleep 1
: ${local_timezone:=America/Los_Angeles}
done
local_timezone=${local_timezone//[\/]/\\\/}
echo "Ok."
read -p "Apply changes (y/n)? " choice
case "$choice" in
y|Y ) echo "Yes! Proceeding now...";;
n|N ) echo "No! Aborting now..."; exit 0;;
* ) echo "Invalid input! Aborting now..."; exit 0;;
esac
cp ./phpmyadmin/apache2/sites-available/default-ssl.sample.conf ./phpmyadmin/apache2/sites-available/default-ssl.conf
sed -i 's/example.com/'$domain_name'/g' ./phpmyadmin/apache2/sites-available/default-ssl.conf
cp env.example .env
sed -i 's/example.com/'$domain_name'/' .env
sed -i 's/[email protected]/'$email'/' .env
sed -i 's/db_username/'$db_username'/g' .env
sed -i 's/db_password/'$db_password'/g' .env
sed -i 's/db_name/'$db_name'/' .env
sed -i 's/mysql_root_password/'$mysql_root_password'/' .env
sed -i 's/pma_username/'$pma_username'/' .env
sed -i 's/pma_password/'$pma_password'/' .env
sed -i "s@directory_path@$(pwd)@" .env
sed -i 's/local_timezone/'$local_timezone'/' .env
if [ -x "$(command -v docker)" ] && [ "$(docker compose version)" ]; then
# Firstly: create external volume
docker volume create --driver local --opt type=none --opt device=`pwd`/certbot --opt o=bind certbot-etc > /dev/null
# installing Yii and the other services
docker compose up -d & export pid=$!
echo "Yii and the other services installing proceeding..."
echo ""
wait $pid
if [ $? -eq 0 ]
then
# installing portainer
docker compose -f portainer-docker-compose.yml -p portainer up -d & export pid=$!
echo ""
echo "portainer installing proceeding..."
wait $pid
if [ $? -ne 0 ]; then
echo "Error! could not installed portainer" >&2
exit 1
else
echo ""
until [ -n "$(sudo find ./certbot/live -name '$domain_name' 2>/dev/null | head -1)" ]; do
echo "waiting for Let's Encrypt certificates for $domain_name"
sleep 5s & wait ${!}
if sudo [ -d "./certbot/live/$domain_name" ]; then break; fi
done
echo "Ok."
#until [ ! -z `docker compose ps -a --filter "status=running" --services | grep proxy` ]; do
# echo "waiting starting proxy container"
# sleep 2s & wait ${!}
# if [ ! -z `docker compose ps -a --filter "status=running" --services | grep proxy` ]; then break; fi
#done
echo ""
echo "Reloading proxy ssl configuration"
docker container restart proxy > /dev/null 2>&1
echo "Ok."
echo ""
echo "completed setup"
echo ""
echo "Website: https://$domain_name"
echo "Requirements: https://$domain_name/requirements.php"
echo "Portainer: https://$domain_name:9001"
echo "phpMyAdmin: https://$domain_name:9090"
echo ""
echo "Ok."
fi
else
echo ""
echo "Error! could not installed Yii and the other services with docker compose" >&2
exit 1
fi
else
echo ""
echo "not found docker and/or docker compose, Install docker and/or docker compose" >&2
exit 1
fi