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
|
---|
77 | mode=
|
---|
78 | debug_mode=0
|
---|
79 | commit_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
|
---|
86 | function 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
|
---|
109 | function 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
|
---|
168 | function 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)
|
---|
239 | function _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
|
---|
263 | function _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 | # remove the entire archives and index folders from svn
|
---|
275 | cp -r collect/$collection/archives model-collect/$collection/.
|
---|
276 | cp -r 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
|
---|
289 | function 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
|
---|
326 | IFS='
|
---|
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
|
---|
343 | function 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 | cp -r collect/$collection/archives/* model-collect/$collection/archives/.
|
---|
356 | cp -r 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
|
---|
379 | function 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
|
---|
398 | function usage() {
|
---|
399 | # usage() { echo "Usage: $0 [-s <45|90>] [-p <string>]" 1>&2; exit 1; }
|
---|
400 |
|
---|
401 | echo "*******************************************"
|
---|
402 | echo "Usage: $0 [--svnupdate|--svndelete] [--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
|
---|
415 | ARGS=$(getopt -o m:uxadh -l "message:,svnupdate,svndelete,svnaddnew,debug,help" -n "$0" -- "$@");
|
---|
416 |
|
---|
417 | #Bad arguments
|
---|
418 | if [ $? -ne 0 ];then
|
---|
419 | usage
|
---|
420 | exit 1
|
---|
421 | fi
|
---|
422 |
|
---|
423 | eval set -- "$ARGS";
|
---|
424 |
|
---|
425 |
|
---|
426 | # -n: http://tldp.org/LDP/abs/html/testconstructs.html
|
---|
427 | while 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
|
---|
485 | done
|
---|
486 |
|
---|
487 | #echo "commit message: $commit_message"
|
---|
488 | #echo "Debug mode is: $debug_mode"
|
---|
489 | #exit
|
---|
490 |
|
---|
491 |
|
---|
492 | # If no mode provided (svndelete|svnupdate) as cmd line arg, then don't modify
|
---|
493 | # the svn model-collect folder. Then this script stops after rebuilding the model-copy in collect
|
---|
494 |
|
---|
495 | # the remaining arguments to the script are assumed to be collections
|
---|
496 |
|
---|
497 | # debugging
|
---|
498 | #for collection in "$@"; do
|
---|
499 | # collection=collect/$collection
|
---|
500 | # echo "Collection: $collection"
|
---|
501 | #done
|
---|
502 |
|
---|
503 | # finished processing arguments
|
---|
504 |
|
---|
505 |
|
---|
506 | # report will contain the output of the diff for
|
---|
507 | if [ -f report.txt ]; then
|
---|
508 | rm report.txt
|
---|
509 | fi
|
---|
510 |
|
---|
511 | # Need pdfbox for the PDFBox tutorial
|
---|
512 | if [ ! -e ext/pdf-box ]; then
|
---|
513 | cd ext
|
---|
514 | if [ ! -e ext/pdf-box-java.tar.gz ]; then
|
---|
515 | wget http://trac.greenstone.org/export/head/gs2-extensions/pdf-box/trunk/pdf-box-java.tar.gz
|
---|
516 | tar -xvzf pdf-box-java.tar.gz
|
---|
517 | fi
|
---|
518 | cd ..
|
---|
519 | fi
|
---|
520 |
|
---|
521 |
|
---|
522 | # move the existing collect folder out of the way
|
---|
523 | # unless we are adding a new collection to svn, in which case, we'll grab them from whatever collect folder exists
|
---|
524 | if [ "x$mode" != "xsvnaddnew" ] && [ -e collect ] && [ ! -e collect_orig ]; then
|
---|
525 | mv collect collect_orig
|
---|
526 | fi
|
---|
527 |
|
---|
528 |
|
---|
529 | # get model-collect from svn
|
---|
530 | # if we already have it, svn update the entire model-collect folder if processing all collections
|
---|
531 | # or svn update just any collections specified in the model-collect folder
|
---|
532 | if test -e model-collect; then
|
---|
533 | if [ "$1" == "" ]; then
|
---|
534 | svn up model-collect
|
---|
535 | else
|
---|
536 | for collection in "$@"; do
|
---|
537 | svn up model-collect/$collection
|
---|
538 | done
|
---|
539 | fi
|
---|
540 | else
|
---|
541 | svn co http://svn.greenstone.org/other-projects/nightly-tasks/diffcol/trunk/model-collect
|
---|
542 | fi
|
---|
543 |
|
---|
544 | # Not using rsync to copy folders while excluding files/subfolders, since rsync is not available on lsb
|
---|
545 | # http://www.linuxquestions.org/questions/linux-software-2/copy-svn-working-dir-without-svn-hidden-dirs-and-files-620586/
|
---|
546 | # rsync -r --exclude=.svn/ model-collect/ collect
|
---|
547 |
|
---|
548 | # Make a copy of the model-collect named as the new collect
|
---|
549 | # (or if collections are specified in the cmdline arguments, copy just these over from model-collect into collect)
|
---|
550 | # Then remove the copy's .svn folders
|
---|
551 | if [ "x$mode" != "xsvnaddnew" ] && [ -e collect_orig ]; then
|
---|
552 |
|
---|
553 | echo "***********************************************"
|
---|
554 | echo "Creating a copy of the model-collect folder as folder collect and removing the .svn subfolders from the copy:"
|
---|
555 | echo
|
---|
556 |
|
---|
557 | if [ ! -e collect ]; then
|
---|
558 | cp -r model-collect collect
|
---|
559 | find collect -name ".svn" -type d -exec rm -rf {} \; #2>&1 > /dev/null
|
---|
560 | else
|
---|
561 | if [ "$1" == "" ]; then
|
---|
562 | rm -rf collect
|
---|
563 | cp -r model-collect collect
|
---|
564 | find collect -name ".svn" -type d -exec rm -rf {} \;
|
---|
565 | else
|
---|
566 | for collection in "$@"; do
|
---|
567 | if [ -e collect/$collection ]; then
|
---|
568 | rm -rf collect/$collection
|
---|
569 | fi
|
---|
570 | cp -r model-collect/$collection collect/$collection
|
---|
571 | find collect/$collection -name ".svn" -type d -exec rm -rf {} \;
|
---|
572 | done
|
---|
573 | fi
|
---|
574 | fi
|
---|
575 | echo "***********************************************"
|
---|
576 | fi
|
---|
577 |
|
---|
578 |
|
---|
579 | # Set up the Greenstone environment for building
|
---|
580 | source setup.bash
|
---|
581 |
|
---|
582 | # parse arguments
|
---|
583 | # http://stackoverflow.com/questions/12711786/bash-convert-command-line-arguments-into-array
|
---|
584 | # http://stackoverflow.com/questions/255898/how-to-iterate-over-arguments-in-bash-script
|
---|
585 |
|
---|
586 | if [ "$1" == "" ]; then
|
---|
587 |
|
---|
588 | # all_collections
|
---|
589 | #for each collection, import, build, move building to index
|
---|
590 | for collection in collect/*; do
|
---|
591 | build_single_collection $collection;
|
---|
592 |
|
---|
593 | if [ "x$mode" != "x" ]; then
|
---|
594 | #svn_process_single_collection $collection
|
---|
595 |
|
---|
596 | if [ "x$mode" == "xsvnupdate" ]; then
|
---|
597 | update_single_collection $collection
|
---|
598 | elif [ "x$mode" == "xsvnaddnew" ]; then
|
---|
599 | svn_add_new_collection $collection
|
---|
600 | fi
|
---|
601 | fi
|
---|
602 | done
|
---|
603 |
|
---|
604 | # having rebuilt all the collections, just the processing for svndelete remains:
|
---|
605 | if [ "x$mode" == "xsvndelete" ]; then
|
---|
606 | svn_delete
|
---|
607 | fi
|
---|
608 |
|
---|
609 | else
|
---|
610 | # Command-line args are a list of collections,
|
---|
611 | # process each command-line arg, after confirming such a collection exists
|
---|
612 |
|
---|
613 | for collection in "$@"; do
|
---|
614 | collection=collect/$collection
|
---|
615 | if test -e $collection; then
|
---|
616 | build_single_collection $collection;
|
---|
617 |
|
---|
618 | if [ "x$mode" != "x" ]; then
|
---|
619 | #svn_process_single_collection $collection
|
---|
620 |
|
---|
621 | if [ "x$mode" == "xsvnupdate" ]; then
|
---|
622 | update_single_collection $collection
|
---|
623 | elif [ "x$mode" == "xsvnaddnew" ]; then
|
---|
624 | svn_add_new_collection $collection
|
---|
625 | fi
|
---|
626 | fi
|
---|
627 | else
|
---|
628 | echo
|
---|
629 | echo "Can't find collection $collection. Skipping."
|
---|
630 | echo
|
---|
631 | fi
|
---|
632 | done
|
---|
633 |
|
---|
634 | # having rebuilt the specified collections above, just the processing for svndelete remains
|
---|
635 | if [ "x$mode" == "xsvndelete" ]; then
|
---|
636 | svn_delete $@
|
---|
637 | fi
|
---|
638 | fi
|
---|
639 |
|
---|
640 |
|
---|
641 | echo
|
---|
642 | echo "*****************************************"
|
---|
643 | echo
|
---|
644 | # NO LONGER NECESSARY: WE'RE DOING A DIFF BETWEEN collect AND model-collect AT THIS SCRIPT'S END
|
---|
645 | # if we were svn updating/deleting collections, then mode was set
|
---|
646 | # if in that case a report was generated with additional differences, point the user to it
|
---|
647 | #if [ -f report.txt ] && [ "x$mode" != "x" ]; then
|
---|
648 | # echo "Some files or folders outside of archives and index directories were different. See report.txt"
|
---|
649 | # echo
|
---|
650 | #fi
|
---|
651 |
|
---|
652 | # if not svnupdating or svndeleting, then inform the user that model-collect is unchanged
|
---|
653 | # if svnupdating, then warn the user that model-collect still needs committing
|
---|
654 | # if svndeleting, then inform the user that model-collect has been changed and committed
|
---|
655 | if [ "x$mode" == "x" ]; then
|
---|
656 | echo "* The model-collect folder has not been altered. Changes have only been made to collect"
|
---|
657 | elif [ "x$mode" == "xsvnupdate" ]; then
|
---|
658 | echo "* TO DO: You still need to run svn status and svn commit on the model-collect folder. Besides that:"
|
---|
659 | elif [ "x$mode" == "xsvndelete" ]; then
|
---|
660 | echo "* The model-collect folder's archives and index subfolders have been updated and committed to svn."
|
---|
661 | elif [ "x$mode" == "xsvnaddnew" ]; then
|
---|
662 | echo "* The new collection(s) have been built, copied to model-collect and added to svn."
|
---|
663 | echo "* TO DO: You still need to run svn status and svn commit on the model-collect folder. Besides that:"
|
---|
664 | fi
|
---|
665 | echo
|
---|
666 |
|
---|
667 | if [ "x$mode" != "x" ]; then
|
---|
668 | echo "* DIFFERENCES REMAINING BETWEEN model-collect AND collect (skipping .svn folders):"
|
---|
669 | echo
|
---|
670 | if [ "$1" == "" ]; then
|
---|
671 | echo "---START DIFF---"
|
---|
672 | diff -rq model-collect collect | grep -v ".svn"
|
---|
673 | else
|
---|
674 | for collection in "$@"; do
|
---|
675 | echo "--COLLECTION: $collection"
|
---|
676 | diff -rq model-collect/$collection collect/$collection | grep -v ".svn"
|
---|
677 | echo "--"
|
---|
678 | done
|
---|
679 | fi
|
---|
680 | echo "---END DIFF---"
|
---|
681 | echo
|
---|
682 | fi
|
---|
683 |
|
---|
684 | if [ -e collect_orig ]; then
|
---|
685 | echo "* The original collect directory has been left renamed as collect_orig"
|
---|
686 | echo
|
---|
687 | fi
|
---|
688 |
|
---|
689 | if [ "$debug_mode" -eq "1" ]; then
|
---|
690 | echo "* This script was run in DEBUG MODE, nothing has been changed in svn"
|
---|
691 | fi
|
---|
692 | echo
|
---|
693 | echo "*****************************************"
|
---|
694 | echo
|
---|
695 |
|
---|
696 |
|
---|
697 | # deletes empty dirs
|
---|
698 | # find collect/$collection/archives/HASH* -type d -empty -delete
|
---|
699 | # find collect/$collection/index/assoc/HASH* -type d -empty -delete
|
---|
700 |
|
---|
701 | # To recursively delete all empty dirs in the copy of model-collect (since the dirs will not have .svn folders in them anymore)
|
---|
702 | # http://www.commandlinefu.com/commands/view/5131/recursively-remove-all-empty-directories
|
---|
703 | #find collect -type d -empty -delete
|
---|
704 |
|
---|
705 | # The following when put in a separate script file will delete all folders from model-collect that are
|
---|
706 | # empty in the copied collection (all folders which contain only a .svn subfolder in model-collect)
|
---|
707 | # ---------------------------------------------
|
---|
708 | #!/bin/bash
|
---|
709 |
|
---|
710 | #for collection in collect/*; do
|
---|
711 | #escape the filename (in case of space)
|
---|
712 | # collection=`echo $collection | sed 's@ @\\\ @g'`
|
---|
713 |
|
---|
714 | #get just the basename
|
---|
715 | # collection=`basename $collection`
|
---|
716 |
|
---|
717 | # HASH dirs that are empty in local collect's archives and index/assoc,
|
---|
718 | # need to be removed from the svn in model-collect
|
---|
719 |
|
---|
720 | # for line in `find collect/$collection/archives/HASH* -type d -empty`; do
|
---|
721 | # modelline="model-$line"
|
---|
722 | # echo "LINE: $modelline"
|
---|
723 |
|
---|
724 | # remove from svn of model collect
|
---|
725 | # svn rm $modelline
|
---|
726 | ## rm -rf $modelline
|
---|
727 | # remove physically from local collect
|
---|
728 | # rm -rf $line
|
---|
729 | # done
|
---|
730 |
|
---|
731 | # for line in `find collect/$collection/index/assoc/HASH* -type d -empty`; do
|
---|
732 | # modelline="model-$line"
|
---|
733 | # echo "LINE: $modelline"
|
---|
734 |
|
---|
735 | # remove from svn of model collect
|
---|
736 | # svn rm $modelline
|
---|
737 | ## rm -rf $modelline
|
---|
738 | # remove physically from local collect
|
---|
739 | # rm -rf $line
|
---|
740 | # done
|
---|
741 |
|
---|
742 | #done
|
---|
743 | # ---------------------------------------------
|
---|