forked from yvoronoy/m2install
-
Notifications
You must be signed in to change notification settings - Fork 0
/
m2install.sh
executable file
·1752 lines (1576 loc) · 44.2 KB
/
m2install.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
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
# Magento 2 Bash Install Script
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# @copyright Copyright (c) 2015-2017 by Yaroslav Voronoy ([email protected])
# @license http://www.gnu.org/licenses/
VERBOSE=1
CURRENT_DIR_NAME=$(basename "$(pwd)")
STEPS=
HTTP_HOST=http://mage2.dev/
BASE_PATH=${CURRENT_DIR_NAME}
DB_HOST=localhost
DB_USER=root
DB_PASSWORD=
MAGENTO_VERSION=2.2
DB_NAME=
USE_SAMPLE_DATA=
EE_PATH=magento2ee
INSTALL_EE=
INSTALL_B2B=
CONFIG_NAME=.m2install.conf
USE_WIZARD=1
GIT_CE_REPO="[email protected]:magento/magento2.git"
GIT_CE_SD_REPO="[email protected]:magento/magento2-sample-data.git"
GIT_EE_REPO=
GIT_EE_SD_REPO=
GIT_B2B_REPO=
GIT_CE_SD_PATH=magento2-sample-data
GIT_EE_SD_PATH=magento2-sample-data-ee
GIT_B2B_PATH=magento2b2b
SOURCE=
FORCE=
MAGE_MODE=dev
BIN_PHP=php
BIN_MAGE="-d memory_limit=2G bin/magento"
BIN_COMPOSER=$(command -v composer)
BIN_MYSQL="mysql"
BIN_GIT="git"
BACKEND_FRONTNAME="admin"
ADMIN_NAME="admin"
ADMIN_PASSWORD="123123q"
ADMIN_FIRSTNAME="Admin"
ADMIN_LASTNAME="Test"
ADMIN_EMAIL="[email protected]"
TIMEZONE="America/Chicago"
LANGUAGE="en_US"
CURRENCY="USD"
BUNDLED_EXTENSION=(
amzn/amazon-pay-and-login-magento-2-module
dotmailer/dotmailer-magento2-extension
klarna/module-core
klarna/module-kp
klarna/module-ordermanagement
temando/module-shipping-m2
vertex/module-tax
)
function printVersion()
{
printString "1.0.2"
}
function getScriptDirectory()
{
echo "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )";
return 0;
}
function checkDependencies()
{
DEPENDENCIES=(
php
composer
mysql
mysqladmin
git
cat
basename
tar
gunzip
sed
grep
mkdir
cp
mv
rm
find
chmod
date
)
for util in "${DEPENDENCIES[@]}"
do
hash "${util}" &>/dev/null || printError "'${util}' is not found on this system" || exit 1
done;
}
function askValue()
{
MESSAGE="$1"
READ_DEFAULT_VALUE="$2"
READVALUE=
if [ "${READ_DEFAULT_VALUE}" ]
then
MESSAGE="${MESSAGE} (default: ${READ_DEFAULT_VALUE})"
fi
MESSAGE="${MESSAGE}: "
read -r -p "$MESSAGE" READVALUE
if [[ $READVALUE = [Nn] ]]
then
READVALUE=''
return
fi
if [ -z "${READVALUE}" ] && [ "${READ_DEFAULT_VALUE}" ]
then
READVALUE=${READ_DEFAULT_VALUE}
fi
}
function askConfirmation() {
if [ "$FORCE" ]
then
return 0;
fi
read -r -p "${1:-Are you sure? [y/N]} " response
case $response in
[yY][eE][sS]|[yY])
retval=0
;;
*)
retval=1
;;
esac
return $retval
}
function printString()
{
if [[ "$VERBOSE" -eq 1 ]]
then
echo "$@";
fi
}
function printError()
{
>&2 echo "ERROR: $@";
return 1;
}
function printLine()
{
if [[ "$VERBOSE" -eq 1 ]]
then
echo "--------------------------------------------------"
fi
}
function setRequest()
{
local _key=$1
local _value=$2
local expression="REQUEST_${_key}=${_value}"
eval "${expression}";
}
function getRequest()
{
local _key=$1
local _variableName="REQUEST_${_key}";
if [[ "${!_variableName:-}" ]]
then
echo "${!_variableName}"
return 0;
fi
echo "";
return 1;
}
function runCommand()
{
local _prefixMessage=${1:-};
local _suffixMessage=${2:-}
if [[ "$VERBOSE" -eq 1 ]]
then
echo "${_prefixMessage}${CMD}${_suffixMessage}"
fi
# shellcheck disable=SC2086
eval ${CMD};
}
function extract()
{
if [ -f "$EXTRACT_FILENAME" ] ; then
case $EXTRACT_FILENAME in
*.tar.*|*.t*z*)
CMD="tar $(getStripComponentsValue ${EXTRACT_FILENAME}) -xf ${EXTRACT_FILENAME}"
;;
*.gz) CMD="gunzip $EXTRACT_FILENAME" ;;
*.zip) CMD="unzip -qu -x $EXTRACT_FILENAME" ;;
*) printError "'$EXTRACT_FILENAME' cannot be extracted"; exit 1; CMD='' ;;
esac
runCommand
else
printError "'$EXTRACT_FILENAME' is not a valid file"
fi
}
function getStripComponentsValue()
{
local stripComponents=
local slashCount=
slashCount=$(tar -tf "$1" | grep -v vendor | fgrep pub/index.php | sed 's/pub[/]index[.]php//' | sort | head -1 | tr -cd '/' | wc -m | tr -d ' ')
if [[ "$slashCount" -gt 0 ]]
then
stripComponents="--strip-components=$slashCount"
fi
echo "$stripComponents";
}
function mysqlQuery()
{
CMD="${BIN_MYSQL} -h${DB_HOST} -u${DB_USER} --password=\"${DB_PASSWORD}\" --execute=\"${SQLQUERY}\"";
runCommand
}
function generateDBName()
{
if [ -z "$DB_NAME" ]
then
prepareBasePath
if [ "$BASE_PATH" ]
then
DB_NAME=${DB_USER}_${BASE_PATH}
else
DB_NAME=${DB_USER}_${CURRENT_DIR_NAME}
fi
fi
DB_NAME=$(sed -e "s/\//_/g; s/[^a-zA-Z0-9_]//g" <(php -r "print strtolower('$DB_NAME');"));
}
function prepareBasePath()
{
BASE_PATH=$(echo "${BASE_PATH}" | sed "s/^\///g" | sed "s/\/$//g" );
}
function prepareBaseURL()
{
prepareBasePath
HTTP_HOST=$(echo ${HTTP_HOST}/ | sed "s/\/\/$/\//g" );
BASE_URL=${HTTP_HOST}${BASE_PATH}/
BASE_URL=$(echo "$BASE_URL" | sed "s/\/\/$/\//g" );
}
function initQuietMode()
{
if [[ "$VERBOSE" -eq 1 ]]
then
return;
fi
BIN_MAGE="${BIN_PHP} ${BIN_MAGE} --quiet"
BIN_COMPOSER="${BIN_PHP} ${BIN_COMPOSER} --quiet"
BIN_GIT="${BIN_GIT} --quiet"
FORCE=1
}
function getCodeDumpFilename()
{
local codeDumpFilename="";
if [[ -f "$(getRequest codedump)" ]]
then
codeDumpFilename="$(getRequest codedump)";
echo "$codeDumpFilename";
return 0;
fi
codeDumpFilename=$(find . -maxdepth 1 -name '*.tbz2' -o -name '*.tar.bz2' | head -n1)
if [ "${codeDumpFilename}" == "" ]
then
codeDumpFilename=$(find . -maxdepth 1 -name '*.tar.gz' | grep -v 'logs.tar.gz' | head -n1)
fi
if [ ! "$codeDumpFilename" ]
then
codeDumpFilename=$(find . -maxdepth 1 -name '*.tgz' | head -n1)
fi
if [ ! "$codeDumpFilename" ]
then
codeDumpFilename=$(find . -maxdepth 1 -name '*.zip' | head -n1)
fi
echo "$codeDumpFilename";
return 0;
}
function getDbDumpFilename()
{
local dbDumpFilename="";
if [[ -f "$(getRequest dbdump)" ]]
then
dbDumpFilename="$(getRequest dbdump)";
echo "$dbDumpFilename";
return 0;
fi
dbdumpFilename=$(find . -maxdepth 1 -name '*.sql.gz' | head -n1)
if [ ! "$dbdumpFilename" ]
then
dbdumpFilename=$(find . -maxdepth 1 -name '*_db.gz' | head -n1)
fi
if [ ! "$dbdumpFilename" ]
then
dbdumpFilename=$(find . -maxdepth 1 -name '*.sql' | head -n1)
fi
echo "$dbdumpFilename";
return 0;
}
function foundSupportBackupFiles()
{
if [ -z getCodeDumpFilename ]
then
return 1;
fi
if [ -z getDbDumpFilename ]
then
return 1;
fi
if [ ! -f "$(getCodeDumpFilename)" ] || [ ! -f "$(getDbDumpFilename)" ]
then
return 1;
fi
return 0;
}
function wizard()
{
askValue "Enter Server Name of Document Root" "${HTTP_HOST}"
HTTP_HOST=${READVALUE}
askValue "Enter Base Path" "${BASE_PATH}"
BASE_PATH=${READVALUE}
askValue "Enter DB Host" "${DB_HOST}"
DB_HOST=${READVALUE}
askValue "Enter DB User" "${DB_USER}"
DB_USER=${READVALUE}
askValue "Enter DB Password" "${DB_PASSWORD}"
DB_PASSWORD=${READVALUE}
generateDBName
askValue "Enter DB Name" "${DB_NAME}"
DB_NAME=${READVALUE}
if foundSupportBackupFiles
then
return;
fi
if askConfirmation "Do you want to install Sample Data (y/N)"
then
USE_SAMPLE_DATA=1
fi
}
function noSourceWizard()
{
if [[ "$SOURCE" ]]
then
return;
fi
if [[ ! "$SOURCE" ]] && askConfirmation "Do you want install Enterprise Edition (y/N)"
then
INSTALL_EE=1
fi
if [[ "$INSTALL_EE" ]] && askConfirmation "Do you want install B2B Extension (y/N)"
then
INSTALL_B2B=1
fi
}
function printConfirmation()
{
printComposerConfirmation
printGitConfirmation
prepareBaseURL
printString "BASE URL: ${BASE_URL}"
printString "BASE PATH: ${BASE_PATH}"
printString "DB PARAM: ${DB_USER}@${DB_HOST}"
printString "DB NAME: ${DB_NAME}"
printString "DB PASSWORD: ${DB_PASSWORD}"
printString "MAGE MODE: ${MAGE_MODE}"
printString "BACKEND FRONTNAME: ${BACKEND_FRONTNAME}"
printString "ADMIN NAME: ${ADMIN_NAME}"
printString "ADMIN PASSWORD: ${ADMIN_PASSWORD}"
printString "ADMIN FIRSTNAME: ${ADMIN_FIRSTNAME}"
printString "ADMIN LASTNAME: ${ADMIN_LASTNAME}"
printString "ADMIN EMAIL: ${ADMIN_EMAIL}"
printString "TIMEZONE: ${TIMEZONE}"
printString "LANGUAGE: ${LANGUAGE}"
printString "CURRENCY: ${CURRENCY}"
if foundSupportBackupFiles
then
return;
fi
if [ "${USE_SAMPLE_DATA}" ]
then
printString "Sample Data will be installed."
else
printString "Sample Data will NOT be installed."
fi
if [ "${INSTALL_EE}" ]
then
printString "Magento EE will be installed."
else
printString "Magento EE will NOT be installed."
fi
if [ "${INSTALL_B2B}" ]
then
printString "Magento B2B will be installed."
else
printString "Magento B2B will NOT be installed."
fi
}
function showWizard()
{
I=1;
while [ "$I" -eq 1 ]
do
if [ "$USE_WIZARD" -eq 1 ]
then
showComposerWizzard
showWizzardGit
noSourceWizard
wizard
fi
printLine
printConfirmation
if askConfirmation "Confirm That the Entered Data Is Correct? (y/N)"
then
I=0
else
USE_WIZARD=1
fi
done
}
function getConfigFiles()
{
local configPaths[0]="$HOME/$CONFIG_NAME"
configPaths[1]="$HOME/${CONFIG_NAME}.override"
local recursiveconfigs=$( (find "$(pwd)" -maxdepth 1 -name "${CONFIG_NAME}" ;\
x=$(pwd);\
while [ "$x" != "/" ] ;\
do x=$(dirname "$x");\
find "$x" -maxdepth 1 -name "${CONFIG_NAME}";\
done) | sed '1!G;h;$!d')
configPaths=("${configPaths[@]}" "${recursiveconfigs[@]}" "./$(basename ${CONFIG_NAME})");
echo "${configPaths[@]}"
return 0;
}
function loadConfigFile()
{
local filePath=
local configPaths=("$@");
for filePath in "${configPaths[@]}"
do
if [ -f "${filePath}" ]
then
source "$filePath"
USE_WIZARD=0
fi
done
generateDBName
}
function promptSaveConfig()
{
if [ "$FORCE" ]
then
return;
fi
_local=$(dirname "$BASE_PATH")
if [ "$_local" == "." ]
then
_local=
else
_local=$_local/
fi
if [ "$_local" != '/' ]
then
_local=${_local}\$CURRENT_DIR_NAME
fi
_configContent=$(cat << EOF
HTTP_HOST=$HTTP_HOST
BASE_PATH=$_local
DB_HOST=$DB_HOST
DB_NAME=$DB_NAME
DB_USER=$DB_USER
DB_PASSWORD=$DB_PASSWORD
MAGENTO_VERSION=$MAGENTO_VERSION
INSTALL_EE=$INSTALL_EE
INSTALL_B2B=$INSTALL_B2B
GIT_CE_REPO=$GIT_CE_REPO
GIT_EE_REPO=$GIT_EE_REPO
MAGE_MODE=$MAGE_MODE
BACKEND_FRONTNAME=$BACKEND_FRONTNAME
ADMIN_NAME=$ADMIN_NAME
ADMIN_PASSWORD=$ADMIN_PASSWORD
ADMIN_FIRSTNAME=$ADMIN_FIRSTNAME
ADMIN_LASTNAME=$ADMIN_LASTNAME
ADMIN_EMAIL=$ADMIN_EMAIL
TIMEZONE=$TIMEZONE
LANGUAGE=$LANGUAGE
CURRENCY=$CURRENCY
EOF
)
if [ "$(getConfigFiles)" ]
then
_currentConfigContent=$(cat "$HOME/$CONFIG_NAME")
if [ "$_configContent" == "$_currentConfigContent" ]
then
return;
fi
fi
configSavePath="$HOME/$CONFIG_NAME"
if [ -f "${configSavePath}" ]
then
configSavePath="./$CONFIG_NAME"
fi
if askConfirmation "Do you want save config to ${configSavePath} (y/N)"
then
cat << EOF > ${configSavePath}
$_configContent
EOF
printString "Config file has been created in ${configSavePath}";
fi
_local=
configSavePath=
}
function dropDB()
{
SQLQUERY="DROP DATABASE IF EXISTS ${DB_NAME}";
mysqlQuery
}
function createNewDB()
{
SQLQUERY="CREATE DATABASE IF NOT EXISTS ${DB_NAME}";
mysqlQuery
}
function restore_db()
{
dropDB
createNewDB
CMD="gunzip -cf \"$(getDbDumpFilename)\""
if which pv > /dev/null
then
CMD="pv \"$(getDbDumpFilename)\" | gunzip -cf";
fi
# Don't be confused by double gunzip in following command. Some poorly
# configured web servers can gzip everything including gzip files
CMD="${CMD} | gunzip -cf | sed -e 's/DEFINER[ ]*=[ ]*[^*]*\*/\*/'
| sed -e 's/TRIGGER[ ][\`][A-Za-z0-9_]*[\`][.]/TRIGGER /'
| sed -e 's/AFTER[ ]\(INSERT\)\{0,1\}\(UPDATE\)\{0,1\}\(DELETE\)\{0,1\}[ ]ON[ ][\`][A-Za-z0-9_]*[\`][.]/AFTER \1\2\3 ON /'
| grep -v 'mysqldump: Couldn.t find table' | grep -v 'Warning: Using a password'
| ${BIN_MYSQL} -h${DB_HOST} -u${DB_USER} --password=\"${DB_PASSWORD}\" --force $DB_NAME";
runCommand
}
function restore_code()
{
EXTRACT_FILENAME="$(getCodeDumpFilename)"
extract
CMD="mkdir -p var pub/media pub/static"
runCommand
}
function configure_files()
{
CMD="find -L ./pub -type l -delete"
runCommand
updateMagentoEnvFile
overwriteOriginalFiles
CMD="find . -type d -exec chmod 775 {} \; && find . -type f -exec chmod 664 {} \;"
runCommand
}
function appConfigImport()
{
if ${BIN_PHP} bin/magento | grep -q app:config:import
then
CMD="${BIN_PHP} bin/magento app:config:import -n"
runCommand
fi
}
function validateDeploymentFromDumps()
{
local files=(
'composer.json'
'composer.lock'
'index.php'
'pub/index.php'
'pub/static.php'
);
local directories=("app" "bin" "dev" "lib" "pub/errors" "setup" "vendor");
missingDirectories=();
for dir in "${directories[@]}"
do
if [ ! -d "$dir" ]; then
missingDirectories+=("$dir");
fi
done
if [[ "${missingDirectories[@]-}" ]]
then
echo "The following directories are missing: ${missingDirectories[@]}";
fi
missingFiles=()
for file in "${files[@]}"
do
if [ ! -f "$file" ]; then
missingFiles+=("$file");
fi
done
if [[ "${missingFiles[@]-}" ]]
then
echo "The following files are missing: ${missingFiles[@]}";
fi
if [[ "${missingDirectories[@]-}" || "${missingFiles[@]-}" ]]
then
printError "Download missing files and directories from vanilla magento"
fi
}
function switchSearchEngineToDefaultEngine()
{
local red=`tput setaf 1`
local green=`tput setaf 2`
local yellow=`tput setaf 3`
local default=`tput sgr0`
local engine=$(getConfig 'catalog/search/engine' "value");
[ "$engine" == 'mysql' ] \
|| [ -z "$engine" ] \
&& [ ! -z `grep engine app/etc/config.php | grep elastic` ] \
&& [ ! -z `grep engine app/etc/env.php.merchant | grep elastic` ] \
&& return 0;
[ -z "$engine" ] && engine=elasticsearch;
deleteConfig 'catalog/search/engine'
local stepsToTake=" - Run php bin/magento indexer:reindex catalogsearch_fulltext"
[[ ! -z `grep engine app/etc/config.php | grep elastic` ]] \
&& stepsToTake=" - Edit app/etc/config.php file and remove section engine => elasticsearch
${stepsToTake}"
cat <<endmessage
${yellow}
####################################################################################
Warning: A Search Engine has been switched from ${engine} to ${green}mysql${yellow}
If you need to see products on frontend follow the steps below:
${stepsToTake}
####################################################################################
${default}
endmessage
}
function configure_db()
{
setConfig 'web/secure/base_url' "${BASE_URL}";
setConfig 'web/unsecure/base_url' "${BASE_URL}";
deleteConfig 'web/unsecure/base_link_url';
deleteConfig 'web/secure/base_link_url';
deleteConfig 'web/unsecure/base_static_url';
deleteConfig 'web/unsecure/base_media_url';
deleteConfig 'web/secure/base_static_url';
deleteConfig 'web/secure/base_media_url';
deleteConfig "web/cookie/cookie_domain";
deleteConfig "web/secure/use_in_adminhtml";
deleteConfig "web/secure/use_in_frontend";
deleteConfig "admin/url/custom";
deleteConfig "admin/url/custom_path";
deleteConfig "admin/url/use_custom";
deleteConfig "admin/url/use_custom_path";
deleteConfig 'system/full_page_cache/fastly/fastly_api_key';
deleteConfig 'system/full_page_cache/caching_application';
deleteConfig 'catalog/placeholder/%' 'LIKE';
resetAdminPassword
switchSearchEngineToDefaultEngine
}
function setConfig()
{
local path="${1}";
local value="${2}";
SQLQUERY="UPDATE ${DB_NAME}.$(getTablePrefix)core_config_data SET ${DB_NAME}.$(getTablePrefix)core_config_data.value = '${value}' WHERE path = '${path}'"
mysqlQuery
}
function getConfig()
{
local output=
local path="${1}";
local field="${2}";
SQLQUERY="SELECT ${field} FROM ${DB_NAME}.$(getTablePrefix)core_config_data WHERE path = '${path}'";
output=$(mysqlQuery)
echo "$output" | grep -v "$field"
}
function deleteConfig()
{
local path="${1}";
local where="=";
if [ ! -z $2 ]
then
where="${2}";
fi
SQLQUERY="DELETE FROM ${DB_NAME}.$(getTablePrefix)core_config_data WHERE path ${where} '${path}'";
mysqlQuery
}
function resetAdminPassword()
{
SQLQUERY="UPDATE ${DB_NAME}.$(getTablePrefix)admin_user SET ${DB_NAME}.$(getTablePrefix)admin_user.email = '${ADMIN_EMAIL}' WHERE ${DB_NAME}.$(getTablePrefix)admin_user.username = '${ADMIN_NAME}'"
mysqlQuery
CMD="${BIN_PHP} ${BIN_MAGE} admin:user:create
--admin-user='${ADMIN_NAME}'
--admin-password='${ADMIN_PASSWORD}'
--admin-email='${ADMIN_EMAIL}'
--admin-firstname='${ADMIN_FIRSTNAME}'
--admin-lastname='${ADMIN_LASTNAME}'"
runCommand
}
function overwriteOriginalFiles()
{
if [ -f app/etc/config.local.php ]
then
CMD="mv app/etc/config.local.php app/etc/config.local.php.merchant"
runCommand
fi
if [ ! -f pub/static.php ]
then
CMD="curl -s -o pub/static.php https://raw.githubusercontent.com/magento/magento2/${MAGENTO_VERSION}/pub/static.php"
runCommand
fi
if [ -f .htaccess ] && [ ! -f .htaccess.merchant ]
then
CMD="mv .htaccess .htaccess.merchant"
runCommand
fi
CMD="curl -s -o .htaccess https://raw.githubusercontent.com/magento/magento2/${MAGENTO_VERSION}/.htaccess"
runCommand
if [ -f pub/.htaccess ] && [ ! -f pub/.htaccess.merchant ]
then
CMD="mv pub/.htaccess pub/.htaccess.merchant"
runCommand
fi
CMD="curl -s -o pub/.htaccess https://raw.githubusercontent.com/magento/magento2/${MAGENTO_VERSION}/pub/.htaccess"
runCommand
if [ -f pub/static/.htaccess ] && [ ! -f pub/static/.htaccess.merchant ]
then
CMD="mv pub/static/.htaccess pub/static/.htaccess.merchant"
runCommand
fi
CMD="curl -s -o pub/static/.htaccess https://raw.githubusercontent.com/magento/magento2/${MAGENTO_VERSION}/pub/static/.htaccess"
runCommand
if [ -f pub/media/.htaccess ] && [ ! -f pub/media/.htaccess.merchant ]
then
CMD="mv pub/media/.htaccess pub/media/.htaccess.merchant"
runCommand
fi
CMD="curl -s -o pub/media/.htaccess https://raw.githubusercontent.com/magento/magento2/${MAGENTO_VERSION}/pub/media/.htaccess"
runCommand
}
function getTablePrefix()
{
echo $(grep 'table_prefix' app/etc/env.php | head -n1 | sed "s/[a-z'_ ]*[=][>][ ]*[']//" | sed "s/['][,]*//")
return 0;
}
function updateMagentoEnvFile()
{
if [ -f app/etc/env.php ] && [ ! -f app/etc/env.php.merchant ]
then
CMD="cp app/etc/env.php app/etc/env.php.merchant"
runCommand
fi
local deployConfigurator=$(cat << EOF
<?php
\$dbHost = '${DB_HOST}';
\$dbName = '${DB_NAME}';
\$dbUser = '${DB_USER}';
\$dbPassword = '${DB_PASSWORD}';
\$frontName = '${BACKEND_FRONTNAME}';
EOF
);
deployConfigurator+=$(cat << 'EOF'
function updateMode($envConfig, $mode)
{
$envConfig['MAGE_MODE'] = $mode;
return $envConfig;
}
function updateBackendFrontName($envConfig, $frontName)
{
$envConfig['backend'] = array('frontName' => $frontName);
return $envConfig;
}
function updateDbConnection($envConfig, $connectionDetails)
{
if (empty($envConfig['db'])) {
return $envConfig;
}
unset($envConfig['db']['slave_connection']);
foreach ($envConfig['db'] as $key => $connections) {
if ($key != 'connection') {
continue;
}
foreach ($connections as $connectionName => $connectionParams) {
$envConfig['db'][$key][$connectionName] = $connectionDetails;
}
}
return $envConfig;
}
function updateSessionConfiguration($envConfig, $value)
{
$envConfig['session'] = array('save' => $value);
return $envConfig;
}
function removeNonDefaultConfiguration($envConfig)
{
$allowedConfigPaths = array(
'backend',
'crypt',
'db',
'resource',
'x-frame-options',
'MAGE_MODE',
'session',
'cache_types',
'install'
);
foreach ($envConfig as $path => $value) {
if (!in_array($path, $allowedConfigPaths)) {
unset($envConfig[$path]);
}
}
return $envConfig;
}
ob_start();
require 'vendor/autoload.php';
ob_end_clean();
$formatter = new Magento\Framework\App\DeploymentConfig\Writer\PhpFormatter();
$envConfig = require 'app/etc/env.php';
$envConfig = removeNonDefaultConfiguration($envConfig);
$envConfig = updateSessionConfiguration($envConfig, 'files');
$envConfig = updateDbConnection($envConfig, array(
'host' => "$dbHost",
'dbname' => "$dbName",
'username' => "$dbUser",
'password' => "$dbPassword",
'model' => 'mysql4',
'engine' => 'innodb',
'initStatements' => 'SET NAMES utf8;',
'active' => '1'
));
$envConfig = updateBackendFrontName($envConfig, $frontName);
$envConfig = updateMode($envConfig, 'default');
$data = $formatter->format($envConfig);
echo $data;
EOF
);
echo "$deployConfigurator" | php > app/etc/env.php.generated
mv app/etc/env.php.generated app/etc/env.php
}
function deployStaticContent()
{
if [[ "$MAGE_MODE" == "dev" ]]
then
return;
fi
CMD="${BIN_PHP} ${BIN_MAGE} setup:static-content:deploy"
runCommand
}
function compileDi()
{
if [[ "$MAGE_MODE" == "dev" ]]
then
return;
fi
CMD="${BIN_PHP} ${BIN_MAGE} setup:di:compile"
runCommand
}
function installSampleData()
{
if ${BIN_PHP} bin/magento --version | grep -q beta
then
_installSampleDataForBeta;
elif [ "$SOURCE" == 'git' ]
then
_installGitSampleData;
else
_installSampleData;
fi
}
function _installSampleData()
{
if ! ${BIN_PHP} bin/magento | grep -q sampledata:deploy
then
printString "Your version does not support sample data"
return;
fi
if [ -f "${HOME}/.config/composer/auth.json" ]
then
if [ -d "var/composer_home" ]
then
CMD="cp ${HOME}/.config/composer/auth.json var/composer_home/"
runCommand
fi
fi
if [ -f "${HOME}/.composer/auth.json" ]
then
if [ -d "var/composer_home" ]
then
CMD="cp ${HOME}/.composer/auth.json var/composer_home/"
runCommand
fi
fi
if ! grep -q 'https://repo.magento.com' composer.json;
then
CMD="${BIN_PHP} ${BIN_COMPOSER} config repositories.magento composer https://repo.magento.com"
runCommand
fi
CMD="${BIN_PHP} ${BIN_MAGE} sampledata:deploy"