-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmagento.sh
executable file
·396 lines (342 loc) · 9.83 KB
/
magento.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
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
#!/bin/bash
# Not modify line below
# Init environment
# chmod +x /path_to_your_file/magento.sh
# ln -s /path_to_your_file/magento.sh /usr/bin/magento
# open terminal type magento
OWNER=`whoami`;
GROUP=`whoami`;
MAGE_PUBLIC_KEY=your_magento_public_key
MAGE_PRIVATE_KEY=your_magento_private_key
SCRIPTNAME=`basename "$0"`
echo "============================================================="
echo "Welcome $SCRIPTNAME Panel!"
echo "============================================================="
function isMagento()
{
cd `pwd`
if [ -f bin/magento ]
then
return 1
else
echo -e "${White} ${On_Red}"
echo "#######################################################"
echo "You need go to root magento before run this commmand."
echo "Your current locatlion: $(pwd)"
echo "#######################################################"
echo -e "${NC}"
$SCRIPTNAME
fi
}
function commandMagento()
{
if [ "$1" != "" ] ; then
local command=$1;
else
echo -n 'Enter command: '
read command
fi
isMagento
if [ $? == 1 ] ; then
eval "$command"
fi
}
function upgradeMagento2x()
{
cpath=`pwd`
isMagento
if [ $? == 1 ] ; then
chmod u+x bin/magento
fi
# sudo -i -u ${OWNER} bash << EOF
cd ${cpath}
pwd
cp composer.json composer.json.bak
echo "Current version: "
bin/magento --version
echo "All version magento availabel: "
composer config -a http-basic.repo.magento.com ${MAGE_PUBLIC_KEY} ${MAGE_PRIVATE_KEY}
composer show magento/product-community-edition 2.* --all | grep -m 1 versions
# EOF
echo "########################################"
echo -n "Enter version you want to Upgrade! : "
read version
# sudo -i -u ${OWNER} bash << EOF
cd ${cpath}
pwd
bin/magento config:set system/backup/functionality_enabled 1
bin/magento setup:backup --db
bin/magento maintenance:enable
bin/magento deploy:mode:set default
composer require magento/product-community-edition ${version} --no-update
composer update
bin/magento setup:upgrade
bin/magento indexer:reindex
bin/magento setup:static-content:deploy -f
# Remove all files in var exception directory backups
#find ./var ! -name 'backups' -type f -exec rm -f {} +
# Remove file auth account
# rm -rf auth.json
bin/magento deploy:mode:set production
bin/magento maintenance:disable
find . -type d -exec chmod 755 {} \; && find . -type f -exec chmod 644 {} \;
# EOF
echo "Upgrade Done!."
}
function createDatabase()
{
local dbname
if [ "$1" == "" ]; then
echo -n 'Enter database name: '
read dbname
else
dbname=$1;
fi
checkDatabaseExist $dbname
if [ $? -eq 0 ]; then
echo "Database $dbname exist...."
else
mysql -u$USER -p -e "CREATE DATABASE IF NOT EXISTS $dbname"
echo "Create database $dbname ...."
if [ $? -eq 0 ]; then
echo "Success...."
else
echo "FAIL...."
fi
fi
}
function defaultMode ()
{
php bin/magento maintenance:enable
php -dmemory_limit=-1 bin/magento deploy:mode:set default
php bin/magento setup:upgrade
php bin/magento config:set dev/css/minify_files 0
php bin/magento config:set dev/css/merge_css_files 0
php bin/magento config:set dev/js/minify_files 0
php bin/magento config:set dev/js/merge_files 0
php bin/magento config:set dev/js/enable_js_bundling 0
php bin/magento config:set dev/static/sign 1
php bin/magento config:set dev/debug/template_hints_storefront 1
php bin/magento config:set dev/debug/template_hints_storefront_show_with_parameter 1
php bin/magento config:set dev/debug/template_hints_blocks 1
php bin/magento config:set dev/template/allow_symlink 1
rm -rf pub/static/frontend/* && rm -rf var/view_preprocessed
php bin/magento setup:static-content:deploy -f
php bin/magento cache:flush
php bin/magento cache:enable
php bin/magento maintenance:disable
echo 'Enable Default Mode done!';
}
function productionMode ()
{
php bin/magento maintenance:enable
php bin/magento setup:upgrade
php -dmemory_limit=-1 bin/magento deploy:mode:set production --skip-compilation
php bin/magento config:set dev/css/minify_files 1
php bin/magento config:set dev/css/merge_css_files 1
php bin/magento config:set dev/js/minify_files 1
php bin/magento config:set dev/js/merge_files 0
php bin/magento config:set dev/js/enable_js_bundling 1
php bin/magento config:set dev/static/sign 1
php bin/magento config:set dev/debug/template_hints_storefront 0
php bin/magento config:set dev/debug/template_hints_storefront_show_with_parameter 0
php bin/magento config:set dev/debug/template_hints_blocks 0
php bin/magento config:set dev/template/allow_symlink 0
rm -rf pub/static/frontend/* && rm -rf var/view_preprocessed
php bin/magento setup:static-content:deploy -f
php bin/magento cache:flush
php bin/magento cache:enable
php bin/magento maintenance:disable
echo 'Enable Production Mode done!';
}
function createDatabase()
{
local sqlpassword
echo -n "Enter password user $USER : "
read sqlpassword
local name
echo -n 'Enter database name: '
read name
dbname="${USER}_${name}"
local dbexist=`mysqlshow -u$USER -p$sqlpassword $dbname| grep -v Wildcard | grep -o $dbname`;
if [ "$dbexist" == "$dbname" ]; then
echo "Database $dbname exist...."
else
mysql -u$USER -p$sqlpassword -e "CREATE DATABASE IF NOT EXISTS $dbname"
echo "Create database $dbname ...."
if [ $? -eq 0 ]; then
echo "Success...."
else
echo "FAIL...."
fi
fi
}
function importDatabase() # use importDatabase name file.sql
{
local sqlpassword
echo -n "Enter password user $USER : "
read sqlpassword
local dbname
if [ "$1" == "" ]; then
echo -n 'Enter database name: '
read dbname
else
dbname=$1;
fi
if [ "$dbname" = "mysql" ] || [ "$dbname" = "infomation_schema" ] || [ "$dbname" = "performance_schema" ]; then
clear
echo "============================================================="
echo "You can't change database system !"
echo "-------------------------------------------------------------"
#sleep 3
$SCRIPTNAME
fi
local dbexist=`mysqlshow -u$USER -p$sqlpassword $dbname| grep -v Wildcard | grep -o $dbname`;
if [ "$dbexist" == "$dbname" ]; then
if [ "$2" == "" ]; then
echo -n 'Enter database name path file .sql Import: '
read sql
else
sql=$2;
fi
if [ ! -f "$sql" ]; then
echo "============================================================="
echo "No such file sql"
echo "-------------------------------------------------------------"
#sleep 3
$SCRIPTNAME
fi
echo "Import start...."
mysql -u$USER -p$sqlpassword $dbname <$sql
if [ $? -eq 0 ]; then
echo "Import database $dbname success...."
else
echo "Import database $dbname FAIL...."
fi
else
echo "Database $dbname not exist...."
fi
}
function main ()
{
prompt="Enter number option:"
options=(
"Exit"
"php bin/magento cache:flush block_html"
"php bin/magento cache:flush layout"
"php bin/magento cache:flush"
"php bin/magento setup:upgrade"
"php bin/magento indexer:reindex"
"php bin/magento setup:di:compile"
"rm -rf pub/static/frontend/* && rm -rf var/view_preprocessed && php bin/magento setup:static-content:deploy -f"
"################################"
"php bin/magento config:set dev/static/sign 1"
"php bin/magento config:set web/secure/use_in_adminhtml 1"
"php bin/magento setup:backup --db"
"Enable Template Path Hints with Parameter Value magento"
"Enabled default Mode"
"Enabled Production Mode"
"rm -rf generated"
"Upgrade M2 version"
"find `pwd` -type d -exec chmod 755 {} \; find . -type f -exec chmod 644 {} \; find . -name ".DS_Store" -delete;"
"sudo service elasticsearch restart"
"Test elasticsearch curl localhost:9200"
"systemctl restart varnish"
"redis-cli flushall"
"php -r 'opcache_reset();'"
"Create a database with prefix '${USER}_'"
"Import a database with user: '${USER}'"
)
PS3="$prompt"
select opt in "${options[@]}" ; do
case "$REPLY" in
1) clear && echo "Bye !" && killall -g $SCRIPTNAME && clear;;
2)
commandMagento "php bin/magento cache:flush block_html"
$SCRIPTNAME
;;
3)
commandMagento "php bin/magento cache:flush layout"
$SCRIPTNAME
;;
4)
commandMagento "php bin/magento cache:flush"
$SCRIPTNAME
;;
5)
commandMagento "php bin/magento setup:upgrade"
$SCRIPTNAME
;;
6)
commandMagento "php bin/magento indexer:reindex"
$SCRIPTNAME
;;
7)
commandMagento "php bin/magento setup:di:compile"
$SCRIPTNAME
;;
8)
commandMagento "rm -rf pub/static/frontend/* && rm -rf var/view_preprocessed"
commandMagento "php bin/magento setup:static-content:deploy -f"
$SCRIPTNAME
;;
9)
echo '########################################'
$SCRIPTNAME
;;
10)
commandMagento "php bin/magento config:set dev/static/sign 1"
$SCRIPTNAME
;;
11)
commandMagento "php bin/magento config:set web/secure/use_in_adminhtml 1"
$SCRIPTNAME
;;
12)
commandMagento "php bin/magento config:set system/backup/functionality_enabled 1 && php bin/magento setup:backup --db"
$SCRIPTNAME
;;
13)
commandMagento "php bin/magento config:set dev/debug/template_hints_storefront 1"
commandMagento "php bin/magento config:set dev/debug/template_hints_storefront_show_with_parameter 1"
commandMagento "php bin/magento config:set dev/debug/template_hints_blocks 1"
commandMagento "php bin/magento cache:flush config"
;;
14)
defaultMode
$SCRIPTNAME
;;
15)
productionMode
$SCRIPTNAME
;;
16)
commandMagento "rm -rf generated"
echo 'done!';
$SCRIPTNAME
;;
17)
upgradeMagento2x
echo 'done!';
$SCRIPTNAME
;;
18)
find `pwd` -type d -exec chmod 755 {} \;
find `pwd` -type f -exec chmod 644 {} \;
echo 'done!';
$SCRIPTNAME
;;
19)
sudo service elasticsearch restart
;;
20) curl localhost:9200 ;;
21) systemctl restart varnish ;;
22) redis-cli flushall ;;
23) php -r "opcache_reset();" ;;
24) createDatabase ;;
25) importDatabase ;;
*) echo "Input wrong, please input number order on menu !";continue;;
esac
done
}
main