forked from OpenMage/migrate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
migrate.sh
160 lines (143 loc) · 4.85 KB
/
migrate.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
#!/bin/sh
set -e
# OpenMage LTS migration script (for Magento CE only)
#
# See https://www.openmage.org/magento-lts/migration-guide.html for full instructions.
#
# This script is meant for quick and easy install via:
#
# $ curl -fsSL https://migrate.openmage.org | sh
#
# The default channel is "legacy", but you can also specify "main":
#
# $ curl -fsSL https://migrate.openmage.org | CHANNEL=main sh
SCRIPT_COMMIT_SHA="SCRIPT_COMMIT_SHA_HERE"
nightly=1.9.4.x
legacy=v19.4.8
main=v20.0.4
# The channel to install from:
# * nightly
# * legacy
# * main
DEFAULT_CHANNEL_VALUE="legacy"
if [ -z "$CHANNEL" ]; then
CHANNEL=$DEFAULT_CHANNEL_VALUE
fi
case $CHANNEL in
legacy)
version=$legacy
;;
main)
version=$main
;;
*)
echo "Unknown channel: $CHANNEL"
exit 1
esac
DEFAULT_DOWNLOAD_URL="https://openmage.migrationpatches.s3.amazonaws.com/"
if [ -z "$DOWNLOAD_URL" ]; then
DOWNLOAD_URL=$DEFAULT_DOWNLOAD_URL
fi
DRY_RUN=${DRY_RUN:-}
is_dry_run() {
if [ -z "$DRY_RUN" ]; then
return 1
else
return 0
fi
}
do_install() {
if ! [ -d var ]; then
echo "Please run this script from the Magento root directory."
exit 1
fi
if ! command -v git >/dev/null; then
echo "The 'git' command is required as 'patch' does not support binary diffs."
exit 1
fi
if ! [ -f app/Mage.php ]; then
echo "Please run this script in the Magento root directory. (could not find app/Mage.php)"
exit 1
fi
if grep -qF 'getOpenMageVersionInfo' app/Mage.php; then
echo "It appears you have already upgraded this Magento CE installation to OpenMage LTS."
exit 1
fi
cat << 'BANNER'
_____ ___ ___ _ _____ _____
| _ | | \/ | | | |_ _/ ___|
| | | |_ __ ___ _ __ | . . | __ _ __ _ ___ | | | | \ `--.
| | | | '_ \ / _ \ '_ \| |\/| |/ _` |/ _` |/ _ \ | | | | `--. \
\ \_/ / |_) | __/ | | | | | | (_| | (_| | __/ | |____| | /\__/ /
\___/| .__/ \___|_| |_\_| |_/\__,_|\__, |\___| \_____/\_/ \____/
| | __/ |
|_| |___/
BANNER
echo "
This script will download the appropriate patch for your Magento installation
and update the core source code to OpenMage LTS $version.
DO NOT continue if you do not have an easily restorable backup!
DO NOT run this migration on production unless the result has been thoroughly
tested in a development environment for compatibility issues.
Migration will begin in 20 seconds. Press CTRL+C to abort.
"
sleep 20
case "$(grep '$_currentEdition' app/Mage.php | awk '{print $5}' | sed 's/self:://' | sed 's/;//')" in
EDITION_COMMUNITY)
installed=$(grep -A 8 'function getVersionInfo' app/Mage.php | tail -n 6 | awk '{print $3}' | sed "s/[',]//g" | grep -v '^$' | paste -sd '.' -)
echo "Detected that you have installed Magento Commuinity Edition $installed"
patchfile=magento-ce-$installed-openmage-lts-$version.patch
url="$DOWNLOAD_URL$patchfile"
patchfile=var/$patchfile
if ! [ -f "$patchfile" ]; then
echo "Downloading patch for Magento CE $installed to OpenMage LTS $version..."
if command -v wget >/dev/null; then
wget --no-hsts --no-check-certificate $url.gz -O $patchfile.gz
wget --no-hsts --no-check-certificate $url.sha1 -O $patchfile.sha1
elif command -v curl >/dev/null; then
curl --insecure $url.gz -o $patchfile.gz
curl --insecure $url.sha1 -o $patchfile.sha1
else
echo "Command not found, please install curl or wget within your PATH."
exit 1
fi
echo "Extracting and verifying patch file..."
gunzip $patchfile.gz
checksum=$(<$patchfile sha1sum - | awk '{print $1}')
if [ "$(awk '{print $1}' $patchfile.sha1)" != "$checksum" ]; then
rm $patchfile $patchfile.sha1
echo "Downloaded file was corrupt, please try again."
exit 1
fi
fi
echo "Performing dry-run patch..."
if git --git-dir=/dev/null apply --ignore-whitespace --check $patchfile; then
if is_dry_run; then
echo "Dry-run was successful!"
else
echo "Dry run was successful! Applying patch..."
git --git-dir=/dev/null apply --ignore-whitespace $patchfile
echo ""
echo "All done! Please refresh your cache to complete the migration."
fi
else
echo "Unable to apply the patch. The following command failed:"
echo ""
echo " git --git-dir=/dev/null apply --ignore-whitespace --check $patchfile"
echo ""
echo "If you need to restore any files, the original source code may be found at:"
echo ""
echo " https://github.com/OpenMage/magento-mirror"
echo ""
fi
;;
*)
echo "We're sorry, but the edition you have installed is not supported by this migration script."
exit 1
;;
esac
# TODO
}
# wrapped up in a function so that we have some protection against only getting
# half the file during "curl | sh"
do_install