Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2228 - 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
 
59
REPOS="$1"
60
PATH="$2"
61
USER="$3"
62
TOKEN="$4"
63
BREAK="$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
 
68
SVNLOOK=/usr/local/bin/svnlook
69
GREP=/bin/grep
70
SED=/bin/sed
71
 
72
LOCK_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:
76
if [ "$LOCK_OWNER" = "" ]; then
77
  exit 0
78
fi
79
 
80
# If the person unlocking matches the lock's owner, return success:
81
if [ "$LOCK_OWNER" = "$USER" ]; then
82
  exit 0
83
fi
84
 
85
# Otherwise, we've got an owner mismatch, so return failure:
86
echo "Error: $PATH locked by ${LOCK_OWNER}." 1>&2
87
exit 1