~saviq/unity/phablet.release-172

« back to all changes in this revision

Viewing changes to tests/copyright/check_copyright.sh

  • Committer: Michał Sawicz
  • Date: 2013-04-23 22:27:12 UTC
  • mfrom: (612.1.8 phablet)
  • Revision ID: michal.sawicz@canonical.com-20130423222712-6q65wyw0bcif013r
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
 
 
3
#
 
4
# Copyright (C) 2013 Canonical Ltd
 
5
#
 
6
# This program is free software: you can redistribute it and/or modify
 
7
# it under the terms of the GNU General Public License version 3 as
 
8
# published by the Free Software Foundation.
 
9
#
 
10
# This program is distributed in the hope that it will be useful,
 
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
# GNU General Public License for more details.
 
14
#
 
15
# You should have received a copy of the GNU General Public License
 
16
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
#
 
18
# Authored by: Michi Henning <michi.henning@canonical.com>
 
19
#
 
20
 
 
21
#
 
22
# Check that, somewhere in the first 30 lines of each file, the string "Copyright" (case independent) appears.
 
23
# Print out a messsage for each file without a copyright notice and exit with non-zero status
 
24
# if any such file is found.
 
25
#
 
26
 
 
27
usage()
 
28
{
 
29
    echo "usage: check_copyright dir [ignore_dir]" >&2
 
30
    exit 2
 
31
}
 
32
 
 
33
[ $# -lt 1 ] && usage
 
34
[ $# -gt 2 ] && usage
 
35
 
 
36
ignore_pat="\\.sci$"
 
37
 
 
38
#
 
39
# We don't use the -i option of licensecheck to add ignore_dir to the pattern because Jenkins creates directories
 
40
# with names that contain regex meta-characters, such as "." and "+". Instead, if ingnore_dir is set, we post-filter
 
41
# the output with grep -F, so we don't get false positives from licensecheck.
 
42
#
 
43
 
 
44
[ $# -eq 2 ] && ignore_dir="$2"
 
45
 
 
46
if [ -n "$ignore_dir" ]
 
47
then
 
48
    licensecheck -i "$ignore_pat" -r "$1" | grep -F "$ignore_dir" -v | grep 'No copyright'
 
49
else
 
50
    licensecheck -i "$ignore_pat" -r "$1" | grep 'No copyright'
 
51
fi
 
52
 
 
53
[ $? -eq 0 ] && exit 1
 
54
 
 
55
exit 0