Thursday, June 24, 2010

Daily SVN report script

How can i get svn log information for my own commits? How can i see what i committed on a specific day? How do i list all svn repositories i'm working on?


#!/bin/bash
#
# svn_daily_report.sh
#
# A script to extract SVN log info for all repositories you're working on,
# yielding only your own commits, on a particular day.
#
# The script does this:
# * find unique repository roots you're working on
# * get the revision numbers for your own commits in each repo
# * print the full log for each of these revisions
#
# Syntax: svn_daily_report.sh [DATE1] [DATE2]
#
# DATE1 is an optional argument in the format yyyy-mm-dd. If DATE1 is not
# present, today is assumed. DATE2 is an optional end date, the default is
# DATE1.
#
# As this may take a long time, you may want to write the output to a
# file: svn_daily_report.sh 2>&1 | tee -a /tmp/svn_daily_report.txt
#
# TODO:
#
# * Allow passing usernames and directories from the command line

# Set your SVN username. You can set multiple SVN usernames (handy if the
# same person has a different username for different repositories) by
# delimiting them with \|.
username="hink\|khink"

if [ ! -n "$1" ]
then
# No date set; use today
date1=`date +%F`
date2=$date1
else
date1=$1
if [ ! -n "$2" ]
then
# No end date set; using start date
date2=$date1
else
date2=$2
fi
fi
echo "Looking for $username's repository changes from $date1 00:00 to $date2 23:59"

# Find unique repository roots below current working directory
for repo in `find . -name .svn -type d | sed 's/\(.*\).svn$/\1/' | xargs svn info | sed -n 's/^Repository Root: *//p' | sort | uniq`;
do
echo "Repository root: $repo"
# Find all svn revision numbers made in this timespan by this svn user
for revision in `svn log -qr {"$date1 00:00"}:{"$date2 23:59"} $repo | sed -n "s/r\([0-9]*\) | \($username\) |.*/\1/p"`
do
# Print log info
svn log -vr $revision $repo
done
echo
done

Monday, June 21, 2010

VirtualBox kernel module loading script

When starting VirtualBox (on Ubuntu Lucid), i have to load the kernel modules vboxdrv and vboxnetflt. I created a script to do this automatically. Call it virtualbox and place it somewhere on your $PATH, for example in ~/bin/, so the application launcher in the menu will use the script instead of the binary in /usr/bin/.


#!/bin/bash

# Custom VirtualBox OSE startup script; loads kernel modules

echo "Starting kernel module loading script";
for module in vboxdrv vboxnetflt
do
echo "Testing kernel module $module";
if [ `lsmod | grep $module | wc -l` == '0' ]; then
echo "Module $module not yet installed, installing... "
gksudo modprobe $module
echo "done."
else
echo "Module $module already installed; skipping"
fi
done
/usr/bin/virtualbox

Thursday, June 17, 2010

SVN: How to get the changes for one revision

I was looking for a shortcut to svn diff -r N-1:N. Turns out it's -c:
svn diff -c N

Tuesday, June 15, 2010

Using an ssh tunnel to manage your production site

Update (2010-10-20): Script to shorten the command, use hostname instead of IP

Probably, your production servers run behind Apache or some other webserver stack. To manage these portals, ZMI access can be handy, but the Zope port is not exposed to the outside world. You could solve this with an Apache proxy or rewrite rule, but I find it easier to start an SSH tunnel.

Suppose your Zope runs on port 8080, on server myserver.mydomain.com on 11.22.33.44, where you have an account for username.

ssh -L 8765:11.22.33.44:8080 myserver.mydomain.com -l username -N


This will make your Zope accessible locally on port 8765. Here you can add Plone instance, look into their custom skins folders, and do whatever else you need to do.

For detailed info on ssh -L, see the manual pages.

You can also use a hostname instead of the IP address.

And if you get tired of typing this long command, you might want to use this script:

#!/bin/bash
#
# ssh-tunnel.sh
# Shortcut to set up an SSH tunnel with concise syntax.
#
# Usage: ssh-tunnel.sh username hostname portnumber
#
# This assumes you want set op a tunnel to a host that you know by its hostname.
#
# To keep it simple, the remote port number will also be used locally.

# TODO: test parameters present
USER=$1
HOST=$2
REMOTE_PORT=$3
# TODO: allow for optional LOCAL_PORT
SSH='/usr/bin/ssh'

# TODO: allow for optional LOCAL_PORT
# TODO: allow for any hostname, also if not defined in /etc/hosts
COMMAND="$SSH -L $REMOTE_PORT:$HOST:$REMOTE_PORT $HOST -l $USER -N"

# Show what we're going to do
echo $COMMAND
# Do it
$COMMAND