#!/bin/bash version=0.10 program=${0##*/} progdir=${0%/*} if [ "$progdir" = "$program" ]; then progdir="."; fi # ---------------------------------------------------------------------- function usage() { cat < COPYRIGHT Copyright 2007 The IETF Trust. EOF } # ---------------------------------------------------------------------- function die() { echo -e "\n$program: error: $*" > /dev/stderr exit 1 } function note() { if [ -n "$VERBOSE" ]; then echo -e "$*"; fi } # ---------------------------------------------------------------------- function version() { echo -e "$program $version" } # ---------------------------------------------------------------------- trap 'echo "$program($LINENO): Command failed with error code $? ([$$] $0 $*)"; exit 1' ERR # ---------------------------------------------------------------------- # Option parsing # Options shortopts=hnvV longopts=help,dry-run,verbose,version # Default values MSG="" VERFILE=ietf/__init__.py SETTINGS=ietf/settings.py do="" if [ "$(uname)" = "Linux" ]; then args=$(getopt -o "$shortopts" --long "$longopts" -n '$program' -- $SV "$@") if [ $? != 0 ] ; then die "Terminating..." >&2 ; exit 1 ; fi eval set -- "$args" sed="sed -r" else # Darwin, BSDs args=$(getopt -o$shortopts $SV $*) if [ $? != 0 ] ; then die "Terminating..." >&2 ; exit 1 ; fi set -- $args sed="sed -E" fi while true ; do case "$1" in -h| --help) usage; exit;; # Show this help, then exit -m| --message) MSG=$2; shift;; # Specify a commit message -n| --dry-run) do="echo";; # Show what would be done -v| --verbose) VERBOSE=1;; # Be more talkative -V| --version) version; exit;; # Show program version, then exit --) shift; break;; *) die "Internal error, inconsistent option specification: '$1'";; esac shift done # ---------------------------------------------------------------------- # The program itself ARGMIN=1 if [ $# -lt $ARGMIN ]; then usage die "$# arguments found, $ARGMIN required" fi VER=$1 REPO=$(svn info | grep "^Repository Root:" | awk '{ print $3 }') RURL=$(svn info | grep "^URL:" | awk '{ print $2 }') RDIR=${RURL#$REPO} DIR=${RDIR#/} if [ -z "$DIR" ]; then die "Couldn't find anything to release here" elif [ "${DIR%%/*}" = "trunk" ]; then SRC="trunk" elif [ "${DIR%%/*}" = "branch" ]; then tmp=${DIR#*/} # get rid of 'branch/' SRC="branch/${tmp%%/*}" # keep first subdir under branch/ fi note "" note "Releasing from $SRC" note "Locating the root of the working copy..." while [ "${#DIR}" -gt "${#SRC}" ]; do [ "$DIR" = "$prev" ] && die "Internal error" cd .. note " now at $PWD" prev=$DIR DIR=${DIR%/*} done if [ "$DIR" != "$SRC" ]; then die "Couldn't find the root of your '$SRC' working copy" fi REPO=${REPO%/} # remove trailing slash SRC=${SRC#/} # remove leading slash MAJOR=${VER%.*} MINOR=${VER#*.} VER="$(printf %d.%02d $MAJOR $MINOR)" NEXT=$(( $MINOR + 1 )) DEV="$(printf %d.%02d-dev $MAJOR $NEXT)" note "Verifying that version $VER doesn't already exist..." svn info $REPO/tags/$VER 2>&1 | grep -q "Not a valid URL" || die "The tag '$VER' already exists (or there was an error testing for it)." note " Ok" note "Verifying there's no uncommitted changes..." $do svn st | grep "^[AMGRD] " && die "There seems to be uncommitted changes in this working copy" note "\nUpdating the version info in $VERFILE and making sure'\$Rev\$' is Ok" $do sed -i -r -e "/^__version__/s/\"[.0-9]+(-dev)?\"/\"$VER\"/" \ -e "/^__rev__/s/\".*\"/\"\$Rev:\$\"/" \ $VERFILE note "\nUpdating the deployment settings in settings.py" $do sed -i -r -e 's/^DEBUG *= *.*$/DEBUG = False/' \ -e "s/^SERVER_MODE *= *.*\$/SERVER_MODE = 'production'/" \ $SETTINGS note "\nCommitting version information for version $VER: $MSG" $do svn commit $VERFILE $SETTINGS -m "Set version info to release version $VER before branching. $MSG" note "\nCreating new tag 'tags/$VER' from $SRC" $do svn cp $REPO/$SRC $REPO/tags/$VER -m "Creating new tag 'tags/$VER' from $SRC" note "\nUpdating version and revision info to indicate that the source and branch aren't releases" $do sed -i -r -e "/^__version__/s/\"[0-9.]*\"/\"$DEV\"/" \ -e "/^__rev__/s/\"\\\$Rev: (.*) \\\$\"/\"\$Rev:\$ (dev) Latest release: Rev. \1 \"/" \ $VERFILE note "\nUpdating the deployment settings in settings.py to development mode" $do sed -i -r -e 's/^DEBUG *= *.*$/DEBUG = True/' \ -e "s/^SERVER_MODE *= *.*\$/SERVER_MODE = 'development'/" \ $SETTINGS note "\nCommitting the updated version and deployment settings" $do svn commit $VERFILE $SETTINGS -m "Set version info and settings back to development mode" # if SRC is 'trunk', then also create a new branch if [ $SRC = "trunk" ]; then if svn info $REPO/branch/$VER 2>&1 | grep -q "Not a valid URL"; then note "\nCreating new branch 'branch/$VER' from $SRC" $do svn cp $REPO/$SRC $REPO/branch/$VER -m "Creating new branch 'branch/$VER' from $SRC" fi note "\nUpdating version and revision info on trunk" $do sed -i -r -e "/^__version__/s/\"[0-9.]*\"/\"$MAJOR.xx-trunk\"/" \ -e "/^__rev__/s/\"\\\$Rev: (.*) \\\$\"/\"\$Rev:\$ (dev) Latest release: Rev. \1 \"/" \ $VERFILE note "Commit version information '$MAJOR.xx-trunk'" $do svn commit $VERFILE $SETTINGS -m "Set version of the trunk to $MAJOR.xx-trunk after branching off $VER" fi $do svn update