From users-return-5163-daniel=haxx.se@subversion.apache.org Mon Oct 4 21:21:38 2010 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on giant.haxx.se X-Spam-Level: X-Spam-Status: No, score=-1.5 required=3.0 tests=BAYES_00,T_RP_MATCHES_RCVD autolearn=ham version=3.3.1 Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by giant.haxx.se (8.14.3/8.14.3/Debian-9.1) with SMTP id o94JLaQO016893 for ; Mon, 4 Oct 2010 21:21:38 +0200 Received: (qmail 14662 invoked by uid 500); 4 Oct 2010 19:21:26 -0000 Mailing-List: contact users-help@subversion.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list users@subversion.apache.org Received: (qmail 14655 invoked by uid 99); 4 Oct 2010 19:21:25 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 04 Oct 2010 19:21:25 +0000 X-ASF-Spam-Status: No, hits=-2.3 required=10.0 tests=RCVD_IN_DNSWL_MED,SPF_PASS Received-SPF: pass (athena.apache.org: local policy) Received: from [128.220.161.141] (HELO ipex4.johnshopkins.edu) (128.220.161.141) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 04 Oct 2010 19:21:18 +0000 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ag4FAHPGqUyige77/2dsb2JhbACGANoFiGaFRwQ X-IronPort-AV: E=Sophos;i="4.57,280,1283745600"; d="scan'208";a="11444474" Received: from image.rad.jhmi.edu (HELO [162.129.238.251]) ([162.129.238.251]) by ipex4.johnshopkins.edu with ESMTP/TLS/DHE-RSA-CAMELLIA256-SHA; 04 Oct 2010 15:20:55 -0400 Message-ID: <4CAA2947.50806@jhu.edu> Date: Mon, 04 Oct 2010 15:21:43 -0400 From: "Martin J. Stumpf" Organization: Johns Hopkins University User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.9) Gecko/20100915 Thunderbird/3.1.4 MIME-Version: 1.0 To: users@subversion.apache.org Subject: Re: Copying hooks automatically upon repository creation References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.3.5 (giant.haxx.se [80.67.6.50]); Mon, 04 Oct 2010 21:21:38 +0200 (CEST) X-Friend: Nope On 10/4/2010 2:42 PM, Ryan Schmidt wrote: > On Oct 4, 2010, at 12:51, Tech Geek wrote: > >> We use one repository per project. All repository lives in /var/lib/svn/. >> >> Also we use the hooks post-commit and pre-commit for every repository. Right now we have to manually copy these two hooks whenever a new repository is created. >> For example: >> cd /var/lib/svn/ >> cp /path-to-my-hooks/* projectA/hooks >> cp /path-to-my-hooks/* projectB/hooks >> cp /path-to-my-hooks/* projectC/hooks >> >> Is there any way to automate this process? > As Andy said, you can write a script that creates the repository and then copies the scripts, then make sure you call that script instead of calling "svnadmin create" directly whenever you want a new repo. My version of this script creates the repository as the Apache user and symlinks in my common hooks and conf directories. I symlink instead of copying because I want all my repositories to always have the same hooks and conf files, and I want changes I make in them to be reflected in existing repositories. Here's my script: > > > #!/bin/bash > > REPO="/path/to/subversion/repositories/$1" > USER="www" > > if [ -e "$REPO" ]; then > echo "Repository \"$1\" already exists." 1>&2 > exit 1 > fi > > sudo -u "$USER" svnadmin create "$REPO" || exit $? > sudo -u "$USER" rm -rf "$REPO"/{conf,hooks} || exit $? > sudo -u "$USER" ln -s ../../conf "$REPO" || exit $? > sudo -u "$USER" ln -s ../../hooks "$REPO" || exit $? > > > I also use a bash script replacement for svnadmin create and use a common hooks directory. This script will set the file permissions and make the hook symlinks even for a repository that was created by the svnadmin create command. We use one project/one repo and this makes repo creation a snap. HTH, -Martin #!/bin/bash # # svncreate - Create an svn repository and set it up with the correct permissions # The -n switch is used to change the permissions of an existing # repository in the event that we did not create it. # # $Id: svncreate 60 2009-11-19 21:00:02Z mjs $ # # Defaults REPOS=/mip/svn # This is the parent path to the project repositories. HOOKS=/mip/svn/.hooks # The pre, post commit hook scripts. TYPE=fsfs # The type of the repo, bdb or fsfs. NOCREATE= function usage() { echo "Usage: svncreate [-n] [-r REPOPATH] [repo name] ..." echo "Where: -n means don't create the repo, just change permissions and add hooks." echo "Where: -r REPOPATH specifies the repository parent path. (Default=/mip/svn)" } function set_permissions() { if [ $EUID -eq 0 ];then chown -R root ${REPOS}/${PROJECT} || return $? fi mkdir ${REPOS}/${PROJECT}/dav chgrp -R svn ${REPOS}/${PROJECT} || return $? chmod 6770 ${REPOS}/${PROJECT} || return $? dirs=$(find ${REPOS}/${PROJECT} -type d) for d in $dirs; do chmod 6770 $d || return $? done files=$(find ${REPOS}/${PROJECT} -type f) for f in $files; do chmod 660 $f || return $? done } function setup_hooks() { ln -s ${HOOKS}/pre-commit ${REPOS}/${PROJECT}/hooks 2>/dev/null ln -s ${HOOKS}/post-commit ${REPOS}/${PROJECT}/hooks 2>/dev/null ln -s ${HOOKS}/pre-revprop-change ${REPOS}/${PROJECT}/hooks 2>/dev/null } # Get the command line args while getopts "nr:" opt; do case $opt in n)NOCREATE=1;; r)REPOS="$OPTARG";; \?)usage;exit;; esac done shift $(($OPTIND - 1)) if [ $# -lt 1 ]; then usage exit fi for PROJECT in "$@"; do # We need write access to the REPOS directory [ -d "$REPOS" -a -w "$REPOS" ] || { echo "No write permission to $REPOS"; exit; } if [ -z $NOCREATE ]; then if svnadmin create --fs-type ${TYPE} ${REPOS}/${PROJECT} && set_permissions; then setup_hooks echo "" echo "The Project repository: ${REPOS}/${PROJECT} was created." echo "" echo "Use svn import -m "Initial Import" https://svnserver/ /path/to/files to populate it." echo "" echo "Note: If you browse the repo and don't like what you imported" echo "then just rm -rf the project ${REPOS}/${PROJECT} and start over." else echo "Failed to create project repository: ${REPOS}/${PROJECT}" break fi else if set_permissions; then setup_hooks echo "" echo "Permissions on the project repository: ${REPOS}/${PROJECT} were changed." echo "" else echo "Failed to change permissions on project repository: ${REPOS}/${PROJECT}" break fi fi done