Ignore:
Timestamp:
2013-08-15T20:28:00+12:00 (11 years ago)
Author:
ak19
Message:
  1. When run in svnupdate mode, the script now performs an svn add on all the new items added to both model-collect's archives and index. There's a handy command that does a recursive add on all new items in a folder. 2. Added the commit_message and debug flags as cmdline args. Note that now x is the cmdline argument shortcut for svndelete and d is the shortcut for debug mode. Running in debug mode means nothing gets committed to svn, but you get to see what the changes made to model-collect are.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • other-projects/nightly-tasks/diffcol/trunk/gen-model-colls.sh

    r28049 r28069  
    7272# http://stackoverflow.com/questions/1301203/removing-svn-files-from-all-directories
    7373
     74#*******************************GLOBAL VARIABLES***************************
     75
     76# mode can be svndelete or svnupdate
     77mode=
     78debug_mode=0
     79commit_message=
     80
     81#*****************************FUNCTIONS*****************************
    7482
    7583# DON'T ADD ANY FURTHER ECHO STATEMENTS IN FUNCTION get_col_basename
     
    113121    fi
    114122
    115     # commit all the svn rm statements done above in one go:
    116     # don't do `svn up` here, as this will then retrieve all the folders that were svn-removed
    117     svn commit -m "AUTOCOMMIT by gen-model-colls.sh script. Clean rebuild of model collections 1/2. Clearing out deprecated archives and index." model-collect
    118 
    119     # do an svn up to locally delete what was svn-removed above, BEFORE copying from the rebuilt archives and index folders
    120     svn up model-collect
    121 
     123    # svn commit all the svn rm statements done above in one go:
     124    # don't do `svn up` at this point, as doing so will then retrieve all the folders that just were svn-removed
     125
     126    if [ "x$commit_message" == "x" ]; then
     127    commit_message="Clean rebuild of model collections 1/2. Clearing out deprecated archives and index."
     128    fi
     129
     130    # Numerical comparisons: http://tldp.org/LDP/abs/html/comparison-ops.html
     131    if [ "$debug_mode" -eq "0" ]; then
     132    svn commit -m "AUTOCOMMIT by gen-model-colls.sh script. Message: $commit_message" model-collect
     133    fi
     134
     135    # Having svn committed the deletes, do an svn up to locally delete what was svn-removed above,
     136    # BEFORE copying from the rebuilt archives and index folders
     137    if [ "$debug_mode" -eq "0" ]; then
     138    svn up model-collect   
     139    fi
     140
     141    # copy from the rebuilt archives and index over into the svn model-collect and svn add them
    122142    if [ "x$1" == "x" ]; then
    123143    for collection in collect/*; do     
     
    131151
    132152    # commit all the svn add statements done just above in one go
    133     svn commit -m "AUTOCOMMIT by gen-model-colls.sh script. Clean rebuild of model collections 2/2. Adding rebuilt archives and index." model-collect
     153    if [ "x$commit_message" == "x" ]; then
     154    commit_message="Clean rebuild of model collections 2/2. Adding rebuilt archives and index."
     155    fi
     156
     157    if [ "$debug_mode" -eq "0" ]; then
     158    svn commit -m "AUTOCOMMIT by gen-model-colls.sh script. Message: $commit_message" model-collect
     159    fi
    134160
    135161    echo
     
    159185
    160186    # remove the entire archives and index folders from svn
    161     svn rm model-collect/$collection/archives
    162     svn rm model-collect/$collection/index
    163 
    164 # for TESTING purposes:
    165 #    rm -rf model-collect/$collection/archives
    166 #    rm -rf model-collect/$collection/index
     187    if [ "$debug_mode" -eq "0" ]; then
     188    svn rm model-collect/$collection/archives
     189    svn rm model-collect/$collection/index
     190    elif [ "$debug_mode" -eq "1" ]; then
     191    rm -rf model-collect/$collection/archives
     192    rm -rf model-collect/$collection/index
     193    fi
    167194
    168195}
     
    184211    cp -r collect/$collection/archives model-collect/$collection/.
    185212    cp -r collect/$collection/index model-collect/$collection/.
    186    
    187     svn add model-collect/$collection/archives
    188     svn add model-collect/$collection/index
     213
     214    if [ "$debug_mode" -eq "0" ]; then
     215    svn add model-collect/$collection/archives
     216    svn add model-collect/$collection/index
     217    fi
    189218}
    190219
     
    252281    cp -r collect/$collection/index/* model-collect/$collection/index/.
    253282
     283    # now svn add any and all the NEW items in model-collect's archives and index
     284    # see http://stackoverflow.com/questions/1071857/how-do-i-svn-add-all-unversioned-files-to-svn
     285#    if [ "$debug_mode" -eq "0" ]; then
     286    svn add --force model-collect/$collection/archives/* --auto-props --parents --depth infinity -q
     287    svn add --force model-collect/$collection/index/* --auto-props --parents --depth infinity -q
     288#    fi
     289
    254290    echo "svn model-collect update process complete. CHECK AND COMMIT THE model-collect FOLDER!"
    255291
     
    296332
    297333
    298 # The program starts here
     334#*******************************MAIN PROGRAM***************************
    299335
    300336# process optional command line arguments
    301337# http://blog.onetechnical.com/2012/07/16/bash-getopt-versus-getopts/
    302338# Execute getopt
    303 ARGS=$(getopt -o ud -l "svnupdate,svndelete" -n "$0" -- "$@");
     339ARGS=$(getopt -o m:uxd -l "message:,svnupdate,svndelete,debug" -n "$0" -- "$@");
    304340
    305341#Bad arguments
     
    311347eval set -- "$ARGS";
    312348
    313 # mode can be svndelete or svnupdate
    314 mode=
    315349
    316350# -n: http://tldp.org/LDP/abs/html/testconstructs.html
    317351while true; do
    318352  case "$1" in
    319     -d|--svndelete)
     353    -x|--svndelete)
    320354      shift;
    321355      if [ "x$mode" == "xsvnupdate" ]; then
     
    339373      fi
    340374      ;;
     375    -d|--debug)
     376      shift;
     377      debug_mode=1
     378      ;;
     379    -m|--message)
     380      shift;
     381      if [ -n "$1" ]; then
     382      commit_message=$1
     383          shift;
     384      fi
     385      ;;
    341386    --)
    342387      shift;
     
    345390  esac
    346391done
     392
     393#echo "commit message: $commit_message"
     394#echo "Debug mode is: $debug_mode"
     395#exit
    347396
    348397# If no mode provided (svndelete|svnupdate) as cmd line arg, then don't modify
     
    390439    else
    391440    for collection in "$@"; do
    392         if [ -e model-collect/$collection ]; then
    393         svn up model-collect/$collection
    394         else
    395         svn up model-collect
    396         fi
     441        svn up model-collect/$collection
    397442    done
    398443    fi
     
    512557    echo "* DIFFERENCES REMAINING BETWEEN model-collect AND collect (skipping .svn folders):"
    513558    echo
    514     echo "---START DIFF---"
    515     diff -rq model-collect collect | grep -v ".svn"
     559    if [ "$1" == "" ]; then
     560    echo "---START DIFF---"
     561    diff -rq model-collect collect | grep -v ".svn"
     562    else
     563    for collection in "$@"; do
     564        echo "--COLLECTION: $collection"
     565        diff -rq model-collect/$collection collect/$collection | grep -v ".svn"
     566        echo "--"
     567    done
     568    fi
    516569    echo "---END DIFF---"
    517570    echo
     
    519572
    520573echo "* The original collect directory has been left renamed as collect_orig"
     574echo
     575
     576if [ "$debug_mode" -eq "1" ]; then
     577    echo "* This script was run in DEBUG MODE, nothing has been changed in svn"
     578fi
    521579echo
    522580echo "*****************************************"
Note: See TracChangeset for help on using the changeset viewer.