svn-tools: mysvn

Scenario: subversion repository installed on a home-server. Sometimes you need to interact with it from the L.A.N. and sometimes from internet.

This script other then being a wrapper for svn, checks whether the working copy needs to be relocated or not before the operations.

#!/usr/bin/env bash

GATEWAY_IP=192.168.0.254
GATEWAY_MAC=00:14:6c:ab:d2:ca
REPO_LOCAL=192.168.0.4
REPO_REMOTE=code.matteolandi.net

arp -a | grep $GATEWAY_MAC > /dev/null
if [ $? -eq 0 ]; then
 source=$REPO_REMOTE
 destination=$REPO_LOCAL
else
 source=$REPO_LOCAL
 destination=$REPO_REMOTE
fi

url_before=$(svn info | grep URL | cut -d ' ' -f 2)
url_after=${url_before/$source/$destination}

if [ "$url_before" != "$url_after" ]; then
 echo "Relocating ${url_before} -> ${url_after}"
 svn switch --relocate $url_before $url_after
 if [ $? -ne 0 ]; then
   exit 1
 fi
fi

svn $@

I know you could create a new entry inside /etc/hosts and use it depending on the situation, but easy solutions are not my best!

Obviously you will find it inside the hacks/svn-tools repository.

Tags: ,

Leave a Reply