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/SVN installation
|
---|
15 | # that you want to generate the model collections with.
|
---|
16 | # Call with 0 args to process all model collections
|
---|
17 | # Call with n args, where each is a collection name in the model-collections
|
---|
18 | # list
|
---|
19 |
|
---|
20 | # PSEUDOCODE
|
---|
21 | # This script:
|
---|
22 | # Checks out the model-collections folder from SVN
|
---|
23 | # Makes a copy
|
---|
24 | # In the copy: gets rid of their .svn folders, and builds each collection in turn, moving building to index once done
|
---|
25 |
|
---|
26 |
|
---|
27 |
|
---|
28 | function single_collection () {
|
---|
29 | collection=$1
|
---|
30 |
|
---|
31 | #escape the filename (in case of space)
|
---|
32 | collection=`echo $collection | sed 's@ @\\\ @g'`
|
---|
33 |
|
---|
34 | #get just the basename
|
---|
35 | collection=`basename $collection`
|
---|
36 |
|
---|
37 | import.pl -removeold $collection
|
---|
38 | buildcol.pl -removeold $collection
|
---|
39 | rm -rf collect/$collection/index
|
---|
40 | mv collect/$collection/building collect/$collection/index
|
---|
41 |
|
---|
42 | echo
|
---|
43 | echo "*********************"
|
---|
44 | echo "Done processing $collection"
|
---|
45 | echo "*********************"
|
---|
46 | echo
|
---|
47 | }
|
---|
48 |
|
---|
49 |
|
---|
50 | function all_collections() {
|
---|
51 |
|
---|
52 | #for each collection, import, build, move building to index
|
---|
53 | for collection in collect/*; do
|
---|
54 | single_collection $collection;
|
---|
55 | done
|
---|
56 | }
|
---|
57 |
|
---|
58 |
|
---|
59 | # The program starts here
|
---|
60 | if test -e model-collect; then
|
---|
61 | svn up model-collect
|
---|
62 | else
|
---|
63 | svn co http://svn.greenstone.org/other-projects/nightly-tasks/diffcol/trunk/model-collect
|
---|
64 | fi
|
---|
65 |
|
---|
66 | # move the existing collect folder out of the way
|
---|
67 | if [ -e collect ] && [ ! -e collect_orig ] ; then
|
---|
68 | mv collect collect_orig
|
---|
69 | fi
|
---|
70 |
|
---|
71 | # make a copy of the model-collect named as the new collect
|
---|
72 | # and remove the copy's .svn folders
|
---|
73 | if [ -e collect_orig ]; then
|
---|
74 | if [ -e collect ]; then
|
---|
75 | rm -rf collect
|
---|
76 | fi
|
---|
77 | cp -r model-collect collect
|
---|
78 | fi
|
---|
79 |
|
---|
80 | #cd collect
|
---|
81 | #find . -name ".svn" -type d -exec rm -rf {} \;
|
---|
82 | #cd ..
|
---|
83 | find collect -name ".svn" -type d -exec rm -rf {} \;
|
---|
84 |
|
---|
85 | # Set up the Greenstone environment for building
|
---|
86 | source setup.bash
|
---|
87 |
|
---|
88 | # parse arguments
|
---|
89 | # http://stackoverflow.com/questions/12711786/bash-convert-command-line-arguments-into-array
|
---|
90 | # http://stackoverflow.com/questions/255898/how-to-iterate-over-arguments-in-bash-script
|
---|
91 |
|
---|
92 | if [ "$1" == "" ]; then
|
---|
93 | all_collections
|
---|
94 | else
|
---|
95 | # Command-line args are a list of collections,
|
---|
96 | # process each command-line arg, after confirming such a collection exists
|
---|
97 |
|
---|
98 | for collection in collect/"$@"; do
|
---|
99 | if test -e $collection; then
|
---|
100 | single_collection $collection;
|
---|
101 | else
|
---|
102 | echo "Can't find collection $collection. Skipping."
|
---|
103 | fi
|
---|
104 | done
|
---|
105 | fi
|
---|