-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
316 lines (269 loc) · 10.1 KB
/
Makefile
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
#--------------------------------------------------------------------------------------------------
# BUT :
# - Permet de mettre à jour un wordpress distant.
# - Exemple ci-dessous sur un serveur 1and1 mutualisé.
#
# NOTES :
# - Il faut obligatoirement des TAB pour l'indentation des lignes.
# - A executer sur votre machine local.
# - Commande (taper votre mot de passe SSH + valider ou utiliser /.ssh/authorized_keys sur votre serveur) :
# - make help
# - make dev
# - make import
# - etc ...
# Ou avec variable :
# - make import mavariable=value
# - etc ...
# - Lors de la 1er utilisation vous devez :
# - Creer manuellement une db local (puis un : make dbimport, pour importer la db distante)
# - Telecharger wp-config.php du serveur distant. L'adapter avec votre db local :
# - DB_NAME: ma_new_db
# - DB_USER: root
# - DB_PASSWORD: root
# - DB_HOST: 127.0.0.1:3306
#
# IMPORTANT : Si vous utilisez un vhost
# - Edit .htaccess local
# - Changer "RewriteBase /" par "RewriteBase /votre_dossier_dans_htdocs/"
# - Ex : "RewriteBase /mon_site/" (avec mon_site qui est le dossier sur lequel pointe votre vhost)
#
# DOCUMENTATION :
# - https://makefiletutorial.com
#--------------------------------------------------------------------------------------------------
# ENV: dev, prod
ENV=dev
ssh=u12345678@home123456789.1and1-data.host
error_custom=---- ENV:$(ENV) ----
VERSION_MAKEFILE=1.1
# Seulement utilise pour une nouvelle installation de WP (en local)
admin_email_local=wp_test_makefile@tld.com
admin_user_local=admin
admin_password_local=admin
dbhost_local=127.0.0.1:3306
dbname_local=wp_test_$(shell date +%Y-%m-%d_%H-%M-%S)
dbuser_local=root
dbpass_local=root
dbprefix_local=wTESTp_
ifeq ($(ENV), dev)
# Utilise pour replace en db (sans le protocole "http(s)://"):
domain_distant=dev.monSite.com
domain_local=127.0.0.1:80/test_makefile
path_distant=~/monsite_com_dev/
path_local=./
else ifeq ($(ENV), prod)
# Utilise pour replace en db (sans le protocole "http(s)://"):
domain_distant=www.monSite.com
domain_local=127.0.0.1:80/test_makefile
path_distant=~/monsite_com_prod/
path_local=./
else
error_custom=---- Erreur choix ENV ----
endif
#---------------------------------------------------------------
# COLOR
# ex: @echo "${_BOLD}${_UNDER}${_ICYAN}Hello World${_END}"
#---------------------------------------------------------------
# This is a minimal set of ANSI/VT100 color codes
_END=\x1b[0m
_BOLD=\x1b[1m
_UNDER=\x1b[4m
_REV=\x1b[7m
# Colors
_GREY=\x1b[30m
_RED=\x1b[31m
_GREEN=\x1b[32m
_YELLOW=\x1b[33m
_BLUE=\x1b[34m
_PURPLE=\x1b[35m
_CYAN=\x1b[36m
_WHITE=\x1b[37m
# Inverted, i.e. colored backgrounds
_IGREY=\x1b[40m
_IRED=\x1b[41m
_IGREEN=\x1b[42m
_IYELLOW=\x1b[43m
_IBLUE=\x1b[44m
_IPURPLE=\x1b[45m
_ICYAN=\x1b[46m
_IWHITE=\x1b[47m
#---------------------------------------------------------------
# DETECT OS
#---------------------------------------------------------------
os_custom=""
ifeq ($(OS), Windows_NT)
os_custom=windows
else ifeq ($(OS), Darwin)
os_custom="mac"
else
os_custom=""
endif
#---------------------------------------------------------------
# FONCTION
#---------------------------------------------------------------
# Appeler la fonction : $(call message_primary, "Votre message ici")
# @param $(1) votre message ici
# @return string
define message_primary
@echo -e "\n${_BOLD}${_BLUE}---- $1 ----${_END}"
endef
# Appeler la fonction : @echo $(call test_fonction_custom, lorem, ipsum)
#test_fonction_custom_2 = Variable Name: $(0) ---- First: $(1) ---- Second: $(2) ---- Empty Variable: $(3)
#---------------------------------------------------------------
# SCRIPT CONFIG (ne rien modifier ci-dessous)
#---------------------------------------------------------------
.PHONY: help config debug dev update install_local import dbimport deploy dbdeploy
help: ## Affiche cette aide
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
config: ## Afficher la config actuellement en place
@echo '#####################################################'
@echo '# CONFIG CURRENT (v$(VERSION_MAKEFILE)) :'
@echo '#####################################################'
@echo '# ENV :'
@echo '# - $(ENV)'
@echo '# PATH :'
@echo '# - distant: $(path_distant)'
@echo '# - local: $(path_local)'
@echo '# DOMAIN:'
@echo '# - distant: $(domain_distant)'
@echo '# - local: $(domain_local)'
@echo '#####################################################'
debug: ## debug custom
$(error Debug: $(error_custom))
dev: ## Lance le serveur de développement
php -S localhost:8000 -d display_errors=1
update: ## LOCAL : update core and plugins all
wp core update
wp plugin update --all
test: ## Test : utilisation de fonctions
$(call test_fonction_custom_1, "loremA", "ipsumA")
@echo $(call test_fonction_custom_2, lorem, ipsum)
test_affiche: ## Afficher : info, warning, error
$(info test pour afficher un simple message)
$(warning test pour afficher un warning)
$(error test pour afficher une erreur + exit)
test_color: ## Afficher : texte avec couleur (font or background)
@echo "${_BOLD}${_GREY}Hello World${_END}"
@echo "${_BOLD}${_GREEN}Hello World${_END}"
@echo "${_BOLD}${_RED}Hello World${_END}"
@echo "${_BOLD}${_YELLOW}Hello World${_END}"
@echo "${_BOLD}${_BLUE}Hello World${_END}"
@echo "${_BOLD}${_PURPLE}Hello World${_END}"
@echo "${_BOLD}${_CYAN}Hello World${_END}"
@echo "${_BOLD}${_WHITE}Hello World${_END}"
#---------------------------------------------------------------
# NEW INSTALL WP (en local)
#---------------------------------------------------------------
install_local: ## Installer une nouvelle version de Wordpress (en local)
$(call message_primary, "DOWNLOAD WP")
wp core download --locale=fr_FR --force
$(call message_primary, "VERSION WP")
wp core version
$(call message_primary, "CONFIG DATABASE")
wp core config \
--dbhost=$(dbhost_local) \
--dbname=$(dbname_local) \
--dbuser=$(dbuser_local) \
--dbpass=$(dbpass_local) \
--dbprefix=$(dbprefix_local) \
--locale=fr_FR \
--skip-check
$(call message_primary, "CREATE DB")
wp db create
$(call message_primary, "INSTALL WP")
wp core install \
--url=$(domain_local) \
--title=Test \
--admin_user=$(admin_user_local) \
--admin_password=$(admin_password_local) \
--admin_email=$(admin_email_local) \
--skip-plugins=hello \
--skip-themes=twentyfifteen,twentysixteen,twentyseventeen,twentynineteen,twentytwenty
#$(call message_primary, "INSTALL PLUGINS")
#wp plugin install jetpack --activate
#wp plugin install contact-form-7 --activate
#wp plugin install wordpress-seo --activate
#wp plugin install updraftplus --activate
#wp plugin install backwpup
$(call message_primary, "INSTALL THEME")
#wp theme install astra --activate
wp theme install twentytwenty --activate
$(call message_primary, "PAGES CREATE - accueil / blog / contact / mentions megales")
wp post create --post_type=page --post_title='Accueil' --post_status=publish
wp post create --post_type=page --post_title='Blog' --post_status=publish
wp post create --post_type=page --post_title='Contact' --post_status=publish
wp post create --post_type=page --post_title='Mentions Legales' --post_status=publish
$(call message_primary, "ARTICLES CREATE : FAKER")
curl -N http://loripsum.net/api/5 | wp post generate --post_content --count=5 --post_date='2020-01-15 04:35:45'
$(call message_primary, "CONFIG SET PAGE - selectionner page accueil / article")
wp option update show_on_front page
wp option update page_on_front 4
wp option update page_for_posts 5
$(call message_primary, "CONFIG MENU")
wp menu create "Menu Principal"
wp menu item add-post menu-principal 3
wp menu item add-post menu-principal 4
wp menu item add-post menu-principal 5
wp menu item add-post menu-principal 6
$(call message_primary, "SUPPRIMER : plugin - theme - articles exemples")
wp option update blogdescription ''
wp post delete 1 --force
wp post delete 2 --force
wp theme delete twentynineteen
wp theme delete twentyseventeen
wp plugin delete hello
$(call message_primary, "UTILISER PERMALIENS")
wp option get permalink_structure
wp option update permalink_structure '/%postname%'
wp rewrite flush --hard
$(call message_primary, "CATEG et TAG - update")
wp option update category_base theme
wp option update tag_base sujet
ifeq ($(os_custom), mac)
$(call message_primary, "GIT - init")
git init
git add -A
git commit -m "Initial commit" > /dev/null 2>&1
endif
$(call message_primary, "OPEN PAGES - accueil et admin")
ifeq ($(os_custom), windows)
@echo -e "windows"
start "http://"$(domain_local)
start "http://"$(domain_local)"/wp-admin"
else
@echo -e "mac"
open "http://"$(domain_local)
open "http://"$(domain_local)"/wp-admin"
endif
#---------------------------------------------------------------
# IMPORT (en local)
#---------------------------------------------------------------
import: ## Importe les fichiers distants
rsync -av $(ssh):$(path_distant) $(path_local) \
--exclude wp-config.php # > /dev/null 2>&1
dbimport: ## Recupere db (depuis le serveur)
ssh $(ssh) "cd $(path_distant); wp db export --add-drop-table dump.sql"
rsync -av $(ssh):$(path_distant)dump.sql $(path_local)
ssh $(ssh) "rm $(path_distant)dump.sql"
wp db import dump.sql
wp search-replace '$(domain_distant)' '$(domain_local)' --dry-run
wp search-replace '$(domain_distant)' '$(domain_local)'
rm dump.sql
#---------------------------------------------------------------
# EXPORTER/DEPLOYER (vers serveur distant)
#---------------------------------------------------------------
deploy: ## Deploie new version de l'application
rsync -av $(path_local) $(ssh):$(path_distant) \
--exclude Makefile \
--exclude .git \
--exclude .idea \
--exclude .DS_Store \
--exclude .htaccess \
--exclude wp-config.php \
--exclude /wp-admin \
--exclude /wp-includes \
--exclude /wp-content/uploads
dbdeploy: ## Envoie les donnees sur le serveur
wp db export --add-drop-table dump.sql
rsync -av $(path_local)dump.sql $(ssh):$(path_distant)
ssh $(ssh) "cd $(path_distant); wp db import dump.sql; wp search-replace '$(domain_local)' '$(domain_distant)'; rm dump.sql"
rm dump.sql