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