Project

General

Profile

RE: Question on Automatic svn creation ยป reposman_wrapper.sh

Reposman wrapper - Pieter Smith, 2011-02-13 20:02

 
#!/bin/bash
# Creates repositories for new redmine projects, adds commit hooks and creates a basic repository structure

# Keep track of the install path
HOOKS_DIR=/var/hooks
TMP_WC=/tmp/new_repo
INSTALL_DIR=/usr/redmine
REDMINE_PORT=3000
REDMINE_SUB_URI=redmine
WWW_OWNER='www-data'
SCM_DATA_PATH=/var/svn


svn_initial_commit() {
local NEW_REPO=$1
echo " Performing initial commit..."
svn checkout $NEW_REPO $TMP_WC
pushd $TMP_WC > /dev/null
mkdir -p trunk tags branches
svn add *
svn commit -m "Initial commit: Added repository structure"
popd
rm -rf $TMP_WC
}

svn_add_hooks() {
local NEW_REPO=$1
echo " Adding hooks..."
cp -P $HOOKS_DIR/* $NEW_REPO/hooks
}

prep_new_repositories() {
local HOOKS_DIR=$1
while read i; do
echo "New repository created: $i"

# Check for repository creation
i=`echo $i | grep -P '^.+(created$){1}'`

# Strip repository paths from the reposman.rb output
i=${i##repository }
i=${i%% created}

# Perform initial commit and add hooks for every new repository
if [ -n "$i" ]; then
svn_initial_commit $i
svn_add_hooks $i
fi
done
}

# Call reposman.rb, parse output and prep whatever was created
ruby $INSTALL_DIR/extra/svn/reposman.rb --svn-dir=$SCM_DATA_PATH --redmine-host=localhost:$REDMINE_PORT/$REDMINE_SUB_URI --scm=subversion --url=file://$SCM_DATA_PATH --owner=$WWW_OWNER --group=$WWW_OWNER | grep 'repository /' | prep_new_repositories $HOOKS_DIR
    (1-1/1)