root/other-projects/nightly-tasks/diffcol/trunk/gen-model-colls.sh @ 28133

Revision 28133, 27.1 KB (checked in by ak19, 7 years ago)

Some updates to the GS2-only versio of the script before the changes for GS3 are incorporated

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