Date Tags bash / svn

This is a small script to generate code snapshots from the svn repository.

#!/bin/bash
#
# MakeSvnSnapshot.sh
# Purpose: To make easily downloadable (clean) versions of a snapshot of code.
# Intended Use: Called as a daily/weekly/etc cron job
#
# Author: Colin Ross <cross@php.net>
# Modified Pietro Abate <pietro.abate@pps.jussieu.fr>
#
# License:
# This work is licensed under the
# Creative Commons Attribution-Share Alike 2.5 License.
# To view a copy of this license,
# visit http://creativecommons.org/licenses/by-sa/2.5/
# or send a letter to
# Creative Commons
# 543 Howard Street
# 5th Floor
# San Francisco, California, 94105, USA.
#
#

# Ex: MakeSnapshot.sh /tmp http://svn.cduce.org/cduce/trunk
: ${1?"Usage: $0 snapshot-dir svn-url"}

# Creates an up-to-date tgz of the latest svn snapshot
SNAP_DIR=$1
SVN_URI=$2
CUR_DATE=`date +%Y%m%d`

cd $SNAP_DIR

if [ -f .svn-snapshot-log ]; then
  rm .svn-snapshot-log
fi

#if this isn't a working copy
if [ ! -d .src/.svn ]; then
  svn co $SVN_URI .src >> .svn-snapshot-log # check it out
fi
svn cleanup .src

# just update the working copy
svn up .src >> .svn-snapshot-log
# and get the current revision
REV=`svn info .src | grep Revision | cut -f2 -d " "`

# if the REV has changed...
if [ ! -d cduce-svn-$REV ]; then
  #export it to get rid of .svn files
  svn export .src cduce-svn-$REV >> .svn-snapshot-log
  # tgz it up
  tar cvf - cduce-svn-$REV  | gzip > cduce-svn-$REV-$CUR_DATE.tar.gz

  #keep only the latest 10 snapshots
  n=`ls cduce-svn-*.tar.gz| wc -l`
  if [ $n -gt 10 ]; then
      find -ctime +10 -name "*.tgz" -exec mv {} /tmp \;
  fi

  # update the current symlink
  if [ -f cduce-svn-current.tar.gz ]
   then
     rm -f cduce-svn-current.tar.gz
  fi
  ln -s cduce-svn-$REV-$CUR_DATE.tar.gz cduce-svn-current.tar.gz
fi

cd -