#!/usr/bin/env bash # svn-mirror --- Keep local mirror of remote svn server # Created: 2010-03-03 # Public domain # $Id: svn-mirror,v 1.2 2016/08/01 14:38:28 friedman Exp $ # Commentary: # Code: get_dst_url() { set : ${1%/}; shift # remove any trailing / case $1 in /* ) echo file://$1 ;; '' ) echo file://`pwd` ;; * ) echo file://`cd "$1" && pwd` ;; esac } get_src_url() { svnlook propget --revprop -r0 "$1" svn:sync-from-url } set_src_url() { local dst_url=`get_dst_url "$1"` local old_src_url=`get_src_url "$1"` case $2 in $old_src_url ) echo Source URL unchanged from $old_src_url return 0 ;; esac if svn propset --revprop -r0 svn:sync-from-url "$2" "$dst_url"; then echo "Old URL: $old_src_url" echo "New URL: $2" fi } svn_setup() { local dst_dir=$1 local src_url=$2 svnadmin create "$dst_dir" echo '#!/bin/sh' > "$dst_dir/hooks/pre-revprop-change" chmod a+x "$dst_dir/hooks/pre-revprop-change" local dst_url=`get_dst_url "$dst_dir"` svnsync init "$dst_url" "$src_url" } svn_sync() { local dst_url=`get_dst_url "$1"` svnsync sync "$dst_url" } usage() { progname=${0##*/} { case $# in 0 ) : ;; * ) echo "$progname: $*"; echo ;; esac echo "Usage: $progname [path to local repository] {remote svn url}" echo echo If the local repository is already present, the url is not required echo and the local repository will just be brought up to date. } 1>&2 exit 1 } main() { case $# in 1|2 ) : ;; * ) usage ;; esac local dst_dir=$1 local src_url=$2 if [ ! -d "$dst_dir/db" ]; then case $src_url in '' ) usage "Need to specify URL to mirror." ;; esac svn_setup "$dst_dir" "$src_url" elif [ -n "$src_url" ]; then set_src_url "$dst_dir" "$src_url" fi svn_sync "$dst_dir" } main "$@" # eof