source: vendors/FCM-2017.10.0/sbin/pre-revprop-change @ 10672

Last change on this file since 10672 was 10672, checked in by nicolasmartin, 3 years ago

Reimport latest FCM release

File size: 2.7 KB
Line 
1#!/bin/bash
2#-------------------------------------------------------------------------------
3# (C) British Crown Copyright 2006-17 Met Office.
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#-------------------------------------------------------------------------------
47set -eu
48
49REPOS=$1
50REV=$2
51USER=$3
52PROPNAME=$4
53ACTION=$5
54
55export PATH=${PATH:-'/usr/local/bin:/bin:/usr/bin'}:$(dirname $0)
56THIS=$(basename "$0")
57USER=${USER:-(whoami)}
58NAME=$(basename "$REPOS")
59
60OK_CHANGES=$(echo 'M svn:log')
61OK_CHANGES_FILE="$REPOS/hooks/$THIS-ok.conf"
62if [[ -f $OK_CHANGES_FILE ]]; then
63    OK_CHANGES=$(<$OK_CHANGES_FILE)
64fi
65
66NOW=$(date -u +%FT%H:%M:%SZ)
67if ! 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        mail -s "$NAME:$THIS" "$FCM_SVN_HOOK_ADMIN_EMAIL" <<<"[! $NOW] $@" \
79            || true
80    fi
81    echo "[! $NOW] $@"
82    exit 1
83fi
84exit
Note: See TracBrowser for help on using the repository browser.