source: other-projects/nightly-tasks/diffcol/trunk/gen-model-colls.sh

Last change on this file was 38017, checked in by anupama, 8 months ago

Some changes for GS3, some info statements, and need to skip rebuilding Word-PDF-Enhanced model collections if OS where models are built is linux.

File size: 31.2 KB
Line 
1#!/bin/bash
2
3# PURPOSE
4# This is not a nightly script. You use it to regenerate the model-collections
5# if Greenstone has changed fundamentally, such as what HASH OIDs get assigned
6# to documents or something that changes the contents of the index and
7# archives folders. This has happened now with the commits
8# http://trac.greenstone.org/changeset/28022 and
9# http://trac.greenstone.org/changeset/28021
10# These commits generate new stable HASH OIDs for the existing documents.
11
12
13# USAGE
14# Put this file in the toplevel of the Greenstone 2 binary/compiled SVN installation
15# that you want to generate the model collections with.
16# You can provide a list of collection names or none, in which case all the collections
17# are processed.
18
19# Pass in --svnupdate to copy across the contents of archives and index in the
20# rebuilt collection, overwriting their equivalents in the svn model collection,
21# but not removing any extraneous HASH folders already present.
22# !!!!! IMPORTANT: if you pass in svnupdate, it leaves you to do the final commit on
23# the (svn) model-collect folder!
24
25# Pass in --svndelete to remove the archives and index from svn in the model-collect
26# and replace this with the rebuilt archives and index
27# The --svndelete is useful for when the HASH directory naming has changed and everything
28# in archives and index has to be wiped out and moved back in from the rebuilt col.
29# Passing in --svndelete will do the final commits on the model-collect folder.
30
31# If neither flag is passed in, then the collections are rebuilt but the svn model-collect
32# is not updated and the repository is not updated.
33
34# Examples of usage:
35# ./gen-model-colls.sh
36# ./gen-model-colls.sh --svndelete
37# ./gen-model-colls.sh --svnupdate Tudor-Basic Tudor-Enhanced
38
39# The first just rebuilds all the collections in a new folder called collect and stops there
40
41# The second rebuilds all the collections in collect and svn removes the archives and the index
42# folders in model-collect. Then it copies across the rebuilt archives and index into model-collect
43# and svn adds them.
44
45# The third example checks out all the model-collections again, but rebuilds only the 2 collections
46# specified in the new collect folder. Then it copies across the *contents* of the archives and
47# index folders of those 2 collections into their model-collect equivalents. You then still have to
48# do the final svn commit on the model-collect folder after looking over the differences.
49
50# Also valid examples:
51# ./gen-model-colls.sh Tudor-Basic Tudor-Enhanced
52# ./gen-model-colls.sh --svndelete Tudor-Basic Tudor-Enhanced
53# ./gen-model-colls.sh --svnupdate
54
55# PSEUDOCODE
56# This script:
57# Checks out the model-collections folder from SVN
58# Makes a copy
59# In the copy: gets rid of their .svn folders, and builds each collection in turn, moving building to index once done
60# If --svndelete was passed in: svn removes model-collect/archives and model-collect/index, copies over collect/index
61# and collect/archives into model-collect and svn adds model-collect/archives and model-collect/index. Then SVN COMMITS
62# model-collect/archives and model-collect/index.
63# If --svnupdate was passed in: copies collect/archives/* into model-collect/archives/*, and copies collect/index/*
64# into model-collect/index/*, overwriting files that already existed but have now been updated upon rebuild. However,
65# --svnupdate will leave untouched any files and folders unique to model-collect. No SVN commit, that's LEFT UP TO YOU.
66
67# See earlier version of this script:
68# To svn remove what's unique to model-collect and svn add what's been rebuilt in index and archives
69# see http://stackoverflow.com/questions/7502261/delete-folder-content-and-remove-from-version-control
70
71# http://stackoverflow.com/questions/5044214/how-do-i-detect-and-or-delete-empty-subversion-directories
72# http://stackoverflow.com/questions/1301203/removing-svn-files-from-all-directories
73
74# To checkout just this file and other files at this level from trac, see
75# http://stackoverflow.com/questions/11650156/svn-checkout-depth
76# http://svnbook.red-bean.com/en/1.7/svn.advanced.sparsedirs.html
77# So you would do:
78# svn co http://svn.greenstone.org/other-projects/nightly-tasks/diffcol/trunk diffcol --depth files
79
80#*******************************GLOBAL VARIABLES***************************
81
82# mode can be svndelete or svnupdate
83mode=
84debug_mode=0
85commit_message=
86
87#*****************************FUNCTIONS*****************************
88
89# DON'T ADD ANY FURTHER ECHO STATEMENTS IN FUNCTION get_col_basename
90# "you have to be really careful on what you have in this function, as having any code which will eventually echo will mean that you get incorrect return string."
91# see http://stackoverflow.com/questions/3236871/how-to-return-a-string-value-from-a-bash-function
92function get_col_basename () {
93 collection=$1
94
95 #escape the filename (in case of space)
96 collection=`echo $collection | sed 's@ @\\\ @g'`
97
98 #get just the basename
99 collection=`basename $collection`
100
101 # returning a string does not work in bash
102 # see http://stackoverflow.com/questions/3236871/how-to-return-a-string-value-from-a-bash-function
103
104 #return $collection
105 echo $collection
106}
107
108# model-collect>svn -R propset svn:ignore -F .customignore .
109# where .customignore is a file containing:
110# log
111# earliestDatestamp
112# cache
113# model-collect>svn proplist -v
114# shows the svn properties, including the svn:ignore property. So it shows what files svn will ignore
115function svn_add_new_collection () {
116
117 collection=$1
118
119 #escape the filename (in case of space) and get just the basename
120 collection=$(get_col_basename $collection)
121
122 if [ -e model-collect/$collection ];then
123 echo "svn_add_new_collection: $collection already exists in model-collect, can't add it to svn."
124 return
125 fi
126
127 # Using rsync to copy folders while excluding files/subfolders, BUT rsync is not available on lsb
128 # http://www.linuxquestions.org/questions/linux-software-2/copy-svn-working-dir-without-svn-hidden-dirs-and-files-620586/
129 # See also http://www.thegeekstuff.com/2011/01/rsync-exclude-files-and-folders/,
130 # section "Exclude multiple files and directories at the same time" (can also use a file to blacklist folders/files)
131
132 # for GS3 we have a custom ignore file
133# if [ "x$GSDL3SRCHOME" != "x" ]; then
134# mkdir model-collect/$collection
135# svn add --force model-collect/$collection
136# svn propset -R svn:ignore -F model-collect/.customignore model-collect/$collection
137#
138# if [ "x$commit_message" == "x" ]; then
139# commit_message="Adding new model collections 1/2: new empty collection dir with svn-ignore set."
140# fi
141# if [ "$debug_mode" -eq "0" ]; then
142# svn commit -m "AUTOCOMMIT by gen-model-colls.sh script. Message: $commit_message" model-collect/$collection
143# fi
144# fi
145
146
147 # need slash on end of src dir collect/$collection/ !
148 rsync -r --exclude=.svn/ --exclude=log/ --exclude=cached/ --exclude=cache/ --exclude=earliestDatestamp --exclude=fail.log --exclude=collectionConfig.bak collect/$collection/ model-collect/$collection
149
150# find collect/$collection -name ".svn" -type d -exec rm -rf {} \;
151# cp -r collect/$collection model-collect/$collection
152
153 # http://www.thegeekstuff.com/2010/06/bash-array-tutorial/
154# ignorelist=('log' 'cache' 'archives/earliestDatestamp');
155# for ignored in "${ignorelist[@]}"; do
156# if [ -f model-collect/$collection/$ignorelist ]; then
157# rm model-collect/$collection/$ignorelist
158# elif [ -d model-collect/$collection/$ignorelist ]; then
159# rm -rf model-collect/$collection/$ignorelist
160# fi
161# done
162
163 svn add --force model-collect/$collection
164
165 # http://stackoverflow.com/questions/15880249/subclipse-svn-first-commit-ignore-certain-directories
166 # http://wolfram.kriesing.de/blog/index.php/2005/svnignore-and-svnkeywords
167 # http://boblet.tumblr.com/post/35755799/setting-up-and-using-svn-ignore-with-subversion
168 # http://www.petefreitag.com/item/662.cfm
169 # http://svnbook.red-bean.com/en/1.7/svn.advanced.props.special.ignore.html
170 # http://stackoverflow.com/questions/116074/how-to-ignore-a-directory-with-svn
171
172 # Dr Bainbridge's way of doing an svn ignore is better and involves fewer steps:
173 # create the empty collection folder (-p for subcollections), svn add it,
174 # svn:ignore all the files to be ignored
175 # copy the contents of the collection across,
176 # do an svn add --force on the collection folder
177
178 #mkdir -p model-collect/$collection
179 #svn add model-collect/$collection
180 #ignorelist=('log' 'cache' 'archives/earliestDatestamp');
181 #for ignored in "${ignorelist[@]}"; do
182 # svn propset svn:ignore $ignorelist model-collect/$collection/.
183 #done
184 # cp -r collect/$collection/* model-collect/$collection/*
185 #svn add --force model-collect/$collection
186}
187
188# Function that handles the --svndelete flag (mode) of this script for a single collection
189function svn_delete () {
190
191 # svn remove archives and index in each collection
192 # commit them all
193 # copy over newly rebuilt archives and index into each model-collection
194 # svn add the new archives and index folders of each collection
195 # commit them all
196
197
198 # make a space-separated list of all the collections
199 # to keep track of which ones should be committed from the model-collect folder
200 concatlist=
201
202 if [ "x$1" == "x" ]; then
203 for collection in collect/*; do
204 _del_col_archives_index $collection
205 concatlist="$concatlist model-$collection"
206 done
207 else
208 for collection in "$@"; do
209 _del_col_archives_index $collection
210 concatlist="$concatlist model-collect/$collection"
211 done
212 fi
213
214 # svn commit in one go all the svn rm statements done above:
215 # don't do `svn up` at this point, as doing so will then retrieve all the folders that just were svn-removed
216
217 if [ "x$commit_message" == "x" ]; then
218 commit_message="Clean rebuild of model collections 1/2. Clearing out deprecated archives and index."
219 fi
220
221 # Numerical comparisons: http://tldp.org/LDP/abs/html/comparison-ops.html
222 if [ "$debug_mode" -eq "0" ]; then
223 svn commit -m "AUTOCOMMIT by gen-model-colls.sh script. Message: $commit_message" model-collect #$concatlist
224 fi
225
226 # Having svn committed the deletes, do an svn up to locally delete what was svn-removed above,
227 # BEFORE copying from the rebuilt archives and index folders
228 if [ "$debug_mode" -eq "0" ]; then
229 svn up model-collect #/$concatlist
230 fi
231
232 # copy from the rebuilt archives and index over into the svn model-collect and svn add them
233 if [ "x$1" == "x" ]; then
234 for collection in collect/*; do
235 _add_col_archives_index $collection
236 done
237 else
238 for collection in "$@"; do
239 _add_col_archives_index $collection
240 done
241 fi
242
243 # commit all the svn add statements done just above in one go
244 if [ "x$commit_message" == "x" ]; then
245 commit_message="Clean rebuild of model collections 2/2. Adding rebuilt archives and index."
246 fi
247
248 if [ "$debug_mode" -eq "0" ]; then
249 svn commit -m "AUTOCOMMIT by gen-model-colls.sh script. Message: $commit_message" model-collect #$concatlist
250 fi
251
252 echo
253 echo "*********************"
254 echo "Done svn-deleting rebuilt model-collection: $collection"
255 echo "*********************"
256 echo
257}
258
259# To undo the changes made by svndelete, run the following manually
260# svn revert --depth infinity <model-collect/$collection/archives/*
261# svn revert --depth infinity <model-collect/$collection/archives/*
262# then remove both the local archives and index, and do an svn up to get original checkout back
263
264# svn delete this collection's archives and index folders
265# (On returning from this subroutine, the commit will be done in one step for all collections on which this function was called)
266function _del_col_archives_index () {
267 collection=$1
268
269 # Do not rebuild windows-specific collection(s) on non-windows OS
270 # https://stackoverflow.com/questions/2172352/in-bash-how-can-i-check-if-a-string-begins-with-some-value
271 if [ "x$GSDLOS" != "xwindows" ] && [ $collection == Word-PDF-Enhanced* ]; then
272 return;
273 fi
274
275 #escape the filename (in case of space) and get just the basename
276 collection=$(get_col_basename $collection)
277
278 if [ ! -e model-collect/$collection ]; then
279 echo "del_col_archives_index: $collection does not exist in model-collect"
280 return;
281 fi
282
283 # remove the entire archives and index folders from svn
284 if [ "$debug_mode" -eq "0" ]; then
285 svn rm --force model-collect/$collection/archives
286 svn rm --force model-collect/$collection/index
287 elif [ "$debug_mode" -eq "1" ]; then
288 rm -rf model-collect/$collection/archives
289 rm -rf model-collect/$collection/index
290 fi
291
292}
293
294
295# copy and then svn add the collection's archives and index folders
296function _add_col_archives_index () {
297 collection=$1
298
299 #escape the filename (in case of space) and get just the basename
300 collection=$(get_col_basename $collection)
301
302 if [ ! -e model-collect/$collection ]; then
303 echo "add_col_archives_index: $collection does not exist in model-collect"
304 return;
305 fi
306
307 # copy across collect.cfg file if it has been modified
308 `diff collect/$collection/etc/collect.cfg model-collect/$collection/etc/collect.cfg`
309 status=$?
310 if [ "$status" -eq "1" ]; then
311 cp collect/$collection/etc/collect.cfg model-collect/$collection/etc/collect.cfg
312 fi
313
314 # copy across the entire rebuilt index and archives folders to the svn model-collect
315 rsync -r --exclude=.svn/ --exclude=cached/ --exclude=cache/ --exclude=earliestDatestamp collect/$collection/archives model-collect/$collection
316 rsync -r --exclude=.svn/ --exclude=cached/ --exclude=cache/ collect/$collection/index model-collect/$collection
317
318 # need a --force to skip all the svn:ignored files (archives/earliestDatestamp)
319 # when doing the recursive svn add on the archives and index directories
320 if [ "$debug_mode" -eq "0" ]; then
321 svn add --force model-collect/$collection/archives
322 svn add --force model-collect/$collection/index
323 fi
324}
325
326
327# UNUSED, but useful for spotting differences between the collect and model-collect
328# after rebuild, before svn updating/deleting, as opposed to at the end of the script
329function svn_process_single_collection () {
330 collection=$1
331
332 #escape the filename (in case of space) and get just the basename
333 collection=$(get_col_basename $collection)
334
335 if [ ! -e model-collect/$collection ]; then
336 echo "svn_process_single_collection: $collection does not exist in model-collect"
337 return;
338 fi
339
340# return here if just deleting empty dirs
341#return
342
343 # diff the svn model and rebuilt model collections
344 diff_result=`diff -rq model-collect/$collection collect/$collection | grep -v ".svn"`
345# echo "Diff result for collection $collection: $diff_result"
346
347 # if no differences in the current collection, then we're done
348 if [ "x$diff_result" == "x" ]; then
349 echo "No differences in collection $collection"
350 return;
351 fi
352
353 # check that none of the lines mention files outside the archives or index folders
354 # http://en.gibney.org/tell_the_bash_to_split_by_newline_charac
355 # http://forums.gentoo.org/viewtopic-p-3130541.html
356
357 # http://wi-fizzle.com/article/276
358 # http://stackoverflow.com/questions/918886/how-do-i-split-a-string-on-a-delimiter-in-bash
359 # http://www.linuxquestions.org/questions/programming-9/split-a-string-on-newlines-bash-313206/
360 # http://unix.stackexchange.com/questions/39473/command-substitution-splitting-on-newline-but-not-space
361
362 # store backup of Internal Field Separator value, then set IFS to newline for splitting on newline
363
364 IFS_BAK=$IFS
365# IFS='\n' # splits on all whitespace
366IFS='
367'
368 # in the lines returned from the diff, test for archives or newline
369 # http://stackoverflow.com/questions/229551/string-contains-in-bash
370 for line in `diff -rq model-collect/$collection collect/$collection | grep -v ".svn"`; do
371 # echo "LINE: $line"
372 if [[ "$line" != *archives* && "$line" != *index* ]]; then
373 # the file that is different is neither in index nor in archives, send this diffline to the report
374 echo $line >> report.txt
375 fi
376 done
377
378 IFS=$IFS_BAK
379 IFS_BAK=
380}
381
382# Function that takes care of the --svnupdate flag mode of this script for a single collection
383function update_single_collection () {
384 collection=$1
385
386 #escape the filename (in case of space) and get just the basename
387 collection=$(get_col_basename $collection)
388
389 if [ ! -e model-collect/$collection ]; then
390 echo "update_single_collection: $collection does not exist in model-collect"
391 return;
392 fi
393
394 # copy across collect.cfg file if it has been modified
395 `diff collect/$collection/etc/collect.cfg model-collect/$collection/etc/collect.cfg`
396 status=$?
397 if [ "$status" -eq "1" ]; then
398 cp collect/$collection/etc/collect.cfg model-collect/$collection/etc/collect.cfg
399 fi
400
401 # copy across the contents of the rebuilt model-collection's index and archives to the svn model-collect
402 rsync -r --exclude=.svn/ --exclude=cached/ --exclude=cache/ --exclude=earliestDatestamp collect/$collection/archives/* model-collect/$collection/archives
403 rsync -r --exclude=.svn/ --exclude=cached/ --exclude=cache/ collect/$collection/index/* model-collect/$collection/index
404
405 # now svn add any and all the NEW items in model-collect's archives and index
406 # see http://stackoverflow.com/questions/1071857/how-do-i-svn-add-all-unversioned-files-to-svn
407 # see also http://stackoverflow.com/questions/116074/how-to-ignore-a-directory-with-svn
408# if [ "$debug_mode" -eq "0" ]; then
409 svn add --force model-collect/$collection/archives/* --auto-props --parents --depth infinity -q
410 svn add --force model-collect/$collection/index/* --auto-props --parents --depth infinity -q
411# fi
412
413 echo "svn model-collect update process complete. CHECK AND COMMIT THE model-collect FOLDER!"
414
415 # if etc/collect.cfg is different, copy it across too?
416
417 echo
418 echo "*********************"
419 echo "Done updating the rebuilt LOCAL model-collection: model-collect/$collection"
420 echo "*********************"
421 echo
422}
423
424
425# re-build a single collection in "collect" which is a copy of model-collect
426function build_single_collection () {
427 collection=$1
428
429 collection=$(get_col_basename $collection)
430
431 # GS2 or GS3 building
432 if [ "x$GSDL3SRCHOME" == "x" ]; then
433 import.pl -removeold $collection;
434 buildcol.pl -removeold $collection;
435 else
436 import.pl -site localsite -removeold $collection
437 buildcol.pl -site localsite -removeold $collection
438 fi
439
440 rm -rf collect/$collection/index
441 mv collect/$collection/building collect/$collection/index
442
443 echo
444 echo "*********************"
445 echo "Done rebuilding model collection: $collection"
446 echo "*********************"
447 echo
448}
449
450
451# http://stackoverflow.com/questions/16483119/example-of-how-to-use-getopt-in-bash
452function usage() {
453# usage() { echo "Usage: $0 [-s <45|90>] [-p <string>]" 1>&2; exit 1; }
454
455 echo "*******************************************"
456 echo "Usage: $0 [--svnupdate|--svndelete|--svnaddnew] [--debug] [--message 'custom commit message'] [col1, col2, col3,...]";
457 echo "If no collections are provided, all collections will be processed.";
458 echo "If none of svnupdate, svndelete or svnaddnew are provided,"
459 echo "the specified collections are just rebuilt in the collect folder.";
460 echo "*******************************************"
461 exit 1;
462}
463
464
465#*******************************MAIN PROGRAM***************************
466
467# process optional command line arguments
468# http://blog.onetechnical.com/2012/07/16/bash-getopt-versus-getopts/
469# Execute getopt
470ARGS=$(getopt -o m:uxadh -l "message:,svnupdate,svndelete,svnaddnew,debug,help" -n "$0" -- "$@");
471
472#Bad arguments
473if [ $? -ne 0 ];then
474 usage
475 exit 1
476fi
477
478eval set -- "$ARGS";
479
480
481# -n: http://tldp.org/LDP/abs/html/testconstructs.html
482while true; do
483 case "$1" in
484 -h|--help)
485 shift;
486 usage
487 exit 0
488 ;;
489 -a|--svnaddnew)
490 shift;
491 if [ "x$mode" == "xsvnupdate" ] || [ "x$mode" == "xsvndelete" ]; then
492 echo
493 echo "Can't use both svnaddnew and svndelete/svnupdate"
494 usage
495 exit 1
496 else
497 mode=svnaddnew
498# echo "svnaddnew not yet implemented"
499# exit 0
500 fi
501 ;;
502 -x|--svndelete)
503 shift;
504 if [ "x$mode" == "xsvnupdate" ] || [ "x$mode" == "xsvnaddnew" ]; then
505 echo
506 echo "Can't use both svndelete and svnupdate/svnaddnew"
507 usage
508 exit 1
509 else
510 mode=svndelete
511 fi
512 ;;
513 -u|--svnupdate)
514 shift;
515 if [ "x$mode" == "xsvndelete" ] || [ "x$mode" == "xsvnaddnew" ]; then
516 echo
517 echo "Can't use both svnupdate and svndelete/svnaddnew"
518 usage
519 exit 1
520 else
521 mode=svnupdate
522 fi
523 ;;
524 -d|--debug)
525 shift;
526 debug_mode=1
527 ;;
528 -m|--message)
529 shift;
530 if [ -n "$1" ]; then
531 commit_message=$1
532 shift;
533 fi
534 ;;
535 --)
536 shift;
537 break;
538 ;;
539 esac
540done
541
542#echo "commit message: $commit_message"
543#echo "Debug mode is: $debug_mode"
544#exit
545
546
547# Set up the Greenstone environment, this is mainly for building, but also for locating a
548# Greenstone installation folder, in case this script doesn't live in one.
549# Then cd into the collect folder's parent for the Greenstone installation.
550# Test for GS3 home env then for GS2 home and if found, cd into the GS2/GS3 home location and
551# run setup, else try to find setup.bash/gs3-setup.bash in the current location and run it.
552# Else print a warning message saying that GSDLHOME is not set.
553if [ "$GSDL3SRCHOME" != "" ]; then
554 echo "cd-ing into Greenstone 3 home directory: $GSDL3SRCHOME"
555 cd "$GSDL3SRCHOME/web/sites/localsite"
556elif [ "$GSDLHOME" != "" ]; then
557 echo "cd-ing into Greenstone home directory: $GSDLHOME"
558 cd "$GSDLHOME"
559else
560 echo "** No GS envvars set. Attempting to source the Greenstone setup script"
561 if [ -e gs3-setup.sh ]; then
562 source ./gs3-setup.sh
563 cd "$GSDL3SRCHOME/web/sites/localsite"
564 echo "PERL_PERTURB_KEYS is $PERL_PERTURB_KEYS"
565 echo "PERL_HASH_SEED is $PERL_HASH_SEED"
566 #exit 1
567 elif [ -e setup.bash ]; then
568 source ./setup.bash
569 else
570 echo "No Greenstone Home set and no setup script found in current folder."
571 echo "You need to source the setup script in a Greenstone installation. Exiting."
572 exit -1
573 fi
574fi
575
576
577# If no mode provided (svndelete|svnupdate) as cmd line arg, then don't modify
578# the svn model-collect folder. Then this script stops after rebuilding the model-copy in collect
579
580# the remaining arguments to the script are assumed to be collections
581
582# debugging
583#for collection in "$@"; do
584# collection=collect/$collection
585# echo "Collection: $collection"
586#done
587
588# finished processing arguments
589
590
591# report will contain the output of the diff for
592if [ -f report.txt ]; then
593 rm report.txt
594fi
595
596# Need the pdfbox extension for the PDFBox tutorial
597# The PDFBox ext has to be placed in the *GSDLHOME*/ext,
598# also in GS3's case where GSDLHOME is GS3/gs2build/ext
599# Go into ext and at end popd to get back into the collect folder's parent for the GS installation
600if [ ! -e "$GSDLHOME/ext/pdf-box" ]; then
601 echo "** Getting PDFBox"
602 pushd "$GSDLHOME/ext"
603 if [ ! -e "$GSDLHOME/ext/pdf-box-java.tar.gz" ]; then
604 wget --no-check-certificate https://trac.greenstone.org/export/head/gs2-extensions/pdf-box/trunk/pdf-box-java.tar.gz
605 fi
606 tar -xvzf pdf-box-java.tar.gz
607 popd
608fi
609# for GS2 need to make PDFv2Plugin.tmp functional, now that we have pdfbox
610if [ -e "$GSDLHOME/ext/pdf-box" ] && [ "x$GSDL3SRCHOME" == "x" ]; then
611 if [ -e "$GSDLHOME/perllib/plugins/PDFv2Plugin.tmp" ]; then
612 echo "** Renaming PDFv2Plugin.tmp to PDFv2Plugin.pm to work with pdf-box"
613 mv "$GSDLHOME/perllib/plugins/PDFv2Plugin.tmp" "$GSDLHOME/perllib/plugins/PDFv2Plugin.pm"
614 fi
615fi
616
617
618# move the existing collect folder out of the way
619# unless we are adding a new collection to svn, in which case, we'll grab them from whatever collect folder exists
620if [ "x$mode" != "xsvnaddnew" ] && [ -e collect ] && [ ! -e collect_orig ]; then
621 echo "** Moving collect out of the way"
622 mv collect collect_orig
623fi
624
625
626# get model-collect from svn
627# if we already have it, svn update the entire model-collect folder if processing all collections
628# or svn update just any collections specified in the model-collect folder
629if test -e model-collect; then
630 echo "** SVN updating model-collect"
631 if [ "$1" == "" ]; then
632 svn up model-collect
633 else
634 for collection in "$@"; do
635 svn up model-collect/$collection
636 done
637 fi
638else
639 echo "** Getting the model-collect folder from SVN"
640 if [ "$GSDL3SRCHOME" != "" ]; then
641 svn co http://svn.greenstone.org/other-projects/nightly-tasks/diffcol/trunk/gs3-model-collect model-collect
642 else
643 svn co http://svn.greenstone.org/other-projects/nightly-tasks/diffcol/trunk/model-collect
644 fi
645fi
646
647
648# Not using rsync to copy folders while excluding files/subfolders, since rsync is not available on lsb
649# http://www.linuxquestions.org/questions/linux-software-2/copy-svn-working-dir-without-svn-hidden-dirs-and-files-620586/
650# rsync -r --exclude=.svn/ model-collect/ collect
651
652# Make a copy of the model-collect named as the new collect
653# (or if collections are specified in the cmdline arguments, copy just these over from model-collect into collect)
654# Then remove the copy's .svn folders
655if [ "x$mode" != "xsvnaddnew" ] && [ -e collect_orig ]; then
656
657 echo "***********************************************"
658 echo "Creating a copy of the model-collect folder as folder collect and removing the .svn subfolders from the copy:"
659 echo
660
661 if [ ! -e collect ]; then
662 cp -r model-collect collect
663 find collect -name ".svn" -type d -exec rm -rf {} \; #2>&1 > /dev/null
664 else
665 if [ "$1" == "" ]; then
666 rm -rf collect
667 cp -r model-collect collect
668 find collect -name ".svn" -type d -exec rm -rf {} \;
669 else
670 for collection in "$@"; do
671 if [ -e collect/$collection ]; then
672 rm -rf collect/$collection
673 fi
674 cp -r model-collect/$collection collect/$collection
675 find collect/$collection -name ".svn" -type d -exec rm -rf {} \;
676 done
677 fi
678 fi
679 echo "***********************************************"
680fi
681
682
683# parse arguments
684# http://stackoverflow.com/questions/12711786/bash-convert-command-line-arguments-into-array
685# http://stackoverflow.com/questions/255898/how-to-iterate-over-arguments-in-bash-script
686
687if [ "$1" == "" ]; then
688
689 # all_collections
690 #for each collection, import, build, move building to index
691 for collection in collect/*; do
692
693 if [ "x$GSDLOS" = "xwindows" ] || [ $collection != Word-PDF-Enhanced* ]; then
694
695 build_single_collection $collection;
696
697 if [ "x$mode" != "x" ]; then
698 #svn_process_single_collection $collection
699
700 if [ "x$mode" == "xsvnupdate" ]; then
701 update_single_collection $collection
702 elif [ "x$mode" == "xsvnaddnew" ]; then
703 svn_add_new_collection $collection
704 fi
705 fi
706 fi
707 done
708
709 # having rebuilt all the collections, just the processing for svndelete remains:
710 if [ "x$mode" == "xsvndelete" ]; then
711 svn_delete
712 fi
713
714else
715 # Command-line args are a list of collections,
716 # process each command-line arg, after confirming such a collection exists
717
718 for collection in "$@"; do
719 collection=collect/$collection
720 if test -e $collection; then
721 if [ "x$GSDLOS" = "xwindows" ] || [ $collection != Word-PDF-Enhanced* ]; then
722
723 build_single_collection $collection;
724
725 if [ "x$mode" != "x" ]; then
726 #svn_process_single_collection $collection
727
728 if [ "x$mode" == "xsvnupdate" ]; then
729 update_single_collection $collection
730 elif [ "x$mode" == "xsvnaddnew" ]; then
731 svn_add_new_collection $collection
732 fi
733 fi
734 fi
735 else
736 echo
737 echo "Can't find collection $collection. Skipping."
738 echo
739 fi
740 done
741
742 # having rebuilt the specified collections above, just the processing for svndelete remains
743 if [ "x$mode" == "xsvndelete" ]; then
744 svn_delete $@
745 fi
746fi
747
748
749echo
750echo "*****************************************"
751echo
752# NO LONGER NECESSARY: WE'RE DOING A DIFF BETWEEN collect AND model-collect AT THIS SCRIPT'S END
753# if we were svn updating/deleting collections, then mode was set
754# if in that case a report was generated with additional differences, point the user to it
755#if [ -f report.txt ] && [ "x$mode" != "x" ]; then
756# echo "Some files or folders outside of archives and index directories were different. See report.txt"
757# echo
758#fi
759
760# if not svnupdating or svndeleting, then inform the user that model-collect is unchanged
761# if svnupdating, then warn the user that model-collect still needs committing
762# if svndeleting, then inform the user that model-collect has been changed and committed
763if [ "x$mode" == "x" ]; then
764 echo "* The model-collect folder has not been altered. Changes have only been made to collect"
765elif [ "x$mode" == "xsvnupdate" ]; then
766 echo "* TO DO: You still need to run svn status and svn commit on the model-collect folder. Besides that:"
767elif [ "x$mode" == "xsvndelete" ]; then
768 echo "* The model-collect folder's archives and index subfolders have been updated and committed to svn."
769elif [ "x$mode" == "xsvnaddnew" ]; then
770 echo "* The new collection(s) have been built, copied to model-collect and added to svn."
771 echo "* TO DO: You still need to run svn status and svn commit on the model-collect folder. Besides that:"
772fi
773echo
774
775if [ "x$mode" != "x" ]; then
776 echo "* DIFFERENCES REMAINING BETWEEN model-collect AND collect (skipping .svn folders):"
777 echo
778 if [ "$1" == "" ]; then
779 echo "---START DIFF---"
780 diff -rq model-collect collect | grep -v ".svn"
781 else
782 for collection in "$@"; do
783 echo "--COLLECTION: $collection"
784 diff -rq model-collect/$collection collect/$collection | grep -v ".svn"
785 echo "--"
786 done
787 fi
788 echo "---END DIFF---"
789 echo
790fi
791
792if [ -e collect_orig ]; then
793 echo "* The original collect directory has been left renamed as collect_orig"
794 echo
795fi
796
797if [ "$debug_mode" -eq "1" ]; then
798 echo "* This script was run in DEBUG MODE, nothing has been changed in svn"
799fi
800echo
801echo "*****************************************"
802echo
803
804
805# deletes empty dirs
806# find collect/$collection/archives/HASH* -type d -empty -delete
807# find collect/$collection/index/assoc/HASH* -type d -empty -delete
808
809# To recursively delete all empty dirs in the copy of model-collect (since the dirs will not have .svn folders in them anymore)
810# http://www.commandlinefu.com/commands/view/5131/recursively-remove-all-empty-directories
811#find collect -type d -empty -delete
812
813# The following when put in a separate script file will delete all folders from model-collect that are
814# empty in the copied collection (all folders which contain only a .svn subfolder in model-collect)
815# ---------------------------------------------
816#!/bin/bash
817
818#for collection in collect/*; do
819 #escape the filename (in case of space)
820# collection=`echo $collection | sed 's@ @\\\ @g'`
821
822 #get just the basename
823# collection=`basename $collection`
824
825 # HASH dirs that are empty in local collect's archives and index/assoc,
826 # need to be removed from the svn in model-collect
827
828# for line in `find collect/$collection/archives/HASH* -type d -empty`; do
829# modelline="model-$line"
830# echo "LINE: $modelline"
831
832 # remove from svn of model collect
833# svn rm $modelline
834## rm -rf $modelline
835 # remove physically from local collect
836# rm -rf $line
837# done
838
839# for line in `find collect/$collection/index/assoc/HASH* -type d -empty`; do
840# modelline="model-$line"
841# echo "LINE: $modelline"
842
843 # remove from svn of model collect
844# svn rm $modelline
845## rm -rf $modelline
846 # remove physically from local collect
847# rm -rf $line
848# done
849
850#done
851# ---------------------------------------------
Note: See TracBrowser for help on using the repository browser.