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

Last change on this file since 28148 was 28148, checked in by ak19, 11 years ago

Updated the script to handle generating model collections for Greenstone 3 as well and tested it by using it build the GS3 model cols previously built on Windows and commit them. Also some corrections.

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