Python1320

.svnupdate.sh

Jul 12th, 2011
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.34 KB | None | 0 0
  1. #!/bin/sh
  2. cd "`dirname \"$0\"`" #I want to go home
  3. . ./.header.sh #Folders and such
  4. cdstart
  5.  
  6.  
  7. header "Updating SVNs"
  8.  
  9. SRVUPDATE_ONLY=0
  10. unprotect
  11.     if [[ "$1" == "serversvn" ]]
  12.     then
  13.         SRVUPDATE_ONLY=1
  14.     fi
  15. protect
  16.  
  17. declare -a on_exit_items
  18.  
  19. function on_exit()
  20. {
  21.     for i in "${on_exit_items[@]}"
  22.     do
  23.         #log "Cleanup: $i"
  24.         eval $i
  25.     done
  26. }
  27.  
  28. function add_on_exit()
  29. {
  30.     local n=${#on_exit_items[*]}
  31.     on_exit_items[$n]="$*"
  32.     #log "Cleanup added: $*"
  33.     if [[ $n -eq 0 ]]; then
  34.         trap on_exit EXIT
  35.     fi
  36. }
  37.  
  38.  
  39. addlock () {
  40.     touch "$SVN_LOCKDIR"/"$1"
  41. }
  42. dellock () {
  43.     rm -f "$SVN_LOCKDIR"/"$1"
  44. }
  45.  
  46. checkout () {
  47.     cd "$SVN_FOLDER"/"$file"
  48.         oldrev="REVISION"
  49.         newrev="FAILURE"
  50.        
  51.         oldrev=`cat ".svn/entries" | head -n 4 | tail -n 1` || true
  52.             svn update -q --accept "theirs-full" --force --non-interactive --trust-server-cert || err "Svn update failed: $file"
  53.         newrev=`cat ".svn/entries" | head -n 4 | tail -n 1` || true
  54.        
  55.         if [[ "$oldrev" != "$newrev" ]]
  56.         then
  57.             log "Updated $file | $oldrev -> $newrev"
  58.         fi
  59.        
  60.     cdstart
  61. }
  62.  
  63. ## THREAD ##
  64. updatesvn ()
  65. {
  66.         file=$1
  67.  
  68.         addlock "$file" || fatal "lock creation failed"
  69.             checkout "$file" || err "svn system failure!!"
  70.         dellock "$file" || err "lock removal failed??"
  71.        
  72. }
  73.  
  74. if [[ -d "$SVN_LOCKDIR" ]]; then
  75.     header "Cleaning SVN lockdir"
  76.     rm -rf "$SVN_LOCKDIR"/*
  77. fi
  78. mkdir -p "$SVN_LOCKDIR"|| fatal "Could not create locks folder"
  79. add_on_exit rm -rf "$SVN_LOCKDIR"
  80.  
  81. initate_update() {
  82.     cd "$SVN_FOLDER"|| fatal "no svn addons folder found"
  83.         for file in * ## All SVN folders
  84.         do
  85.                 # check if its a dir and a repo and has no noupdate flag    or   if it's our special folder..
  86.                 unprotect
  87.                     if ( [[ -d "$file" ]] && [[ -d "$file"/.svn ]]  && [[ ! -f "$file"/.noupdate ]] ) && ( [ $SRVUPDATE_ONLY != 1 ] || [[ -f "$file"/.serversvn ]] )
  88.                     then
  89.                         protect
  90.                         #log "Updating SVN $file"
  91.                         updatesvn "$file" & # async is async.
  92.                        
  93.                         sleep 0.3 # So we don't kill/dos the server
  94.                        
  95.                     fi
  96.                 protect
  97.         done
  98.     cdstart
  99. }
  100. initate_update
  101.  
  102. sleep 1 # :v
  103.  
  104.  
  105. # WAIT FOR LOCK FILES TO CLEAR OUT
  106. wait_locks() {
  107.     cd "$SVN_LOCKDIR"||fatal "Lock dir failed??"
  108.         while [ $(ls -1A | wc -l) -ne 0 ]
  109.         do
  110.             header "SVN Updaters: `(ls -1A | wc -l)` "
  111.             sleep 0.2
  112.         done
  113.     cdstart
  114. }
  115. wait_locks
  116.  
  117. exit 0
Advertisement
Add Comment
Please, Sign In to add comment