root/trunk/hotstuff/scripts/pre-commit

Revision 446, 2.5 KB (checked in by josef, 4 years ago)

- adapt copyright headers to the updated licence

  • Property svn:executable set to *
Line 
1#!/bin/sh
2#
3# GHNS pre-commit hook for meta file validation in a SVN-backed repository
4# Copyright (C) 2007 Josef Spillner <josef@kstuff.org>
5# Published under 'GNU AGPLv3 or later' conditions
6
7# Read in parameters
8REPOS="$1"
9TXN="$2"
10
11# Change to line-based processing
12IFS="
13"
14
15# Assign values for temporary file locations
16diff=~/.ghnsmeta.$$.diff
17cat=~/.ghnsmeta.$$.cat
18
19# Examine files: we're only interested in '*.meta'
20changes=`svnlook changed -t $TXN $REPOS | grep "\.meta"`
21for change in $changes; do
22        # Get the previous version (might be empty) and the patch
23        mod=`echo $change | awk '{print $1}'`
24        file=`echo $change | awk '{print $2}'`
25        svnlook diff -t $TXN $REPOS | filterdiff -i "$file" > $diff
26        svnlook cat $REPOS "$file" > $cat 2>/dev/null
27
28        # Apply the requested changes to files
29        patch $cat $diff
30
31        # Shortcut for deletions
32        lines=`wc -l $cat | awk '{print $1}'`
33        if [ $lines = 0 ]; then
34                continue
35        fi
36
37        # Run XML validation first
38        out=`xmllint --noout $cat 2>&1`
39        if [ $? != 0 ]; then
40                echo "----------------------------" >&2
41                echo "** GHNS validation failed **" >&2
42                echo "Reason: Invalid XML in $file" >&2
43                echo "----------------------------" >&2
44                echo $out >&2
45                exit 1
46        fi
47
48        # Run XML schema validation
49        out=`xmllint --schema /etc/xml/ghns.xsd --noout $cat 2>&1`
50        if [ $? != 0 ]; then
51                echo "----------------------------" >&2
52                echo "** GHNS validation failed **" >&2
53                echo "Reason: Non-conforming upload XML in $file" >&2
54                echo "----------------------------" >&2
55                echo $out >&2
56                exit 1
57        fi
58done
59
60# Look for provider administrativia
61changes=`svnlook changed -t $TXN $REPOS | grep "ADMIN/hotstuff.d/"`
62for change in $changes; do
63        # Get the previous version (might be empty) and the patch
64        mod=`echo $change | awk '{print $1}'`
65        file=`echo $change | awk '{print $2}'`
66        svnlook diff -t $TXN $REPOS | filterdiff -i "$file" > $diff
67        svnlook cat $REPOS "$file" > $cat 2>/dev/null
68
69        # Apply the requested changes to files
70        patch $cat $diff
71
72        # Shortcut for deletions
73        lines=`wc -l $cat | awk '{print $1}'`
74        if [ $lines = 0 ]; then
75                continue
76        fi
77
78        # Add repository databases for new provider files
79        publiccat=/tmp/.ghnsmeta.$$.publiccat
80        cp $cat $publiccat
81        out=`hotstuff-siteadmin addsvn $publiccat 2>&1`
82        ret=$?
83        rm -f $publiccat
84        if [ $ret != 0 ]; then
85                echo "-----------------------------------------" >&2
86                echo "** GHNS provider administration failed **" >&2
87                echo "Reason: Siteadmin error in $file" >&2
88                echo "-----------------------------------------" >&2
89                echo $out >&2
90                exit 1
91        fi
92done
93
94rm -f $diff
95rm -f $cat
96
97exit 0
Note: See TracBrowser for help on using the browser.