source: XIOS/tools/FCM/examples/svn-hooks/post-commit-background @ 1293

Last change on this file since 1293 was 81, checked in by ymipsl, 12 years ago

ajout FCM 1.5

File size: 2.9 KB
Line 
1#!/bin/ksh
2# ------------------------------------------------------------------------------
3# NAME
4#   post-commit-background
5#
6# SYNOPSIS
7#   post-commit-background REPOS REV
8#
9# DESCRIPTION
10#   This script performs the Subversion post-commit tasks in the background. The
11#   first argument must be the path to the current Subversion repository, and
12#   the second argument must be the revision of the current commit. Errors in
13#   the script are automatically e-mailed to the FCM user account.
14#
15#   The script does the following:
16#    1. updates the "latest" file in the log directory with the latest revision
17#       number of the repository.
18#    2. creates an incremental revision dump of the current revision.
19#    3. runs "background_updates.pl" if it exists in the hook script directory.
20#
21# COPYRIGHT
22#   (C) Crown copyright Met Office. All rights reserved.
23#   For further details please refer to the file COPYRIGHT.txt
24#   which you should have received as part of this distribution.
25# ------------------------------------------------------------------------------
26
27REPOS=$1
28REV=$2
29
30REPOS_NAME=${REPOS##*/}
31LOG_DIR=~fcm/svn/post-commit
32LOG_FILE=$LOG_DIR/${REPOS_NAME}.log
33DUMP_DIR=~fcm/svn/dumps/$REPOS_NAME
34DUMP_FILE=$DUMP_DIR/$REV
35ERR=''
36
37{
38  # Update the "latest" file with the latest revision number
39  # ----------------------------------------------------------------------------
40  echo "$(date): Updating ${REPOS_NAME}.latest ..."
41  echo $REV > $LOG_DIR/${REPOS_NAME}.latest
42
43  if (($? != 0)); then
44    ERR="${ERR}Update of ${REPOS_NAME}.latest: failed. "
45  fi
46
47  # Dump the current revision
48  # ----------------------------------------------------------------------------
49  if [[ ! -d $DUMP_DIR ]]; then
50    mkdir -p $DUMP_DIR
51  fi
52
53  svnadmin dump -r $REV --incremental --deltas $REPOS 1>$DUMP_FILE
54
55  if (($? != 0)); then
56    ERR="${ERR}$REPOS_NAME@$REV: svnadmin dump: failed. "
57  fi
58
59  # Warn us of large changesets (>1Mb)
60  dump_size=$(du -b -s $DUMP_FILE | cut -f 1)
61
62  if (($dump_size > 1048576)); then
63    dump_size=$(du -h -s $DUMP_FILE | cut -f 1)
64    ERR="${ERR}Dump size exceeds 1Mb. "
65    echo "WARNING: large changeset dump, size = ${dump_size}">&2
66  fi
67
68  # Perform background update, if necessary
69  # ----------------------------------------------------------------------------
70  if [[ -e ${REPOS}/hooks/background_updates.pl ]]; then
71    echo "$(date): Running background tasks and exiting ..."
72    export TMPDIR=/var/tmp
73    ${REPOS}/hooks/background_updates.pl $REPOS_NAME $LOG_DIR
74
75    if (($? != 0)); then
76      ERR="${ERR}background_updates.pl: failed. "
77    fi
78
79  else
80    echo "$(date): No background tasks required - exiting"
81  fi
82
83} 1>$LOG_FILE 2>&1
84
85# If there are errors, e-mail the log message to FCM
86# ------------------------------------------------------------------------------
87if [[ -n $ERR ]]; then
88  ERR=${ERR% *}
89  /bin/mail -s "$REPOS@$REV: $ERR" my.name@somewhere.org <<EOF
90$(<$LOG_FILE)
91EOF
92fi
Note: See TracBrowser for help on using the repository browser.