source: LMDZ6/branches/Amaury_dev/tools/fcm/sbin/post-revprop-change-bg @ 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: 4.0 KB
RevLine 
[5095]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#   post-revprop-change-bg
22#
23# SYNOPSIS
24#   post-revprop-change-bg 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 performs the post-revprop-change tasks of a Subversion
35#   repository in the background.
36#
37#   The script does the following:
38#   1. Write diff between old and new property.
39#   2. Update corresponding Trac environment, if relevant.
40#   3. E-mails the host user account on error.
41#   4. E-mails the changeset author if property author is not changeset author.
42#
43# ENVIRONMENT VARIABLES
44#   FCM_SVN_HOOK_TRAC_ROOT_DIR
45#     The root directories of Trac environments. Update corresponding Trac
46#     environment if specified.
47#   FCM_SVN_HOOK_REPOS_SUFFIX
48#     A suffix that should be removed from the basename of REPOS to get the
49#     name of the Trac environment. (Default is "".)
50#-------------------------------------------------------------------------------
51set -eu
52. "$(dirname $0)/trac_hook"
53
54REPOS=$1
55REV=$2
56PROP_AUTHOR=$3
57PROP_NAME=$4
58ACTION=$5
59
60export PATH=${PATH:-'/usr/local/bin:/bin:/usr/bin'}:$(dirname $0)
61THIS=$(basename $0)
62USER=${USER:-$(whoami)}
63LOG_TMP=$(mktemp "$REPOS/log/$THIS.log.XXXXXXXXXX")
64NAME=$(basename "$REPOS")
65
66main() {
67    local RET_CODE=0
68    local NOW=$(date -u +%FT%H:%M:%SZ)
69    echo "$NOW+ $ACTION $PROP_NAME @$REV by $PROP_AUTHOR"
70
71    # Diff old/new in log
72    local OLD_FILE=$(mktemp "$REPOS/log/$THIS.$REV.XXXXXXXXXX.old")
73    cat >"$OLD_FILE"
74    local DIFF_FILE=$(mktemp "$REPOS/log/$THIS.$REV.XXXXXXXXXX.diff")
75    {
76        echo "$NOW+ $ACTION $PROP_NAME @$REV by $PROP_AUTHOR"
77        printf '=%.0s' {1..72}
78        echo
79    } >"$DIFF_FILE"
80    svnlook pg -r "$REV" --revprop "$REPOS" "$PROP_NAME" \
81        | diff -u --label="old-value" --label="new-value" "$OLD_FILE" - \
82        | tee -a "$DIFF_FILE"
83
84    # Email to changeset author if not the same as property change author
85    REV_AUTHOR=$(svnlook author -r "$REV" "$REPOS")
86    if [[ "$REV_AUTHOR" != "$PROP_AUTHOR" ]]; then
87        SUBJECT="-s$(basename $REPOS)@$REV [$ACTION $PROP_NAME] by $PROP_AUTHOR"
88        FROM=
89        if [[ -n ${FCM_SVN_HOOK_NOTIFICATION_FROM:-} ]]; then
90            FROM="-r${FCM_SVN_HOOK_NOTIFICATION_FROM:-}"
91        fi
92        ADDRS=$(fcm-user-to-email "$REV_AUTHOR" "$PROP_AUTHOR" 2>'/dev/null')
93        mail "$FROM" "$SUBJECT" "$ADDRS" <"$DIFF_FILE" || true
94    fi
95    rm -f "$OLD_FILE" "$DIFF_FILE"
96
97    # Resync Trac
98    trac_hook "$REPOS" "$REV" modified || RET_CODE=$?
99
100    echo "RET_CODE=$RET_CODE"
101    return $RET_CODE
102}
103
104if ! main 1>$LOG_TMP 2>&1 && [[ -n ${FCM_SVN_HOOK_ADMIN_EMAIL:-} ]]; then
105    FROM=
106    if [[ -n ${FCM_SVN_HOOK_NOTIFICATION_FROM:-} ]]; then
107        FROM="-r${FCM_SVN_HOOK_NOTIFICATION_FROM:-}"
108    fi
109    mail "$FROM" -s "[ERROR $THIS] $NAME" \
110        "$FCM_SVN_HOOK_ADMIN_EMAIL" <"$LOG_TMP" || true
111fi
112
113cat "$LOG_TMP"
114rm -f "$LOG_TMP"
115exit
Note: See TracBrowser for help on using the repository browser.