Project

General

Profile

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

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

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

    
4
# Keep track of the install path
5
HOOKS_DIR=/var/hooks
6
TMP_WC=/tmp/new_repo
7
INSTALL_DIR=/usr/redmine
8
REDMINE_PORT=3000
9
REDMINE_SUB_URI=redmine
10
WWW_OWNER='www-data'
11
SCM_DATA_PATH=/var/svn
12

    
13

    
14
svn_initial_commit() {
15
				local NEW_REPO=$1
16
        echo "  Performing initial commit..."
17
        svn checkout $NEW_REPO $TMP_WC
18
        pushd $TMP_WC > /dev/null
19
        mkdir -p trunk tags branches
20
        svn add *
21
        svn commit -m "Initial commit: Added repository structure"
22
        popd
23
        rm -rf $TMP_WC
24
}
25

    
26
svn_add_hooks() {
27
				local NEW_REPO=$1
28
        echo "  Adding hooks..."
29
        cp -P $HOOKS_DIR/* $NEW_REPO/hooks
30
}
31

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

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

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

    
44
								# Perform initial commit and add hooks for every new repository
45
                if [ -n "$i" ]; then
46
                        svn_initial_commit $i
47
                        svn_add_hooks $i
48
                fi
49
        done
50
}
51

    
52
# Call reposman.rb, parse output and prep whatever was created
53
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)