Created
October 26, 2012 22:05
-
-
Save beryllium/3961840 to your computer and use it in GitHub Desktop.
Automatic SVN synchronization with UUID autocopy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# autosvnsync.sh is a tool for automatically synchronizing/mirroring SVN repositories. | |
# By default, the script assumes that you have configured a "syncuser" account on the SRC and DEST servers, | |
# and that you are running the script as "syncuser" on the DEST server (presumably behind a firewall). | |
#Remote SVN info | |
SVN_HOST="[email protected]" #User and host, for SSH - alternatively, you can use ~/.ssh/config to specialize something | |
SVN_LOC="data/svn" | |
SVN_REPO="svn+ssh://$SVN_HOST/$SVN_LOC" | |
#Local SVN info | |
SYNC_LOC="/data/svnsync" | |
#Retrieve the list of repositories and UUIDs from the remote server | |
REPOS=`ssh $SVN_HOST 'for uuid_file in \`find /$SVN_LOC -type f -name uuid\`; do echo \`echo $uuid_file | cut -f4 -d'/'\`,\`cat $uuid_file\`; done'` | |
# refresh_repo function | |
# Example: | |
# refresh_repo $REPO $UUID $SVN_LOC | |
# | |
# Note: I'm fairly certain that it is simply pulling the variables from the environment names, and not importing them | |
# into the scope. So that means that strictly speaking, I should be using $1/$2/$3/$4 notation. I think. | |
# However, for the sake of readability, I am leaving it as-is. | |
refresh_repo () | |
{ | |
INITIALIZE="false" | |
echo "Processing $REPO for UUID $UUID in $SYNC_LOC/$REPO for repo $SVN_REPO/$REPO" | |
cd $SYNC_LOC | |
if [ ! -d $REPO ] | |
then | |
echo "... Creating repository $REPO" | |
svnadmin create $REPO | |
echo "... Setting UUID to match source repository" | |
svnadmin setuuid $REPO $UUID | |
echo "... Setting INITALIZE flag to true" | |
INITIALIZE="true" | |
else | |
echo "... Repository $REPO has already been created" | |
fi | |
if [ ! -f "$SYNC_LOC/$REPO/hooks/pre-revprop-change" ] | |
then | |
echo "... Creating hook pre-revprop-change" | |
cat > "$SYNC_LOC/$REPO/hooks/pre-revprop-change" <<'EOF' | |
#!/bin/sh | |
USER="$3" | |
if [ "$USER" = "syncuser" ]; then exit 0; fi | |
echo "Only the syncuser user may change revision properties" >&2 | |
exit 1 | |
EOF | |
chmod 755 "$SYNC_LOC/$REPO/hooks/pre-revprop-change" | |
INITIALIZE="true" | |
else | |
echo "... Hook pre-revprop-change already exists" | |
fi | |
if [ ! -f "$SYNC_LOC/$REPO/hooks/start-commit" ] | |
then | |
echo "... Creating hook start-commit" | |
cat > "$SYNC_LOC/$REPO/hooks/start-commit" <<'EOF' | |
#!/bin/sh | |
USER="$2" | |
if [ "$USER" = "syncuser" ]; then exit 0; fi | |
echo "Only the syncuser user may commit new revisions" >&2 | |
exit 1 | |
EOF | |
chmod 755 "$SYNC_LOC/$REPO/hooks/start-commit" | |
INITIALIZE="true" | |
else | |
echo "... Hook start-commit already exists" | |
fi | |
if [ "$INITIALIZE" = "true" ] | |
then | |
echo "... Initializing svnsync" | |
svnsync initialize "file://$SYNC_LOC/$REPO" "$SVN_REPO/$REPO" | |
else | |
echo "... Initialization already performed" | |
fi | |
echo "... Synchronizing" | |
svnsync synchronize --non-interactive "file://$SYNC_LOC/$REPO" | |
if [ "$?" -ne 0 ] | |
then | |
echo "... *** ERROR ***" | |
else | |
echo "... Done." | |
fi | |
} | |
for i in $REPOS | |
do | |
REPO=`echo $i | cut -f1 -d','` | |
UUID=`echo $i | cut -f2 -d','` | |
refresh_repo $REPO $UUID $SYNC_LOC | |
echo | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment