source: trunk/hooks/pre-unlock.tmpl @ 1572

Last change on this file since 1572 was 1572, checked in by pg, 19 months ago
File size: 3.3 KB
Line 
1#!/bin/sh
2
3# PRE-UNLOCK HOOK
4#
5# The pre-unlock hook is invoked before an exclusive lock is
6# destroyed.  Subversion runs this hook by invoking a program
7# (script, executable, binary, etc.) named 'pre-unlock' (for which
8# this file is a template), with the following ordered arguments:
9#
10#   [1] REPOS-PATH   (the path to this repository)
11#   [2] PATH         (the path in the repository about to be unlocked)
12#   [3] USER         (the user destroying the lock)
13#   [4] TOKEN        (the lock token to be destroyed)
14#   [5] BREAK-UNLOCK (1 if the user is breaking the lock, else 0)
15#
16# If the hook program exits with success, the lock is destroyed; but
17# if it exits with failure (non-zero), the unlock action is aborted
18# and STDERR is returned to the client.
19#
20# The default working directory for the invocation is undefined, so
21# the program should set one explicitly if it cares.
22#
23# On a Unix system, the normal procedure is to have 'pre-unlock'
24# invoke other programs to do the real work, though it may do the
25# work itself too.
26#
27# Note that 'pre-unlock' must be executable by the user(s) who will
28# invoke it (typically the user httpd runs as), and that user must
29# have filesystem-level permission to access the repository.
30#
31# On a Windows system, you should name the hook program
32# 'pre-unlock.bat' or 'pre-unlock.exe',
33# but the basic idea is the same.
34#
35# The hook program runs in an empty environment, unless the server is
36# explicitly configured otherwise.  For example, a common problem is for
37# the PATH environment variable to not be set to its usual value, so
38# that subprograms fail to launch unless invoked via absolute path.
39# If you're having unexpected problems with a hook program, the
40# culprit may be unusual (or missing) environment variables.
41#
42# CAUTION:
43# For security reasons, you MUST always properly quote arguments when
44# you use them, as those arguments could contain whitespace or other
45# problematic characters. Additionally, you should delimit the list
46# of options with "--" before passing the arguments, so malicious
47# clients cannot bootleg unexpected options to the commands your
48# script aims to execute.
49# For similar reasons, you should also add a trailing @ to URLs which
50# are passed to SVN commands accepting URLs with peg revisions.
51#
52# Here is an example hook script, for a Unix /bin/sh interpreter.
53# For more examples and pre-written hooks, see those in
54# the Subversion repository at
55# http://svn.apache.org/repos/asf/subversion/trunk/tools/hook-scripts/ and
56# http://svn.apache.org/repos/asf/subversion/trunk/contrib/hook-scripts/
57
58
59REPOS="$1"
60PATH="$2"
61USER="$3"
62TOKEN="$4"
63BREAK="$5"
64
65# If a lock is owned by a different person, don't allow it be broken.
66# (Maybe this script could send email to the lock owner?)
67
68SVNLOOK=/usr/local/bin/svnlook
69GREP=/bin/grep
70SED=/bin/sed
71
72LOCK_OWNER=`$SVNLOOK lock "$REPOS" "$PATH" | \
73            $GREP '^Owner: ' | $SED 's/Owner: //'`
74
75# If we get no result from svnlook, there's no lock, return success:
76if [ "$LOCK_OWNER" = "" ]; then
77  exit 0
78fi
79
80# If the person unlocking matches the lock's owner, return success:
81if [ "$LOCK_OWNER" = "$USER" ]; then
82  exit 0
83fi
84
85# Otherwise, we've got an owner mismatch, so return failure:
86echo "Error: $PATH locked by ${LOCK_OWNER}." 1>&2
87exit 1
Note: See TracBrowser for help on using the repository browser.