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

Last change on this file since 28241 was 28240, checked in by ak19, 11 years ago
  1. Copying over collect.cfg from rebuilt collect into svn model-collect if doing an svndelete or svnupdate. 2. More messages as to what the script is doing at each stage.
File size: 29.5 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#*******************************GLOBAL VARIABLES***************************
75
76# mode can be svndelete or svnupdate
77mode=
78debug_mode=0
79commit_message=
80
81#*****************************FUNCTIONS*****************************
82
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 () {
87 collection=$1
88
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`
94
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
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
109function svn_add_new_collection () {
110
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
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
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
141 # need slash on end of src dir collect/$collection/ !
142 rsync -r --exclude=.svn/ --exclude=log/ --exclude=cache/ --exclude=earliestDatestamp --exclude=fail.log --exclude=collectionConfig.bak collect/$collection/ model-collect/$collection
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
180}
181
182# Function that handles the --svndelete flag (mode) of this script for a single collection
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
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
204
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
208
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
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
232 if [ "x$commit_message" == "x" ]; then
233 commit_message="Clean rebuild of model collections 2/2. Adding rebuilt archives and index."
234 fi
235
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
240 echo
241 echo "*********************"
242 echo "Done svn-deleting rebuilt model-collection: $collection"
243 echo "*********************"
244 echo
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
260 if [ ! -e model-collect/$collection ]; then
261 echo "del_col_archives_index: $collection does not exist in model-collect"
262 return;
263 fi
264
265 # remove the entire archives and index folders from svn
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
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
285 echo "add_col_archives_index: $collection does not exist in model-collect"
286 return;
287 fi
288
289 # copy across collect.cfg file if it has been modified
290 `diff collect/$collection/etc/collect.cfg model-collect/$collection/etc/collect.cfg`
291 status=$?
292 if [ "$status" -eq "1" ]; then
293 cp collect/$collection/etc/collect.cfg model-collect/$collection/etc/collect.cfg
294 fi
295
296 # copy across the entire rebuilt index and archives folders to the svn model-collect
297 rsync -r --exclude=.svn/ --exclude=cache/ --exclude=earliestDatestamp collect/$collection/archives model-collect/$collection
298 rsync -r --exclude=.svn/ --exclude=cache/ collect/$collection/index model-collect/$collection
299
300 # need a --force to skip all the svn:ignored files (archives/earliestDatestamp)
301 # when doing the recursive svn add on the archives and index directories
302 if [ "$debug_mode" -eq "0" ]; then
303 svn add --force model-collect/$collection/archives
304 svn add --force model-collect/$collection/index
305 fi
306}
307
308
309# UNUSED, but useful for spotting differences between the collect and model-collect
310# after rebuild, before svn updating/deleting, as opposed to at the end of the script
311function svn_process_single_collection () {
312 collection=$1
313
314 #escape the filename (in case of space) and get just the basename
315 collection=$(get_col_basename $collection)
316
317 if [ ! -e model-collect/$collection ]; then
318 echo "svn_process_single_collection: $collection does not exist in model-collect"
319 return;
320 fi
321
322# return here if just deleting empty dirs
323#return
324
325 # diff the svn model and rebuilt model collections
326 diff_result=`diff -rq model-collect/$collection collect/$collection | grep -v ".svn"`
327# echo "Diff result for collection $collection: $diff_result"
328
329 # if no differences in the current collection, then we're done
330 if [ "x$diff_result" == "x" ]; then
331 echo "No differences in collection $collection"
332 return;
333 fi
334
335 # check that none of the lines mention files outside the archives or index folders
336 # http://en.gibney.org/tell_the_bash_to_split_by_newline_charac
337 # http://forums.gentoo.org/viewtopic-p-3130541.html
338
339 # http://wi-fizzle.com/article/276
340 # http://stackoverflow.com/questions/918886/how-do-i-split-a-string-on-a-delimiter-in-bash
341 # http://www.linuxquestions.org/questions/programming-9/split-a-string-on-newlines-bash-313206/
342 # http://unix.stackexchange.com/questions/39473/command-substitution-splitting-on-newline-but-not-space
343
344 # store backup of Internal Field Separator value, then set IFS to newline for splitting on newline
345
346 IFS_BAK=$IFS
347# IFS='\n' # splits on all whitespace
348IFS='
349'
350 # in the lines returned from the diff, test for archives or newline
351 # http://stackoverflow.com/questions/229551/string-contains-in-bash
352 for line in `diff -rq model-collect/$collection collect/$collection | grep -v ".svn"`; do
353 # echo "LINE: $line"
354 if [[ "$line" != *archives* && "$line" != *index* ]]; then
355 # the file that is different is neither in index nor in archives, send this diffline to the report
356 echo $line >> report.txt
357 fi
358 done
359
360 IFS=$IFS_BAK
361 IFS_BAK=
362}
363
364# Function that takes care of the --svnupdate flag mode of this script for a single collection
365function update_single_collection () {
366 collection=$1
367
368 #escape the filename (in case of space) and get just the basename
369 collection=$(get_col_basename $collection)
370
371 if [ ! -e model-collect/$collection ]; then
372 echo "update_single_collection: $collection does not exist in model-collect"
373 return;
374 fi
375
376 # copy across collect.cfg file if it has been modified
377 `diff collect/$collection/etc/collect.cfg model-collect/$collection/etc/collect.cfg`
378 status=$?
379 if [ "$status" -eq "1" ]; then
380 cp collect/$collection/etc/collect.cfg model-collect/$collection/etc/collect.cfg
381 fi
382
383 # copy across the contents of the rebuilt model-collection's index and archives to the svn model-collect
384 rsync -r --exclude=.svn/ --exclude=cache/ --exclude=earliestDatestamp collect/$collection/archives/* model-collect/$collection/archives
385 rsync -r --exclude=.svn/ --exclude=cache/ collect/$collection/index/* model-collect/$collection/index
386
387 # now svn add any and all the NEW items in model-collect's archives and index
388 # see http://stackoverflow.com/questions/1071857/how-do-i-svn-add-all-unversioned-files-to-svn
389 # see also http://stackoverflow.com/questions/116074/how-to-ignore-a-directory-with-svn
390# if [ "$debug_mode" -eq "0" ]; then
391 svn add --force model-collect/$collection/archives/* --auto-props --parents --depth infinity -q
392 svn add --force model-collect/$collection/index/* --auto-props --parents --depth infinity -q
393# fi
394
395 echo "svn model-collect update process complete. CHECK AND COMMIT THE model-collect FOLDER!"
396
397 # if etc/collect.cfg is different, copy it across too?
398
399 echo
400 echo "*********************"
401 echo "Done updating the rebuilt LOCAL model-collection: model-collect/$collection"
402 echo "*********************"
403 echo
404}
405
406
407# re-build a single collection in "collect" which is a copy of model-collect
408function build_single_collection () {
409 collection=$1
410
411 collection=$(get_col_basename $collection)
412
413 # GS2 or GS3 building
414 if [ "x$GSDL3SRCHOME" == "x" ]; then
415 import.pl -removeold $collection;
416 buildcol.pl -removeold $collection;
417 else
418 import.pl -site localsite -removeold $collection
419 buildcol.pl -site localsite -removeold $collection
420 fi
421
422 rm -rf collect/$collection/index
423 mv collect/$collection/building collect/$collection/index
424
425 echo
426 echo "*********************"
427 echo "Done rebuilding model collection: $collection"
428 echo "*********************"
429 echo
430}
431
432
433# http://stackoverflow.com/questions/16483119/example-of-how-to-use-getopt-in-bash
434function usage() {
435# usage() { echo "Usage: $0 [-s <45|90>] [-p <string>]" 1>&2; exit 1; }
436
437 echo "*******************************************"
438 echo "Usage: $0 [--svnupdate|--svndelete|--svnaddnew] [--debug] [--message 'custom commit message'] [col1, col2, col3,...]";
439 echo "If no collections are provided, all collections will be processed.";
440 echo "If none of svnupdate, svndelete or svnaddnew are provided,"
441 echo "the specified collections are just rebuilt in the collect folder.";
442 echo "*******************************************"
443 exit 1;
444}
445
446
447#*******************************MAIN PROGRAM***************************
448
449# process optional command line arguments
450# http://blog.onetechnical.com/2012/07/16/bash-getopt-versus-getopts/
451# Execute getopt
452ARGS=$(getopt -o m:uxadh -l "message:,svnupdate,svndelete,svnaddnew,debug,help" -n "$0" -- "$@");
453
454#Bad arguments
455if [ $? -ne 0 ];then
456 usage
457 exit 1
458fi
459
460eval set -- "$ARGS";
461
462
463# -n: http://tldp.org/LDP/abs/html/testconstructs.html
464while true; do
465 case "$1" in
466 -h|--help)
467 shift;
468 usage
469 exit 0
470 ;;
471 -a|--svnaddnew)
472 shift;
473 if [ "x$mode" == "xsvnupdate" ] || [ "x$mode" == "xsvndelete" ]; then
474 echo
475 echo "Can't use both svnaddnew and svndelete/svnupdate"
476 usage
477 exit 1
478 else
479 mode=svnaddnew
480# echo "svnaddnew not yet implemented"
481# exit 0
482 fi
483 ;;
484 -x|--svndelete)
485 shift;
486 if [ "x$mode" == "xsvnupdate" ] || [ "x$mode" == "xsvnaddnew" ]; then
487 echo
488 echo "Can't use both svndelete and svnupdate/svnaddnew"
489 usage
490 exit 1
491 else
492 mode=svndelete
493 fi
494 ;;
495 -u|--svnupdate)
496 shift;
497 if [ "x$mode" == "xsvndelete" ] || [ "x$mode" == "xsvnaddnew" ]; then
498 echo
499 echo "Can't use both svnupdate and svndelete/svnaddnew"
500 usage
501 exit 1
502 else
503 mode=svnupdate
504 fi
505 ;;
506 -d|--debug)
507 shift;
508 debug_mode=1
509 ;;
510 -m|--message)
511 shift;
512 if [ -n "$1" ]; then
513 commit_message=$1
514 shift;
515 fi
516 ;;
517 --)
518 shift;
519 break;
520 ;;
521 esac
522done
523
524#echo "commit message: $commit_message"
525#echo "Debug mode is: $debug_mode"
526#exit
527
528
529# Set up the Greenstone environment, this is mainly for building, but also for locating a
530# Greenstone installation folder, in case this script doesn't live in one.
531# Then cd into the collect folder's parent for the Greenstone installation.
532# Test for GS3 home env then for GS2 home and if found, cd into the GS2/GS3 home location and
533# run setup, else try to find setup.bash/gs3-setup.bash in the current location and run it.
534# Else print a warning message saying that GSDLHOME is not set.
535if [ "$GSDL3SRCHOME" != "" ]; then
536 echo "cd-ing into Greenstone 3 home directory: $GSDL3SRCHOME"
537 cd "$GSDL3SRCHOME/web/sites/localsite"
538elif [ "$GSDLHOME" != "" ]; then
539 echo "cd-ing into Greenstone home directory: $GSDLHOME"
540 cd "$GSDLHOME"
541else
542 echo "** No GS envvars set. Attempting to source the Greenstone setup script"
543 if [ -e gs3-setup.sh ]; then
544 source ./gs3-setup.sh
545 cd "$GSDL3SRCHOME/web/sites/localsite"
546 elif [ -e setup.bash ]; then
547 source ./setup.bash
548 else
549 echo "No Greenstone Home set and no setup script found in current folder."
550 echo "You need to source the setup script in a Greenstone installation. Exiting."
551 exit -1
552 fi
553fi
554
555
556# If no mode provided (svndelete|svnupdate) as cmd line arg, then don't modify
557# the svn model-collect folder. Then this script stops after rebuilding the model-copy in collect
558
559# the remaining arguments to the script are assumed to be collections
560
561# debugging
562#for collection in "$@"; do
563# collection=collect/$collection
564# echo "Collection: $collection"
565#done
566
567# finished processing arguments
568
569
570# report will contain the output of the diff for
571if [ -f report.txt ]; then
572 rm report.txt
573fi
574
575# Need the pdfbox extension for the PDFBox tutorial
576# The PDFBox ext has to be placed in the *GSDLHOME*/ext,
577# also in GS3's case where GSDLHOME is GS3/gs2build/ext
578# Go into ext and at end popd to get back into the collect folder's parent for the GS installation
579if [ ! -e "$GSDLHOME/ext/pdf-box" ]; then
580 echo "** Getting PDFBox"
581 pushd "$GSDLHOME/ext"
582 if [ ! -e "$GSDLHOME/ext/pdf-box-java.tar.gz" ]; then
583 wget http://trac.greenstone.org/export/head/gs2-extensions/pdf-box/trunk/pdf-box-java.tar.gz
584 fi
585 tar -xvzf pdf-box-java.tar.gz
586 popd
587fi
588
589
590# move the existing collect folder out of the way
591# unless we are adding a new collection to svn, in which case, we'll grab them from whatever collect folder exists
592if [ "x$mode" != "xsvnaddnew" ] && [ -e collect ] && [ ! -e collect_orig ]; then
593 echo "** Moving collect out of the way"
594 mv collect collect_orig
595fi
596
597
598# get model-collect from svn
599# if we already have it, svn update the entire model-collect folder if processing all collections
600# or svn update just any collections specified in the model-collect folder
601if test -e model-collect; then
602 echo "** SVN updating model-collect"
603 if [ "$1" == "" ]; then
604 svn up model-collect
605 else
606 for collection in "$@"; do
607 svn up model-collect/$collection
608 done
609 fi
610else
611 echo "** Getting the model-collect folder from SVN"
612 if [ "$GSDL3SRCHOME" != "" ]; then
613 svn co http://svn.greenstone.org/other-projects/nightly-tasks/diffcol/trunk/gs3-model-collect model-collect
614 else
615 svn co http://svn.greenstone.org/other-projects/nightly-tasks/diffcol/trunk/model-collect
616 fi
617fi
618
619
620# Not using rsync to copy folders while excluding files/subfolders, since rsync is not available on lsb
621# http://www.linuxquestions.org/questions/linux-software-2/copy-svn-working-dir-without-svn-hidden-dirs-and-files-620586/
622# rsync -r --exclude=.svn/ model-collect/ collect
623
624# Make a copy of the model-collect named as the new collect
625# (or if collections are specified in the cmdline arguments, copy just these over from model-collect into collect)
626# Then remove the copy's .svn folders
627if [ "x$mode" != "xsvnaddnew" ] && [ -e collect_orig ]; then
628
629 echo "***********************************************"
630 echo "Creating a copy of the model-collect folder as folder collect and removing the .svn subfolders from the copy:"
631 echo
632
633 if [ ! -e collect ]; then
634 cp -r model-collect collect
635 find collect -name ".svn" -type d -exec rm -rf {} \; #2>&1 > /dev/null
636 else
637 if [ "$1" == "" ]; then
638 rm -rf collect
639 cp -r model-collect collect
640 find collect -name ".svn" -type d -exec rm -rf {} \;
641 else
642 for collection in "$@"; do
643 if [ -e collect/$collection ]; then
644 rm -rf collect/$collection
645 fi
646 cp -r model-collect/$collection collect/$collection
647 find collect/$collection -name ".svn" -type d -exec rm -rf {} \;
648 done
649 fi
650 fi
651 echo "***********************************************"
652fi
653
654
655# parse arguments
656# http://stackoverflow.com/questions/12711786/bash-convert-command-line-arguments-into-array
657# http://stackoverflow.com/questions/255898/how-to-iterate-over-arguments-in-bash-script
658
659if [ "$1" == "" ]; then
660
661 # all_collections
662 #for each collection, import, build, move building to index
663 for collection in collect/*; do
664 build_single_collection $collection;
665
666 if [ "x$mode" != "x" ]; then
667 #svn_process_single_collection $collection
668
669 if [ "x$mode" == "xsvnupdate" ]; then
670 update_single_collection $collection
671 elif [ "x$mode" == "xsvnaddnew" ]; then
672 svn_add_new_collection $collection
673 fi
674 fi
675 done
676
677 # having rebuilt all the collections, just the processing for svndelete remains:
678 if [ "x$mode" == "xsvndelete" ]; then
679 svn_delete
680 fi
681
682else
683 # Command-line args are a list of collections,
684 # process each command-line arg, after confirming such a collection exists
685
686 for collection in "$@"; do
687 collection=collect/$collection
688 if test -e $collection; then
689 build_single_collection $collection;
690
691 if [ "x$mode" != "x" ]; then
692 #svn_process_single_collection $collection
693
694 if [ "x$mode" == "xsvnupdate" ]; then
695 update_single_collection $collection
696 elif [ "x$mode" == "xsvnaddnew" ]; then
697 svn_add_new_collection $collection
698 fi
699 fi
700 else
701 echo
702 echo "Can't find collection $collection. Skipping."
703 echo
704 fi
705 done
706
707 # having rebuilt the specified collections above, just the processing for svndelete remains
708 if [ "x$mode" == "xsvndelete" ]; then
709 svn_delete $@
710 fi
711fi
712
713
714echo
715echo "*****************************************"
716echo
717# NO LONGER NECESSARY: WE'RE DOING A DIFF BETWEEN collect AND model-collect AT THIS SCRIPT'S END
718# if we were svn updating/deleting collections, then mode was set
719# if in that case a report was generated with additional differences, point the user to it
720#if [ -f report.txt ] && [ "x$mode" != "x" ]; then
721# echo "Some files or folders outside of archives and index directories were different. See report.txt"
722# echo
723#fi
724
725# if not svnupdating or svndeleting, then inform the user that model-collect is unchanged
726# if svnupdating, then warn the user that model-collect still needs committing
727# if svndeleting, then inform the user that model-collect has been changed and committed
728if [ "x$mode" == "x" ]; then
729 echo "* The model-collect folder has not been altered. Changes have only been made to collect"
730elif [ "x$mode" == "xsvnupdate" ]; then
731 echo "* TO DO: You still need to run svn status and svn commit on the model-collect folder. Besides that:"
732elif [ "x$mode" == "xsvndelete" ]; then
733 echo "* The model-collect folder's archives and index subfolders have been updated and committed to svn."
734elif [ "x$mode" == "xsvnaddnew" ]; then
735 echo "* The new collection(s) have been built, copied to model-collect and added to svn."
736 echo "* TO DO: You still need to run svn status and svn commit on the model-collect folder. Besides that:"
737fi
738echo
739
740if [ "x$mode" != "x" ]; then
741 echo "* DIFFERENCES REMAINING BETWEEN model-collect AND collect (skipping .svn folders):"
742 echo
743 if [ "$1" == "" ]; then
744 echo "---START DIFF---"
745 diff -rq model-collect collect | grep -v ".svn"
746 else
747 for collection in "$@"; do
748 echo "--COLLECTION: $collection"
749 diff -rq model-collect/$collection collect/$collection | grep -v ".svn"
750 echo "--"
751 done
752 fi
753 echo "---END DIFF---"
754 echo
755fi
756
757if [ -e collect_orig ]; then
758 echo "* The original collect directory has been left renamed as collect_orig"
759 echo
760fi
761
762if [ "$debug_mode" -eq "1" ]; then
763 echo "* This script was run in DEBUG MODE, nothing has been changed in svn"
764fi
765echo
766echo "*****************************************"
767echo
768
769
770# deletes empty dirs
771# find collect/$collection/archives/HASH* -type d -empty -delete
772# find collect/$collection/index/assoc/HASH* -type d -empty -delete
773
774# To recursively delete all empty dirs in the copy of model-collect (since the dirs will not have .svn folders in them anymore)
775# http://www.commandlinefu.com/commands/view/5131/recursively-remove-all-empty-directories
776#find collect -type d -empty -delete
777
778# The following when put in a separate script file will delete all folders from model-collect that are
779# empty in the copied collection (all folders which contain only a .svn subfolder in model-collect)
780# ---------------------------------------------
781#!/bin/bash
782
783#for collection in collect/*; do
784 #escape the filename (in case of space)
785# collection=`echo $collection | sed 's@ @\\\ @g'`
786
787 #get just the basename
788# collection=`basename $collection`
789
790 # HASH dirs that are empty in local collect's archives and index/assoc,
791 # need to be removed from the svn in model-collect
792
793# for line in `find collect/$collection/archives/HASH* -type d -empty`; do
794# modelline="model-$line"
795# echo "LINE: $modelline"
796
797 # remove from svn of model collect
798# svn rm $modelline
799## rm -rf $modelline
800 # remove physically from local collect
801# rm -rf $line
802# done
803
804# for line in `find collect/$collection/index/assoc/HASH* -type d -empty`; do
805# modelline="model-$line"
806# echo "LINE: $modelline"
807
808 # remove from svn of model collect
809# svn rm $modelline
810## rm -rf $modelline
811 # remove physically from local collect
812# rm -rf $line
813# done
814
815#done
816# ---------------------------------------------
Note: See TracBrowser for help on using the repository browser.