-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwpinstall.sh
executable file
·362 lines (291 loc) · 7.98 KB
/
wpinstall.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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
#!/bin/bash
if [ "$(uname)" != "Linux" ]; then rpath=`readlink "$0"`; else rpath=`readlink -f "$0"`; fi;
abs_path=$(dirname "$rpath")
dir=$1
install_path=$(pwd)/$dir
function echolor () {
red="\033[31m"
green='\033[32m'
yellow='\033[33m'
std="\033[0m"
case $1 in
r)
color=$red
;;
g)
color=$green
;;
y)
color=$yellow
;;
s)
color=$std
;;
esac
echo -e $color$2$std
}
if [ "$dir" == "" ]; then
read -p "Vous n'avez pas indiqué de répertoire d'installation, Wordpress sera installé ici : "$install_path", ok [Y,n] : " yn
if [[ ! $yn =~ ^[Yy]$ ]]
then
echo "Ok, ok... on arrête tout."
exit 1
fi
else
if [ -d $dir ] || [ -f $dir ]; then echo "Ce répertoire existe déjà, on arrête tout."; exit 1; fi
fi
if [ -d $install_path/web ]; then echo "Un projet wordpress est déjà présent, on arrête tout."; exit 1; fi
mkdir -p $install_path;
setfacl=$(which setfacl)
if [ "$?" -eq 0 ];
then
sudo setfacl -dR -m u:`whoami`:rwx .
fi
sudo_opt=""
read -p "Avez-vous besoin de sudo pour les commandes docker ? [Y,n] : " yn
if [[ $yn =~ ^[Yy]$ ]]
then
sudo_opt="sudo"
fi
cd $install_path;
###########################
# INSTALL
###########################
function gitignore () {
echolor y "Mise en place du gitignore dans "$install_path
cat << EOF > $install_path"/.gitignore"
# marmite
/.marmite
# OS or Editor folders
._*
.cache
.DS_Store
.idea
Thumbs.db
.tmp
nbproject
# Node
node_modules
npm-*.log
*.log
web/app/advanced-cache.php
web/app/backup-db/
web/app/backups/
web/app/blogs.dir/
web/app/cache/
web/app/upgrade/
web/app/uploads/
web/app/plugins/*
!web/app/plugins/advanced-custom-fields-pro
!web/app/plugins/sitepress-multilingual-cms
!web/app/plugins/wpml-string-translation
!web/app/plugins/wpml-translation-management
web/app/themes/acti-starter-theme
web/wp/
# Composer
/vendor/
EOF
}
function conffiles () {
echolor y "Mise en place des fichiers de configutations \"-at-preprod\" et \"-at-prod\" dans "$install_path
cp $install_path"/.env.example" $install_path"/.env-at-preprod"
cp $install_path"/.env.example" $install_path"/.env-at-prod"
}
echolor y "Installation de Wordpress dans "$install_path
composer create-project roots/bedrock $install_path/tmpinstall
cd $install_path/tmpinstall
mv .[!.]* ../
mv * ../
cd ../
rm -rf $install_path/tmpinstall
# Require plugins
composer require acti/acti-starter-theme:dev-master
composer require timber/timber
composer require tedivm/stash
composer require wpackagist-plugin/cookie-law-info
composer require wpackagist-plugin/kint-debugger
composer require wpackagist-plugin/autodescription
composer require wpackagist-plugin/breadcrumb-navxt
gitignore
conffiles
function childtheme ( ){
childpath=$install_path/web/app/themes/$dir
nicethemename="${dir//_/ }"
nicethemename="${nicethemename^}"
echolor y "Clone du thème enfant dans "$childpath
# Clone the child theme from github
git clone https://github.com/c2is/acti-starter-theme-child.git clonetmp
cd clonetmp
# Creation of the child theme directory
mkdir $childpath
# Move child theme folders and files from tmp to final directory
mv * $childpath
# Remove clonetmp
cd ../
rm -rf clonetmp
cd $childpath
# Generation of style.css's informations
printf "/**
* $nicethemename
* Theme Name: $nicethemename
* Author: Acti
* Description: $nicethemename theme.
* Template: acti-starter-theme
*/" > style.css
cd $install_path
}
childtheme
function dockerize () {
netstat=$(netstat)
if [ "$?" -ne 0 ];
then
echolor y "netstat n'est pas installé sur votre machine, il est vivement conseillé de l'installer";
fi
port="[0-9]"
if [ -f docker-compose.yml ]; then
read -p "Le fichier docker-compose.yml existe déjà, on l'écrase ? [y,N] " resp
if [ $resp != "y" ]; then echo "Ok..."; return 0; fi
echo "Arrêts des containers de cet environnement..."
$sudo_opt docker-compose stop
fi
docker_compose_write
ports_wanted=$(grep -A3 "ports" docker-compose.yml | grep "[0-9]" | cut -c12-25 | sed 's/"//' | cut -d':' -f1)
for port in $ports_wanted; do
if [ "$(is_used $port)" == "y" ]; then
if [ "$port" == "80" ] || [ "$port" == "443" ]; then
read -p "Voulez-vous stopper les containers des autres projets tournant sur le port 80 ? [y,N] " resp
if [ $resp == "y" ]; then docker stop $(docker ps |grep ":80->" | cut -d " " -f1); fi
fi
fi
if [ "$(is_used $port)" == "y" ]; then
newport=$(get_next_free_port $port)
echo $port" est occupé, on le remplace par : "$newport
perl -pi -e "s/\"$port:/\"$newport:/" docker-compose.yml
fi
done
read -p "Domaine pour le vhost (s'il se finit par dev.acti vous aurez un certificat ssl valide) : "$'\n' domain
perl -pi -e "s/- WEBSITE_HOST=unprojet.dev.acti/- WEBSITE_HOST=$domain/" docker-compose.yml
perl -pi -e "s/- CERTIFICAT_CNAME=unprojet.dev.acti/- CERTIFICAT_CNAME=$domain/" docker-compose.yml
perl -pi -e "s/- maildomain=unprojet.dev.acti/- maildomain=$domain/" docker-compose.yml
read -p "Voulez-vous ajouter la ligne \"127.0.0.1 $domain\" à votre fichier hosts ? [y,N] " resp
if [ $resp != "y" ]; then
echo "Ok, ok, on touche pas au fichier hosts...";
else
host_file="/etc/hosts"
(sudo echo "127.0.0.1 $domain" && sudo cat $host_file) > temp && sudo mv temp $host_file
fi
echo '""""""""""""""""'
echo -e "Démarrage des containers...\n"
$sudo_opt docker-compose up -d
if [ "$?" -ne 0 ]; then return 0; fi
if [ -d ./web/app/uploads];
then
docker-compose exec php chown -R www-data /var/www/website/web/app/uploads
fi
mysql_container=`basename $(pwd) | sed "s/_//g"`
echo '""""""""""""""""'
echolor g "Maintenant vous pouvez importer un dump mysql, par exemple :"
echo ""
echolor g "docker exec -i "$mysql_container"_db_1 mysql website < ./dump.sql"
}
function is_used() {
if [ "$(uname)" == "Darwin" ]; then
port_used=`$sudo_opt netstat -anv | awk 'NR>2{print $4}' | grep -E '\.'$port | sed 's/.*\.//' | sort -n | uniq`
else
port_used=`$sudo_opt netstat -lnt | awk 'NR>2{print $4}' | grep -E '0.0.0.0:$port' | sed 's/.*://' | sort -n | uniq`
fi
port=$1
res="n"
for i in ${port_used[@]}
do
if [ "$i" == ${port} ]; then
res="y"; break;
fi
done
echo $res
}
function get_next_free_port() {
port=$1
#si le dernier chiffre est 0, on le retire
if [ "${port:(${#port}-1):1}" == "0" ]; then
port=$(echo $port | sed 's/.$//')
fi
limit="10000"
counter=1
while [ $counter -lt $limit ]; do
newport=$port"$counter"
if [ "$(is_used $newport)" == "n" ]; then
break;
fi
let counter=counter+1
done
echo $newport
}
function docker_compose_write () {
cat << EOF > $install_path/docker-compose.yml
application:
image: debian:stretch
volumes:
- ./:/var/www/website
tty: true
db:
image: mysql
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: website
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
php:
image: c2is/ubuntu-php
volumes_from:
- application
links:
- db
- mail
composer:
image: composer
volumes_from:
- application
links:
- db
apache:
image: c2is/debian-apache
environment:
- WEBSITE_HOST=unprojet.dev.acti
- CERTIFICAT_CNAME=unprojet.dev.acti
- VHOST_SUFFIX=web
ports:
- "80:80"
- "443:443"
links:
- php
volumes_from:
- application
wp-cli:
image: tatemz/wp-cli
volumes_from:
- application
links:
- db
entrypoint: wp
command: "--info"
mail:
image: catatnight/postfix
environment:
- maildomain=unprojet.dev.acti
- smtp_user=web:web
ports:
- "25"
EOF
}
dockerhere=$(docker)
if [ "$?" -ne 0 ];
then
echolor y "Docker n'est pas installé sur votre machine : ce script ne mettera pas en place l'environnement docker.";
else
echolor y "Docker est installé, mise en place de l'environnement docker du projet";
dockerize
fi
: <<'COMMENT'
TODO
COMMENT