source: MondoRescue/branches/3.3/ansible/roles/trac/templates/trac-svn-hook@ 3814

Last change on this file since 3814 was 3814, checked in by Bruno Cornec, 3 months ago

better debug

  • Property svn:executable set to *
File size: 7.8 KB
Line 
1#!/bin/sh
2# -*- coding: utf-8 -*-
3#
4# Copyright (C) 2009-2023 Edgewall Software
5# Copyright (C) 2009 Christian Boos <cboos@edgewall.org>
6# All rights reserved.
7#
8# This software is licensed as described in the file COPYING, which
9# you should have received as part of this distribution. The terms
10# are also available at https://trac.edgewall.com/license.html.
11#
12# This software consists of voluntary contributions made by many
13# individuals. For the exact contribution history, see the revision
14# history and logs, available at https://trac.edgewall.org/.
15#
16# = trac-svn-hook =
17#
18# Purpose:: this script is meant to be called from the Subversion hooks
19# for notifying Trac when changesets are added or modified.
20#
21# Scope:: https://trac.edgewall.org/wiki/TracRepositoryAdmin#Synchronization
22# describes how to directly call the relevant trac-admin commands
23# from the Subversion hooks. This script makes configuration and
24# troubleshooting easier, and has support for notifying multiple
25# Trac environments.
26#
27# Usage:: copy this script to some location on your filesystem, such as
28# the TRAC_ENV or TRAC_PARENT_ENV folder, or the repository hooks
29# directory.
30# **Be sure to read the Configuration Notes section below first**
31#
32# For each Subversion repository ($REPOS) that has to be monitored by your
33# Trac environment(s), you need to modify the hooks to call the script:
34#
35# Add this to your `$REPOS/hooks/post-commit` script:
36#
37# /path/to/trac-svn-hook $REPOS $REV
38#
39# If you allow revision property editing in `$REPOS/hooks/pre-revprop-change`,
40# you can let Trac know about modified changesets by adding the following
41# lines to the `$REPOS/hooks/post-revprop-change` script:
42#
43# if [ "$PROPNAME" = "svn:log" -o "$PROPNAME" = "svn:author" ]; then
44# /path/to/trac-svn-hook $REPOS $REV $USER $PROPNAME
45# fi
46#
47# See also http://svnbook.red-bean.com/en/1.8/svn.reposadmin.create.html#svn.reposadmin.create.hooks
48#
49# Platform:: Unix or Cygwin.
50#
51# On Windows, if you have Cygwin installed, you can use this script instead
52# of `trac-svn-post-commit-hook.cmd`.
53# In your `post-commit.bat` and `post-revprop-change.bat` hooks, call
54# this script using:
55#
56# bash /path/to/trac-svn-hook "%1" "%2" "%3" "%4"
57#
58# -----------------------------------------------------------------------------
59#
60# == Configuration Notes
61#
62# As a preliminary remark, you should be aware that Subversion usually
63# run the hooks in a very minimal environment.
64# This is why we have to be very explicit about where to find things.
65#
66# According to http://subversion.apache.org/faq.html#hook-debugging,
67# one useful method for getting the post-commit hook to work is to call
68# the hook manually from a shell, as the user(s) which will end up running
69# the hook (e.g. wwwrun, www-data, nobody). For example:
70#
71# env - $REPOS/hooks/post-commit $REPOS 1234
72#
73# or:
74#
75# env - $REPOS/hooks/post-revprop-change $REPOS 1234 nobody svn:log
76#
77#
78# The TRAC_ENV environment variable must be set, and the TRAC_PATH
79# and TRAC_LD_LIBRARY_PATH variables may also need to be set.
80#
81# TRAC_ENV:: the path(s) to the Trac environment(s)
82#
83# In case you need to maintain more than one environment in sync with
84# the repository (using a different scope or not), simply specify more
85# than one path, using the ":" path separator, or ";" if the script is
86# used on Windows with Cygwin's bash (in this case also don't forget to
87# enclose the list of paths in quotes, e.g. TRAC_ENV="path1;path2").
88#
89# TRAC_PATH:: the folder containing the trac-admin script
90#
91# This folder is typically the same as your Python installation bin/ folder.
92# If this is /usr/bin, then you probably don't need to put it in TRAC_PATH.
93#
94# If you're using a python program installed in a non-default location
95# (such as /opt/python27 or a virtual environment), then you need to add it
96# to the TRAC_PATH.
97#
98# TRAC_LD_LIBRARY_PATH:: folder(s) containing additional required libraries
99#
100# You may also need to setup the TRAC_LD_LIBRARY_PATH accordingly.
101# The same goes for any custom dependency, such as SQLite libraries or
102# SVN libraries: make sure everything is reachable.
103# For example, if you get errors like "global name 'sqlite' is not defined"
104# or similar, then make sure the TRAC_LD_LIBRARY_PATH contains the path to all
105# the required libraries (libsqlite3.so in the above example).
106#
107# -----------------------------------------------------------------------------
108#
109# == Configuration
110#
111# You have 3 options for specifying the configuration:
112# 1. Uncomment the variables below and adapt to your local setup.
113# 2. Set the variables in your hook scripts and export them.
114# 3. In Subversion 1.8 and later, set the variables in a hook script
115# environment configuration.
116# See also http://svnbook.red-bean.com/en/1.8/svn.reposadmin.create.html#svn.reposadmin.hooks.configuration
117#
118## TODO: make a loop ?
119#TRAC_ENV=/prj/trac/dploy.env:/prj/trac/mondorescue.env:/prj/trac/project-builder.env:/prj/trac/pusk.env:/prj/trac/uuwl.env/
120# TRAC_PATH=/path/to/python/bin
121# TRAC_LD_LIBRARY_PATH=/path/to/lib:/path/to/another/lib
122#
123# -----------------------------------------------------------------------------
124#
125# == Examples
126#
127# === Minimal setup example ===
128#
129# Python is installed in /usr/bin, Trac was easy_install'ed.
130#
131# {{{
132# TRAC_ENV=/srv/trac/the_trac_env
133# }}}
134#
135#
136# === Simple virtualenv setup example ===
137#
138# Here we're using a Trac installation set up using virtualenv
139# (https://pypi.org/project/virtualenv). The virtualenv has been
140# created at /srv/venv. The TRAC_PATH environment variable must be set
141# to the directory containing the python executable.
142#
143# {{{
144# TRAC_ENV=/srv/trac/the_trac_env
145# TRAC_PATH=/srv/venv/bin
146# }}}
147#
148# === More complex virtualenv setup example ===
149#
150#
151# In this example, the virtualenv is located in
152# /packages/trac/branches/trac-multirepos
153# and is based off a custom Python installation (/opt/python-2.7.11).
154# We're also using a custom SQLite build (/opt/sqlite-3.3.8).
155#
156# Note that virtualenv's activate script seems to only care about TRAC_PATH.
157#
158# We also want to notify two Trac instances:
159#
160# {{{
161# TRAC_ENV=/srv/trac/the_trac_env:/srv/trac/the_other_trac_env
162# TRAC_PATH=/packages/trac/branches/trac-multirepos/bin
163# TRAC_LD_LIBRARY_PATH=/opt/python-2.7.11/lib:/opt/sqlite-3.3.8/lib
164# }}}
165#
166#
167# === Cygwin setup example ===
168#
169# {{{
170# TRAC_ENV=C:/Workspace/local/trac/devel
171# PYTHONPATH=C:/Workspace/src/trac/repos/multirepos
172# TRAC_PATH=/C/Dev/Python27/Scripts
173# }}}
174#
175# -----------------------------------------------------------------------------
176#
177# This is the script itself, you shouldn't need to modify this part.
178
179# -- Command line arguments (cf. usage)
180
181export PATH=/usr/bin:/bin:$PATH
182
183REPOS="$1"
184REV="$2"
185USER="$3"
186PROPNAME="$4"
187
188# -- Foolproofing
189
190if [ -z "$REPOS" -o -z "$REV" ]; then
191 >&2 echo "Usage: $0 REPOS REV"
192 exit 2
193fi
194
195if ! python -V 2>/dev/null; then
196 >&2 echo "python is not in the PATH ($PATH), check TRAC_PATH."
197 exit 2
198fi
199
200if ! trac-admin -v 2>/dev/null; then
201 >&2 echo "trac-admin is not in the PATH ($PATH), check TRAC_PATH."
202 exit 2
203fi
204
205# -- Feedback
206
207echo "----"
208
209if [ -z "$PROPNAME" ]; then
210#if [ -z "$USER" -a -z "$PROPNAME" ]; then
211# USER is last commit id-1 not the user
212 EVENT="added"
213 echo "Changeset $REV was added in $REPOS"
214else
215 EVENT="modified"
216 echo "Changeset $REV was modified by $USER in $REPOS"
217fi
218
219BASEREPO=`basename $REPOS`
220env="/prj/trac/$BASEREPO.env"
221if [ -r "$env/VERSION" ]; then
222 REPO=`grep -E '^name[ \t]*=' $env/conf/trac.ini | cut -d= -f2`
223 mutt bruno@musique-ancienne.org -s "Changeset $REV $EVENT to $REPO in trac repo $env ($USER - $PROPNAME)" < /dev/null
224 trac-admin $env changeset $EVENT $REPO $REV
225 if [ $? -ne 0 ]; then
226 echo "Error: trac-admin $env changeset $EVENT $REPO $REV" 2>&1
227 exit -1
228 fi
229else
230 echo "$env doesn't seem to be a Trac environment, skipping..." 2>&1
231 exit -1
232fi
Note: See TracBrowser for help on using the repository browser.