#!/bin/bash # # Create a new development branch for a module. # THIS HAS TO BE RUN ON THE CVS SERVER! # WARNING: # This file is maintained under $CVSROOT/CVSROOT/admin via CVS. # All changes to the plaintext copy on the CVS server will be lost. # $Id: mkbranch,v 1.11 2008/04/22 16:43:50 toshio Exp $ # Figure out the environment we're running in RUNDIR=$(cd $(dirname $0) && pwd) CVSROOT=$(cd $RUNDIR/.. && pwd) # check if a moron is driving me if [ -d $RUNDIR/CVS ] ; then # we're obviously in a checkout echo "ERROR: This script has to be run on the CVS server." echo "ERROR: Homer sez 'Duh'." exit -9 fi # where are the packages kept TOPLEVEL=rpms # Local variables VERBOSE=0 TEST= IGNORE= BRANCH="" PACKAGES="" SRC_BRANCH="devel" Usage() { cat <] ... Creates a new branch for the list of s Options: -s,--source= Use as the source branch. Defaults is devel/ -n,--test Don't do nothing, only test -i,--ignore Ignore erroneous modules -h,--help This help message -v,--verbose Increase verbosity EOF } # parse the arguments while [ -n "$1" ] ; do case "$1" in -h | --help ) Usage exit 0 ;; -v | --verbose ) VERBOSE=$(($VERBOSE + 1)) ;; -i | --ignore ) IGNORE="yes" ;; -n | --test ) TEST="yes" ;; -s | --source ) shift SRC_BRANCH=$1 ;; -b | --branch ) shift BRANCH=$1 ;; * ) if [ -z "$BRANCH" ] ; then BRANCH="$1" else PACKAGES="$PACKAGES $1" fi ;; esac shift done # check the arguments if [ -z "$BRANCH" -o -z "$PACKAGES" ] ; then Usage exit -1 fi # Sanity checks before we start doing damage NEWP= for p in $PACKAGES ; do [ $VERBOSE -gt 1 ] && echo "Checking package $p..." if [ ! -d $CVSROOT/$TOPLEVEL/$p ] ; then echo "ERROR: Package module $p is invalid" >&2 [ "$IGNORE" = "yes" ] && continue || exit -1 fi if [ ! -d $CVSROOT/$TOPLEVEL/$p/$SRC_BRANCH ] ; then echo "ERROR: Invalid source branch '$SRC_BRANCH' for package $p" >&2 [ "$IGNORE" = "yes" ] && continue || exit -1 fi if [ -d $CVSROOT/$TOPLEVEL/$p/$BRANCH ] ; then echo "IGNORING: Package module $p already has a branch directory $BRANCH" >&2 [ "$IGNORE" = "yes" ] && continue || exit -1 fi NEWP="$NEWP $p" done PACKAGES="$(echo $NEWP)" if [ -z "$PACKAGES" ] ; then echo "NOOP: no valid packages found to process" exit -1 fi if [ -n "$TEST" ] ; then echo "Branch $BRANCH valid for $PACKAGES" exit 0 fi # cvs despises anybody logged in as root. Therefore this account must # have the proper permissions as to not screw up the repository work. if [ "$(id -un)" = "root" ] ; then echo "ERROR: CVS does not allow 'root' to commit files." echo "Please run this script as yourself" exit -3 fi # "global" permissions check if [ ! -w $CVSROOT ] ; then echo "ERROR: You can not write to $CVSROOT" echo "ERROR: You can not perform branching operations" exit -1 fi # Now start working on creating those branches # XXX: the CVS server is locked down, so presumably we don't have no # fuzzy /tmp/ shite going on TMPDIR=$(mktemp -d /tmp/tmpXXXXXX) # Check out the CVSROOT to update the modules file as we go [ $VERBOSE -gt 0 ] && echo "Checking out the modules file..." pushd $TMPDIR >/dev/null cvs -d $CVSROOT -Q checkout modules cd modules # For every module, "create" the branch for NAME in $PACKAGES ; do echo echo "Creating new module branch '$BRANCH' for '$NAME' from branch '$SRC_BRANCH'..." # permissions checks for this particular module for d in $CVSROOT/$TOPLEVEL/$NAME $CVSROOT/$TOPLEVEL/$NAME/$SRC_BRANCH ; do if [ ! -w $d ] ; then echo "ERROR: You can not write to $d" echo "ERROR: $NAME can not be branched by you" continue fi done [ $VERBOSE -gt 0 ] && echo "Creating $BRANCH-split tag for $NAME/$SRC_BRANCH..." cvs -Q rtag -f "$BRANCH-split" $TOPLEVEL/$NAME/$SRC_BRANCH || { echo "ERROR: Branch split tag for $NAME/$SRC_BRANCH could not be created" >&2 exit -2 } [ $VERBOSE -gt 0 ] && echo "Copying files from $NAME/$SRC_BRANCH to $NAME/$BRANCH..." cp -a $CVSROOT/$TOPLEVEL/$NAME/$SRC_BRANCH $CVSROOT/$TOPLEVEL/$NAME/$BRANCH [ $VERBOSE -gt 0 ] && echo "Creating $BRANCH-start tag for $NAME/$BRANCH..." cvs -Q rtag -f "$BRANCH-start" $TOPLEVEL/$NAME/$BRANCH || { echo "ERROR: Branch start tag for $NAME/$BRANCH could not be created" >&2 rm -rf $CVSROOT/$TOPLEVEL/$NAME/$BRANCH exit -2 } # add the branch ID file [ $VERBOSE -gt 0 ] && echo "Updating the $NAME/$BRANCH/branch file..." pushd $CVSROOT/$TOPLEVEL/$NAME/$BRANCH >/dev/null && \ rm -f branch,v Attic/branch,v && \ echo "$BRANCH" > branch && \ /usr/bin/ci -q -m"Initialize branch $BRANCH for $NAME" branch /dev/null done echo popd >/dev/null rm -rf $TMPDIR echo "Done."