Subversion release script

I wrote a script to manage project releases for ProgClub. Basically you pass the project name to the script, and it will create a release tag in tags/release/year/month/day/serial and update tags/latest with the latest release.

#!/bin/bash
if [ "$1" = "" ]; then
  echo "Expected project parameter.";
  exit 1;
fi
if [ "$2" = "" ]; then
  echo "Expected comment parameter.";
  exit 2;
fi
pcrepo="https://www.progclub.org/svn/pcrepo";
project="$1";
comment="$2";
echo Releasing $project;
svn info $pcrepo/$project 2> /dev/null > /dev/null
if [ "$?" -ne "0" ]; then
  echo $project does not exist.
  exit 3;
fi
year="`date --utc +%Y`";
month="`date --utc +%m`";
day="`date --utc +%d`";
serial="0";
serial_formatted="0";
svn_status="0";
while [ "$svn_status" = "0" ]; do
  serial="`echo \"$serial + 1\"|bc`";
  if [ "$serial" = "100" ]; then
    echo "Out of serial numbers. You can't do any more releases today. Take a break!";
    exit 4;
  fi
  less_than_ten="`echo \"$serial < 10\"|bc`";
  serial_formatted=$serial;
  if [ "$less_than_ten" = "1" ]; then
    serial_formatted="0$serial";
  fi
  url="$pcrepo/$project/tags/release/$year/$month/$day/$serial_formatted";
  echo Checking availability of release: $url
  svn info $url 2> /dev/null > /dev/null
  svn_status="$?";
done
trunk_url="$pcrepo/$project/trunk";
svn copy $trunk_url $url -m "Releasing $project: $year-$month-$day-$serial_formatted. $comment" --parents
latest_url="$pcrepo/$project/tags/latest";
svn delete $latest_url -m "Updating $project/tags/latest...";
svn copy $url $latest_url -m "Updating $project/tags/latest. $comment";

Leave a Reply