source: LMDZ6/branches/Amaury_dev/tools/fcm/sbin/pre-revprop-change @ 5110

Last change on this file since 5110 was 5095, checked in by abarral, 4 months ago

Revert cosp*/ from the trunk, as it's external code
Add missing bits from FCM2 source

  • Property svn:executable set to *
File size: 2.8 KB
Line 
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#-------------------------------------------------------------------------------
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        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
87fi
88exit
Note: See TracBrowser for help on using the repository browser.