forked from paliarush/magento2-vagrant-for-developers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
m-reinstall
executable file
·142 lines (116 loc) · 5.27 KB
/
m-reinstall
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
#!/usr/bin/env bash
vagrant_dir="/vagrant"
source "${vagrant_dir}/scripts/output_functions.sh"
get_config_value="/vagrant/scripts/get_config_value.sh"
magento_host_name="$(bash ${get_config_value} "magento_host_name")"
use_nfs="$(bash "${vagrant_dir}/scripts/get_config_value.sh" "guest_use_nfs")"
is_windows_host=${IS_WINDOWS_HOST}
generate_basic_data="$(bash ${get_config_value} "magento_generate_basic_data")"
declare -A setupOptions
setupOptions[admin_frontname]="$(bash ${get_config_value} "magento_admin_frontname")"
setupOptions[language]="$(bash ${get_config_value} "magento_language")"
setupOptions[timezone]="$(bash ${get_config_value} "magento_timezone")"
setupOptions[currency]="$(bash ${get_config_value} "magento_currency")"
setupOptions[admin_user]="$(bash ${get_config_value} "magento_admin_user")"
setupOptions[admin_password]="$(bash ${get_config_value} "magento_admin_password")"
setupOptions[db_host]='localhost'
setupOptions[db_name]='magento'
setupOptions[db_user]='root'
setupOptions[base_url]="http://${magento_host_name}/"
setupOptions[admin_lastname]='Admin'
setupOptions[admin_firstname]='Admin'
setupOptions[admin_email]='[email protected]'
setupOptions[amqp_host]='localhost'
setupOptions[amqp_port]='5672'
setupOptions[amqp_user]='guest'
setupOptions[amqp_password]='guest'
setupOptions[amqp_virtualhost]='/'
if [[ ${is_windows_host} == 1 ]] || [[ ${use_nfs} == 0 ]]; then
sudo chown -R vagrant:vagrant ${MAGENTO_ROOT}
fi
status "Killing MQ processes"
pkill -f queue
status "Installing/re-installing Magento"
incrementNestingLevel
cd ${MAGENTO_ROOT}
status "Removing Magento configuration files (env.php and config.php)"
rm -f "${MAGENTO_ROOT}/app/etc/config.php"
rm -f "${MAGENTO_ROOT}/app/etc/env.php"
bash m-clear-cache
# Cache cleaning takes 5-10 seconds and should be avoided until the end of installation to speed up the process
export SKIP_CACHE_CLEAN=1
db_names=("${setupOptions[db_name]}" "magento_integration_tests" )
for db_name in "${db_names[@]}"; do
status "Dropping and creating '${db_name}' DB"
mysql -e "drop database if exists ${db_name}; create database ${db_name};"
done
# Install Magento application
cd ${MAGENTO_ROOT}
install_cmd="./bin/magento setup:install \
--db-host=${setupOptions[db_host]} \
--db-name=${setupOptions[db_name]} \
--db-user=${setupOptions[db_user]} \
--backend-frontname=${setupOptions[admin_frontname]} \
--base-url=${setupOptions[base_url]} \
--language=${setupOptions[language]} \
--timezone=${setupOptions[timezone]} \
--currency=${setupOptions[currency]} \
--admin-lastname=${setupOptions[admin_lastname]} \
--admin-firstname=${setupOptions[admin_firstname]} \
--admin-email=${setupOptions[admin_email]} \
--admin-user=${setupOptions[admin_user]} \
--admin-password=${setupOptions[admin_password]} \
--cleanup-database \
--use-rewrites=1"
# Configure Rabbit MQ
if [[ -d "${MAGENTO_ROOT}/app/code/Magento/MessageQueue" ]] || [[ -d "${MAGENTO_ROOT}/vendor/magento/magento-message-queue" ]]; then
install_cmd="${install_cmd} \
--amqp-host=${setupOptions[amqp_host]} \
--amqp-port=${setupOptions[amqp_port]} \
--amqp-user=${setupOptions[amqp_user]} \
--amqp-virtualhost=${setupOptions[amqp_virtualhost]} \
--amqp-password=${setupOptions[amqp_password]}"
fi
sudo chmod +x bin/magento
status "${install_cmd}"
php ${install_cmd} 2> >(logError) > >(log)
# Comment out the line above and uncomment the one below to debug Magento Setup script
# php -d xdebug.remote_autostart=1 ${install_cmd} 2> >(logError) > >(log)
if [[ $? != 0 ]]; then
error "Magento installation failed."
exit 1
fi
bash "${vagrant_dir}/scripts/guest/configure_varnish" -f
status "Enabling Magento cron jobs"
echo "* * * * * php ${MAGENTO_ROOT}/bin/magento cron:run &
* * * * * php ${MAGENTO_ROOT}/update/cron.php &
* * * * * php ${MAGENTO_ROOT}/bin/magento setup:cron:run &" | crontab -u vagrant -
if [[ ${is_windows_host} == 1 ]] || [[ ${use_nfs} == 0 ]]; then
status "Changing ownership of "${MAGENTO_ROOT}" to vagrant:vagrant"
sudo chown -R vagrant:vagrant ${MAGENTO_ROOT}
fi
if [[ ${generate_basic_data} != 0 ]]; then
bash generate_basic_data
fi
bash configure_search_engine
bash change_magento_config_for_functional_tests
bash update_magento_config 'admin/security/session_lifetime' '86400'
export SKIP_CACHE_CLEAN=0
bash m-clear-cache
status "Checking if Magento frontend is accessible at '${setupOptions[base_url]}'"
magento_home_page_content="$(curl -sL ${setupOptions[base_url]})"
pattern="All rights reserved."
if [[ ${magento_home_page_content} =~ ${pattern} ]]; then
bash warm_up_cache
status "Generating XSD references for PHP Storm"
php bin/magento dev:urn-catalog:generate /vagrant/.idea/misc.xml
sed -i "s|${MAGENTO_ROOT}|${MAGENTO_ROOT_HOST}|g" "/vagrant/.idea/misc.xml"
decrementNestingLevel
success "Magento reinstalled successfully"
info "Magento application was deployed to $(bold)${MAGENTO_ROOT}$(regular) and installed successfully
Access storefront at $(bold)${setupOptions[base_url]}$(regular)
Access admin panel at $(bold)${setupOptions[base_url]}${setupOptions[admin_frontname]}/$(regular)"
else
error "Magento frontend is not accessible at '${setupOptions[base_url]}' after installation. Please scan output above and logs for errors"
exit 1
fi