Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- cd "`dirname \"$0\"`" #I want to go home
- . ./.header.sh #Folders and such
- cdstart
- header "Updating SVNs"
- SRVUPDATE_ONLY=0
- unprotect
- if [[ "$1" == "serversvn" ]]
- then
- SRVUPDATE_ONLY=1
- fi
- protect
- declare -a on_exit_items
- function on_exit()
- {
- for i in "${on_exit_items[@]}"
- do
- #log "Cleanup: $i"
- eval $i
- done
- }
- function add_on_exit()
- {
- local n=${#on_exit_items[*]}
- on_exit_items[$n]="$*"
- #log "Cleanup added: $*"
- if [[ $n -eq 0 ]]; then
- trap on_exit EXIT
- fi
- }
- addlock () {
- touch "$SVN_LOCKDIR"/"$1"
- }
- dellock () {
- rm -f "$SVN_LOCKDIR"/"$1"
- }
- checkout () {
- cd "$SVN_FOLDER"/"$file"
- oldrev="REVISION"
- newrev="FAILURE"
- oldrev=`cat ".svn/entries" | head -n 4 | tail -n 1` || true
- svn update -q --accept "theirs-full" --force --non-interactive --trust-server-cert || err "Svn update failed: $file"
- newrev=`cat ".svn/entries" | head -n 4 | tail -n 1` || true
- if [[ "$oldrev" != "$newrev" ]]
- then
- log "Updated $file | $oldrev -> $newrev"
- fi
- cdstart
- }
- ## THREAD ##
- updatesvn ()
- {
- file=$1
- addlock "$file" || fatal "lock creation failed"
- checkout "$file" || err "svn system failure!!"
- dellock "$file" || err "lock removal failed??"
- }
- if [[ -d "$SVN_LOCKDIR" ]]; then
- header "Cleaning SVN lockdir"
- rm -rf "$SVN_LOCKDIR"/*
- fi
- mkdir -p "$SVN_LOCKDIR"|| fatal "Could not create locks folder"
- add_on_exit rm -rf "$SVN_LOCKDIR"
- initate_update() {
- cd "$SVN_FOLDER"|| fatal "no svn addons folder found"
- for file in * ## All SVN folders
- do
- # check if its a dir and a repo and has no noupdate flag or if it's our special folder..
- unprotect
- if ( [[ -d "$file" ]] && [[ -d "$file"/.svn ]] && [[ ! -f "$file"/.noupdate ]] ) && ( [ $SRVUPDATE_ONLY != 1 ] || [[ -f "$file"/.serversvn ]] )
- then
- protect
- #log "Updating SVN $file"
- updatesvn "$file" & # async is async.
- sleep 0.3 # So we don't kill/dos the server
- fi
- protect
- done
- cdstart
- }
- initate_update
- sleep 1 # :v
- # WAIT FOR LOCK FILES TO CLEAR OUT
- wait_locks() {
- cd "$SVN_LOCKDIR"||fatal "Lock dir failed??"
- while [ $(ls -1A | wc -l) -ne 0 ]
- do
- header "SVN Updaters: `(ls -1A | wc -l)` "
- sleep 0.2
- done
- cdstart
- }
- wait_locks
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment