Subversion Repository Creation Script

I have been using Subversion (SVN) pretty heavily the past couple of weeks. I wanted a quick way to create a repository that included the standard trunk, branches and tags directories and set the correct owner and file permissions for the new repo. I came up with the following script. Please feel free to comment out sections you do not need.

#!/usr/bin/php -q
< ?php
define('REPO_PARENT_PATH', '/path/to/repos');
define('REPO_OWNER', 'devel_user:devel_group');
define('REPO_MOD', '770');

if( $argc < 2 )
        die("No repo name specified.\\n\\nUsage: addrepo.php repo_name\\n\\n");
$repo_name = $argv[1];
echo "Adding Repository: $repo_name\\n\\n";

// Create repositoryi
$repo_path = REPO_PARENT_PATH;
if( substr( $repo_path, strlen($repo_path)-1, 1) != '/' )
        $repo_path .= '/';
exec("svnadmin create $repo_path$repo_name");

// Add trunk
exec("svn mkdir file://$repo_path$repo_name/trunk -m \"Add trunk\"");

// Add branches
exec("svn mkdir file://$repo_path$repo_name/branches -m \"Add branches\"");

// Add tags
exec("svn mkdir file://$repo_path$repo_name/tags -m \"Add tags\"");

// Change file permissions
exec("chmod -R ".REPO_MOD." $repo_path$repo_name");

// Change file ownership
exec("chown -R ".REPO_OWNER." $repo_path$repo_name");
?>

To use, execute the script from the shell one parameter being the name of your repository.

Example: ./addrepo.php repo_name
Share and Enjoy:
  • Print this article!
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks

Leave a Reply

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Blubrry player!