Merge remote-tracking branch 'upstream/4.5' into 4.5-master-2014-12-22-22-01-44
[civicrm-core.git] / tools / scripts / release-testing / upgrader.sh.txt
1 #!/bin/bash
2
3 : <<COMMENTBLOCK
4
5 Release testing script is located in *tools* repository, in scripts/release-testing directory.
6
7 h2. Utility script
8
9 Script is located in scripts/release-testing/upgrader.sh It's written in bash and offers following functions:
10
11 * *upgrader.sh cleanup-files* - removes CiviCRM installation files
12 * *upgrader.sh cleanup-dbs* - makes sure that CiviCRM database is empty and Drupal database is in pristine state
13 * *upgrader.sh install /path/to/tarball* - installs CiviCRM files from provided tarball and runs install webtest
14 * *upgrader.sh upgrade /path/to/tarball* - puts CiviCRM files from provided tarball in place of currently existing install and runs upgrade webtest
15 * *upgrader.sh dumpschema-cividb /path/to/dumpfile.mysql* - dumps CiviCRM schema into given file
16 * *upgrader.sh run-checks* - verifies if all the params are set correctly
17 * *upgrader.sh run-tests* - TBD
18
19 Before you can use the script, you need to set following variables inside:
20 * CIVIDBNAME - name of CiviCRM database
21 * CIVIDBUSER - username to access CiviCRM database
22 * CIVIDBPASS - password to access CiviCRM database
23 * DRUPALDBNAME - name of Drupal database
24 * DRUPALDBUSER - username to access Drupal database
25 * DRUPALDBPASS - password to access Drupal database
26 * DRUPALPRISTINEDBFILE - path to mysql dump of pristine Drupal database
27 * DRUPALDIR - a path to Drupal root directory
28 * MODULESDIR - a path to Drupal modules directory
29 * CIVICRMDIR - a path where CiviCRM is expected to be
30 * DRUPALURL - URL of Drupal installation used for upgrade testing
31 * CIVICRMURL - URL of CiviCRM installation used for upgrade testing
32 * PHPUNITSCRIPTDIR - path from which WebTests (using PHPunit) will be run
33 * PHPUNITCOMMAND - name of the script used to run WebTests
34
35
36 h2. Example release testing scenarios
37
38 h3. Simple release tests
39
40 Simple release test is located in scripts/release-testing/simpleupgradetest.sh
41
42 {code}
43 ./upgrader.sh run-checks
44 ./upgrader.sh cleanup-dbs
45 ./upgrader.sh cleanup-files
46 ./upgrader.sh install 3.3.0-tarball
47 ./upgrader.sh upgrade 3.4.1-tarball
48 {code}
49
50 Step by step description:
51 * good idea to run-checks at the beginning to make sure all the stuff is set up correctly
52 * first two lines: cleans up databases for upgrade testing installation and removes CiviCRM files (in case they weren't cleaned up from previous runs) for upgrade testing installation
53 * installs start version (3.3.0 in above case) -
54 * upgrades 3.3.0 to 3.4.1
55
56
57 h3. Upgraded database schema verification
58
59 Upgraded database schema verification test is located in scripts/release-testing/simpleupgradetest.sh
60
61 {code}
62 ./upgrader.sh run-checks
63 ./upgrader.sh cleanup-dbs
64 ./upgrader.sh cleanup-files
65
66 ./upgrader.sh install 3.4.1-tarball
67 ./upgrader.sh dumpschema-cividb 3.4.1-clean.mysql
68
69 ./upgrader.sh cleanup-dbs
70 ./upgrader.sh cleanup-files
71
72 ./upgrader.sh install 3.3.0-tarball
73 ./upgrader.sh upgrade 3.4.1-tarball
74 ./upgrader.sh dumpschema-cividb 3.4.1-upgraded.mysql
75
76 diff 3.4.1-clean.mysql 3.4.1-upgraded.mysql
77 {code}
78
79 Step by step description:
80 * good idea to run-checks at the beginning to make sure all the stuff is set up correctly
81 * first two lines: cleans up databases for upgrade testing installation and removes CiviCRM files (in case they weren't cleaned up from previous runs) for upgrade testing installation
82 * installs start version (3.4.1 in above case)
83 * dumps database schema for clean 3.4.1 install
84 * cleans up again
85 * installs 3.3.0
86 * upgrades 3.3.0 to 3.4.1
87 * dumps database schema for upgraded 3.4.1 install
88 * produces a diff between dumps to verify if core upgrade code takes all the necessary schema changes into consideration
89
90 h2. Assembling other release testing scenario
91
92 TBD
93
94 COMMENTBLOCK
95
96 ############
97 #
98 # START: Configuration
99 #
100 ############
101
102 CIVIDBNAME=
103 CIVIDBUSER=
104 CIVIDBPASS=
105
106 DRUPALDBNAME=
107 DRUPALDBUSER=
108 DRUPALDBPASS=
109 DRUPALPRISTINEDBFILE=
110
111 DRUPALDIR=
112 MODULESDIR=$DRUPALDIR"/sites/all/modules"
113 SETTINGSDIR=$DRUPALDIR"/sites/all"
114 CIVICRMDIR=$MODULESDIR"/civicrm"
115 DRUPALURL="http://url.url"
116 CIVICRMURL=$DRUPALURL"/civicrm/dashboard"
117
118
119 PHPUNITSCRIPTDIR=""
120 PHPUNITCOMMAND="scripts/phpunit"
121
122 ############
123 #
124 # END: Configuration
125 #
126 # DO NOT EDIT BELOW THIS LINE
127 #
128 # START: Command line params verification
129 #
130 ############
131
132 PU_INSTALLTEST="WebTest_Release_InstallScript"
133 PU_UPGRADETEST="WebTest_Release_UpgradeScript"
134 PU_SUITE="WebTest_AllTests"
135
136 echo
137
138 USAGE="Usage: upgrader.sh ACTION [/path/to/file]"
139 SELF=$(cd $(dirname $0); pwd -P)/$(basename $0)
140 ACTION=$1
141 FILENAME=$2
142
143 if [ -z $ACTION ] ; then
144 echo $USAGE
145 exit 1
146 fi
147
148 if [ $ACTION == "install" ] && [ -z $FILENAME ] ; then
149 echo $USAGE
150 echo "(Tarball parameter required for install)"
151 exit 1
152 fi
153
154 if [ $ACTION == "upgrade" ] && [ -z $FILENAME ] ; then
155 echo $USAGE
156 echo "(Tarball parameter required for upgrade)"
157 exit 1
158 fi
159
160 if [ $ACTION == "dumpschema-cividb" ] && [ -z $FILENAME ] ; then
161 echo $USAGE
162 echo "(Filename parameter required for dumpschema-cividb)"
163 exit 1
164 fi
165
166 ############
167 #
168 # END: Command line params verification
169 #
170 # START: Utility functions
171 #
172 ############
173
174 function upgecho {
175 echo "*** Upgrader (action: $ACTION): $1 "
176 }
177
178 function errecho {
179 upgecho "## ERROR: $1 "
180 }
181
182 function run-checks {
183
184 SILENT=$1
185 CHECKS=0
186
187 if [ $SILENT -eq 1 ] ; then
188 upgecho "Starting checks..."
189 fi
190
191 if [ $ACTION == "install" ] && [ ! -r $FILENAME ] ; then
192 errecho "Tarball: \""$FILENAME"\" doesn't exist or is not readable."
193 CHECKS=1
194 fi
195
196 if [ $ACTION == "upgrade" ] && [ ! -r $FILENAME ] ; then
197 errecho "Tarball: \""$FILENAME"\" doesn't exist or is not readable."
198 CHECKS=1
199 fi
200
201 if [ ! -r $DRUPALPRISTINEDBFILE ] ; then
202 errecho "Drupal pristine database file: \""$DRUPALPRISTINEDBFILE"\" doesn't exist or is not readable."
203 CHECKS=1
204 fi
205
206 if [ ! -w $DRUPALDIR ] ; then
207 errecho "Drupal directory (value: $DRUPALDIR) does not exist or not writable."
208 CHECKS=1
209 fi
210
211 if [ ! -w $MODULESDIR ] ; then
212 errecho "Drupal modules directory (value: $MODULESDIR) does not exist or not writable."
213 CHECKS=1
214 fi
215
216
217 if [ -d $CIVICRMDIR ] ; then
218 upgecho "CiviCRM directory (value: $CIVICRMDIR) already exists, but maybe it's not a problem."
219 fi
220
221 if [ $CHECKS -eq 1 ] ; then
222 errecho "Quitting due to errors: see messages above."
223 exit 1
224 fi
225
226
227
228 if [ $SILENT -eq 1 ] ; then
229
230 upgecho "Action: $ACTION"
231 upgecho "Tarball: $FILENAME"
232 upgecho "Script path: $SELF"
233 upgecho "Drupal location: $DRUPALDIR"
234 upgecho "CiviCRM will be installed to: $CIVICRMDIR"
235 upgecho "CiviCRM Database credentials: u: $CIVIDBUSER, p: $CIVIDBPASS, n: $CIVIDBNAME"
236 upgecho "Drupal Database credentials: u: $DRUPALDBUSER, p: $DRUPALDBPASS, n: $DRUPALDBNAME"
237
238 upgecho "Done with checks, everything seems fine."
239
240 fi
241
242 }
243
244 ############
245 #
246 # END: Utility functions
247 #
248 # START: Webtest related functions
249 #
250 ############
251
252 function run-upgrade-scenario {
253 upgecho "Running upgrade scenario tests."
254 echo "*** Take it away, Sebastian! "
255 echo
256 cd $PHPUNITSCRIPTDIR
257 $PHPUNITCOMMAND $PU_UPGRADETEST
258 echo
259 }
260
261 function run-install-scenario {
262 upgecho "Running install scenario tests."
263 echo "*** Take it away, Sebastian! "
264 echo
265 cd $PHPUNITSCRIPTDIR
266 $PHPUNITCOMMAND $PU_INSTALLTEST
267 echo
268 }
269
270 function run-tests {
271 upgecho "Running post upgrade tests."
272 echo "*** Take it away, Sebastian! "
273 echo
274 cd $PHPUNITSCRIPTDIR
275 $PHPUNITCOMMAND $PU_SUITE
276 echo
277 }
278
279 ############
280 #
281 # END: Webtest related functions
282 #
283 # START: Core functionality
284 #
285 ############
286
287 function remove-files {
288 upgecho "Cleaning up files. ($CIVICRMDIR is gone!)"
289 rm -rf $CIVICRMDIR
290 }
291
292 function remove-settings {
293 upgecho "Removing civicrm.settings.php. ($SETTINGSDIR/civicrm.settings.php is gone!)"
294 rm -rf $SETTINGSDIR"/civicrm.settings.php"
295 }
296
297 function cleanup-cividb {
298 upgecho "Cleaning up CiviCRM db (dropped and created)."
299 mysqladmin -f -u $CIVIDBUSER -p$CIVIDBPASS drop $CIVIDBNAME >> /dev/null 2>&1
300 mysqladmin -f -u $CIVIDBUSER -p$CIVIDBPASS create $CIVIDBNAME >> /dev/null 2>&1
301 }
302
303 function cleanup-drupdb {
304 upgecho "Cleaning up Drupal db (pristine copy loaded)."
305 mysqladmin -f -u $DRUPALDBUSER -p$DRUPALDBPASS drop $DRUPALDBNAME >> /dev/null 2>&1
306 mysqladmin -f -u $DRUPALDBUSER -p$DRUPALDBPASS create $DRUPALDBNAME >> /dev/null 2>&1
307 mysql -u $DRUPALDBUSER -p$DRUPALDBPASS $DRUPALDBNAME < $DRUPALPRISTINEDBFILE
308 }
309
310 function dump-schema {
311 mysqldump --no-data -u $CIVIDBUSER -p$CIVIDBPASS $CIVIDBNAME > $1
312 }
313
314 function install-files {
315 upgecho "Installing files from $FILENAME."
316 cd $MODULESDIR
317 tar xzvf $1 >> /dev/null 2>&1
318 }
319
320 ############
321 #
322 # END: Core functionality
323 #
324 # START: Action hub
325 #
326 ############
327
328 case $ACTION in
329
330 run-checks)
331 run-checks 1
332 ;;
333
334 cleanup-files)
335 run-checks 0
336 remove-files
337 remove-settings
338 ;;
339
340 cleanup-dbs)
341 run-checks 0
342 cleanup-drupdb
343 cleanup-cividb
344 ;;
345
346 install)
347 run-checks 0
348 install-files $FILENAME
349 run-install-scenario
350 ;;
351
352 upgrade)
353 run-checks 0
354 remove-files
355 install-files $FILENAME
356 run-upgrade-scenario
357 ;;
358
359 dumpschema-cividb)
360 run-checks 0
361 dump-schema $FILENAME
362 ;;
363
364 tests)
365 run-checks 0
366 run-tests
367 ;;
368 esac
369
370 ############
371 #
372 # END: Action hub
373 #
374 ############
375
376 echo