New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
test_header_more in vendors/t/svn-hooks – NEMO

source: vendors/t/svn-hooks/test_header_more @ 10669

Last change on this file since 10669 was 10669, checked in by nicolasmartin, 5 years ago

Import latest FCM release from Github into the repository for testing

File size: 3.9 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#     test_header_more
22#
23# SYNOPSIS
24#     . $(dirname $0)/test_header
25#     . $(dirname $0)/test_header_more
26#
27# DESCRIPTION
28#     Provide more bash shell functions for testing svn-hooks. Create a
29#     subversion repository. Create a Trac environment if possible. Set up
30#     repository hooks environment file.
31#
32# FUNCTIONS
33#     date2datefmt FILE
34#         Convert date time in YYYY-mm-ddTHH:MM:SSZ format into the format
35#         string itself.
36#     poll HOW_LONG COND ...
37#         Poll for COND to become true for HOW_LONG seconds.
38#
39# VARIABLES
40#     FCM_SVN_HOOK_REPOS_SUFFIX
41#     FCM_SVN_HOOK_ADMIN_EMAIL
42#         Optional. See definition in hook scripts.
43#     HOOK_PATH
44#         PATH for the hook scripts.
45#     REPOS_PATH
46#         Path to the Subversion repository ($PWD/svn-repos/foo).
47#     REPOS_URL
48#         URL of the Subversion repository root (file://$REPOS_PATH).
49#     TRAC_ENV_PATH
50#         Path to the Trac environment ($PWD/trac-env/foo).
51#     TRAC_RESYNC
52#         If true, use "trac-admin resync". If false, use "trac-admin
53#         changeset added|modified".
54#-------------------------------------------------------------------------------
55
56date2datefmt() {
57    perl -p -e 's/\d+-\d\d-\d\dT\d\d:\d\d:\d\dZ/YYYY-mm-ddTHH:MM:SSZ/' "$@"
58}
59
60poll() {
61    local HOW_LONG=$1
62    shift 1
63    local WAIT_UNTIL=$(($(date +%s) + $HOW_LONG))
64    while (($(date +%s) < $WAIT_UNTIL)) && ! "$@" 2>/dev/null; do
65        sleep 1
66    done
67    "$@"
68}
69
70HOOK_PATH='/usr/local/bin:/usr/bin:/bin'
71mkdir bin svn-dumps svn-repos trac-env
72svnadmin create svn-repos/foo 2>/dev/null \
73    || skip_all 'cannot create Subversion repository'
74REPOS_PATH="$PWD/svn-repos/foo${FCM_SVN_HOOK_REPOS_SUFFIX:-}"
75REPOS_URL="file://$REPOS_PATH"
76ADMIN_DIR=$(dirname "$(which svnadmin)")
77if ! grep -q '^\(/usr/local/bin\|/usr/bin\|/bin\)$' <<<"$ADMIN_DIR"; then
78    HOOK_PATH="$ADMIN_DIR:$HOOK_PATH"
79fi
80if trac-admin trac-env/foo initenv foo sqlite:db/trac.db svn "$REPOS_PATH" \
81    1>/dev/null 2>&1
82then
83    FCM_SVN_HOOK_TRAC_ROOT_DIR="$PWD/trac-env"
84    TRAC_ENV_PATH="$FCM_SVN_HOOK_TRAC_ROOT_DIR/foo"
85    ADMIN_DIR=$(dirname "$(which trac-admin)")
86    if ! grep -q '^\(/usr/local/bin\|/usr/bin\|/bin\)$' <<<"$ADMIN_DIR"; then
87        HOOK_PATH="$ADMIN_DIR:$HOOK_PATH"
88    fi
89    if [[ $(trac-admin --version) == trac-admin\ 0.11* ]]; then
90        TRAC_RESYNC=true
91    else
92        TRAC_RESYNC=false
93    fi
94    cat >>"${TRAC_ENV_PATH}/conf/trac.ini" <<'__TRAC_INI___'
95
96[components]
97tracopt.versioncontrol.svn.* = enabled
98__TRAC_INI___
99fi
100unset ADMIN_DIR
101cat >bin/mail <<__BASH__
102#!/bin/bash
103{
104    echo "\$@"
105    cat
106} >$PWD/mail.out
107__BASH__
108chmod +x bin/mail
109HOOK_PATH="$PWD/bin:$HOOK_PATH"
110cat >"$REPOS_PATH/conf/hooks-env" <<__CONF__
111[default]
112FCM_HOME=$FCM_HOME
113FCM_SITE_HOME=$PWD
114FCM_SVN_HOOK_ADMIN_EMAIL=${FCM_SVN_HOOK_ADMIN_EMAIL:-}
115FCM_SVN_HOOK_COMMIT_DUMP_DIR=$PWD/svn-dumps
116FCM_SVN_HOOK_NOTIFICATION_FROM=notifications@localhost
117FCM_SVN_HOOK_REPOS_SUFFIX=${FCM_SVN_HOOK_REPOS_SUFFIX:-}
118FCM_SVN_HOOK_TRAC_ROOT_DIR=${FCM_SVN_HOOK_TRAC_ROOT_DIR:-}
119PATH=$HOOK_PATH
120__CONF__
Note: See TracBrowser for help on using the repository browser.