~ubuntu-branches/ubuntu/maverick/computer-janitor/maverick-updates

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/sh
#
# license-check -- verify that each file contains copyright statement/license
#
# This script checks that each of the files given on the command line contain
# copyright statement and a reference to the GPL license. It prints out
# an error message to stderr for each file that fails the check, and exits
# with zero if there were no failures, or one if there were.
#
# (This is based on something originally written for the obnam backup
# program. This code was originally not written for Canonical, and is
# thus owned by the original author.)
#
# Copyright (C) 2007, 2008  Lars Wirzenius <liw@liw.fi>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

whine()
{
    echo "Error: $@" 1>&2
}

has_copyright()
{
    grep -E "Copyright (\(C\) )?[0-9][0-9][0-9][0-9].*[^0-9]" "$1" > /dev/null
}

has_gpl()
{
    # The following construct is so that the source code of this file
    # does not match the pattern itself.

    phrase1="This program is"
    phrase1="$phrase1 free software"

    phrase2="GNU General Public"
    phrase2="$phrase2 License"

    grep "$phrase1" "$1" > /dev/null &&
    grep "$phrase2" "$1" > /dev/null
}

exit=0
bzr ls --versioned --kind=file |
grep -Fxv -f license-exceptions |
while read file
do
    if ! has_copyright "$file"
    then
        whine "$file has no copyright statement"
        exit=1
    fi
    if ! has_gpl "$file"
    then
        whine "$file does not refer to the GPL"
        exit=1
    fi
done

exit $exit