1 | #!/bin/bash |
---|
2 | #------------------------------------------------------------------------------- |
---|
3 | # Copyright (C) 2006-2021 British Crown (Met Office) & Contributors. |
---|
4 | # |
---|
5 | # This file is part of FCM, tools for managing and building source code. |
---|
6 | # |
---|
7 | # FCM is free software: you can redistribute it and/or modify |
---|
8 | # it under the terms of the GNU General Public License as published by |
---|
9 | # the Free Software Foundation, either version 3 of the License, or |
---|
10 | # (at your option) any later version. |
---|
11 | # |
---|
12 | # FCM is distributed in the hope that it will be useful, |
---|
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
15 | # GNU General Public License for more details. |
---|
16 | # |
---|
17 | # You should have received a copy of the GNU General Public License |
---|
18 | # along with FCM. If not, see <http://www.gnu.org/licenses/>. |
---|
19 | #------------------------------------------------------------------------------- |
---|
20 | # NAME |
---|
21 | # pre-revprop-change |
---|
22 | # |
---|
23 | # SYNOPSIS |
---|
24 | # pre-revprop-change REPOS REV PROP_AUTHOR PROP_NAME ACTION |
---|
25 | # |
---|
26 | # ARGUMENTS |
---|
27 | # REPOS - the path to the Subversion repository |
---|
28 | # REV - the revision relevant for the property |
---|
29 | # PROP_AUTHOR - the author of this property change |
---|
30 | # PROP_NAME - the name of the property, should only be "svn:log" |
---|
31 | # ACTION - the action of the property change, should only be "M" |
---|
32 | # |
---|
33 | # DESCRIPTION |
---|
34 | # This script enables users to change revision properties. |
---|
35 | # |
---|
36 | # By default, only "M svn:log" is allowed. If |
---|
37 | # "$REPOS/hooks/pre-revprop-change-ok.conf" exists, the contents should be a |
---|
38 | # list of allowed changes to revision properties. E.g.: |
---|
39 | # |
---|
40 | # M svn:author |
---|
41 | # M svn:log |
---|
42 | # |
---|
43 | # An empty file disables all changes. |
---|
44 | # |
---|
45 | # It e-mails the host user account whenever an action is blocked. |
---|
46 | #------------------------------------------------------------------------------- |
---|
47 | set -eu |
---|
48 | |
---|
49 | REPOS=$1 |
---|
50 | REV=$2 |
---|
51 | USER=$3 |
---|
52 | PROPNAME=$4 |
---|
53 | ACTION=$5 |
---|
54 | |
---|
55 | export PATH=${PATH:-'/usr/local/bin:/bin:/usr/bin'}:$(dirname $0) |
---|
56 | THIS=$(basename "$0") |
---|
57 | USER=${USER:-(whoami)} |
---|
58 | NAME=$(basename "$REPOS") |
---|
59 | |
---|
60 | OK_CHANGES=$(echo 'M svn:log') |
---|
61 | OK_CHANGES_FILE="$REPOS/hooks/$THIS-ok.conf" |
---|
62 | if [[ -f $OK_CHANGES_FILE ]]; then |
---|
63 | OK_CHANGES=$(<$OK_CHANGES_FILE) |
---|
64 | fi |
---|
65 | |
---|
66 | NOW=$(date -u +%FT%H:%M:%SZ) |
---|
67 | if ! grep -q "$ACTION *$PROPNAME" <<<"$OK_CHANGES"; then |
---|
68 | if [[ -n "$OK_CHANGES" ]]; then |
---|
69 | echo -n "[$ACTION $PROPNAME] permission denied. Can only do:" >&2 |
---|
70 | while read; do |
---|
71 | echo -n " [$REPLY]" >&2 |
---|
72 | done <<<"$OK_CHANGES" |
---|
73 | echo >&2 |
---|
74 | else |
---|
75 | echo "[$ACTION $PROPNAME] permission denied." >&2 |
---|
76 | fi |
---|
77 | if [[ -n ${FCM_SVN_HOOK_ADMIN_EMAIL:-} ]]; then |
---|
78 | FROM= |
---|
79 | if [[ -n ${FCM_SVN_HOOK_NOTIFICATION_FROM:-} ]]; then |
---|
80 | FROM="-r${FCM_SVN_HOOK_NOTIFICATION_FROM:-}" |
---|
81 | fi |
---|
82 | mail "$FROM" -s "$NAME:$THIS" \ |
---|
83 | "$FCM_SVN_HOOK_ADMIN_EMAIL" <<<"[! $NOW] $@" || true |
---|
84 | fi |
---|
85 | echo "[! $NOW] $@" |
---|
86 | exit 1 |
---|
87 | fi |
---|
88 | exit |
---|