Updated copyright blurbs and AUTHORS and included script for future updates
[update-copyright.git] / update_copyright.sh
1 #!/bin/bash
2 #
3 # Update copyright information in source code with information from
4 # the bzr repository.  Run from the BE repository root.
5
6 set -o pipefail
7
8 # adjust the AUTHORS file
9 AUTHORS=`bzr log | grep '^ *committer\|^ *author' | cut -d: -f2 | sed 's/ <.*//;s/^ *//' | sort | uniq`
10 AUTHORS=`echo "$AUTHORS" | grep -v 'j\^\|wking\|John Doe'` # remove non-names
11 echo "Bugs Everywhere was written by:" > AUTHORS
12 echo "$AUTHORS" >> AUTHORS
13
14 CURRENT_YEAR=`date +"%Y"`
15 FILES=`grep -rc "# Copyright" . | grep -v ':0$' | cut -d: -f1`
16 TMP=`mktemp BE_update_copyright.XXXXXXX`
17
18 for file in $FILES
19 do
20     # Ignore some files
21     if [ "${file:0:5}" == "./.be" ]; then
22         continue
23     fi
24     if [ "${file:0:6}" == "./.bzr" ]; then
25         continue
26     fi
27     if [ "${file:0:7}" == "./build" ]; then
28         continue
29     fi
30     if [ "$file" == "./COPYING" ]; then
31         continue
32     fi
33     if [ "$file" == "./update_copyright.sh" ]; then
34         continue
35     fi
36     if [ "$file" == "./xml/catmutt" ]; then
37         continue
38     fi
39     echo "Processing $file"
40
41     # Get author history from bzr
42     AUTHORS=`bzr log "$file" | grep "^ *author: \|^ *committer: " | cut -d: -f2 | sed 's/^ *//;s/ *$//' | sort | uniq`
43     if [ $? -ne 0 ]; then
44         continue # bzr doesn't version that file
45     fi
46     ORIG_YEAR=`bzr log "$file" | grep "^ *timestamp: " | tail -n1 | sed 's/^ *//;' | cut -b 16-19`
47
48     # Tweak the author list to make up for problems in the bzr
49     # history, change of email address, etc.
50
51     # Consolidate Aaron Bentley
52     AUTHORS=`echo "$AUTHORS" | sed 's/<abentley@panoramicfeedback.com>/and Panometrics, Inc./'`
53     GREP_OUT=`echo "$AUTHORS" | grep 'Aaron Bentley and Panometrics, Inc.'`
54     if [ -n "$GREP_OUT" ]; then
55         AUTHORS=`echo "$AUTHORS" | grep -v '^Aaron Bentley <aaron.bentley@utoronto.ca>$'`
56     fi
57
58     # Consolidate Ben Finney
59     AUTHORS=`echo "$AUTHORS" | sed 's/John Doe <jdoe@example.com>/Ben Finney <ben+python@benfinney.id.au>/'`
60     GREP_OUt=`echo "$AUTHORS" | grep 'Ben Finney <ben+python@benfinney.id.au>'`
61     if [ -n "$GREP_OUT" ]; then
62         AUTHORS=`echo "$AUTHORS" | grep -v '^Ben Finney <benf@cybersource.com.au>$'`
63     fi
64
65     # Consolidate Chris Ball
66     GREP_OUT=`echo "$AUTHORS" | grep 'Chris Ball <cjb@laptop.org>'`
67     if [ -n "$GREP_OUT" ]; then
68         AUTHORS=`echo "$AUTHORS" | grep -v '^Chris Ball <cjb@thunk.printf.net>$'`
69     fi
70
71     # Consolidate Trevor King
72     AUTHORS=`echo "$AUTHORS" | grep -v "wking <wking@mjolnir>"`
73
74     # Sort again...
75     AUTHORS=`echo "$AUTHORS" | sort | uniq`
76
77     # Generate new Copyright string
78     if [ "$ORIG_YEAR" == "$CURRENT_YEAR" ]; then
79         DATE_RANGE="$CURRENT_YEAR"
80         DATE_SPACE="    "
81     else
82         DATE_RANGE="${ORIG_YEAR}-${CURRENT_YEAR}"
83         DATE_SPACE="         "
84     fi
85     NUM_AUTHORS=`echo "$AUTHORS" | wc -l`
86     FIRST_AUTHOR=`echo "$AUTHORS" | head -n 1`
87     COPYRIGHT="# Copyright (C) $DATE_RANGE $FIRST_AUTHOR"
88     if [ $NUM_AUTHORS -gt 1 ]; then
89         OTHER_AUTHORS=`echo "$AUTHORS" | tail -n +2`
90         while read AUTHOR; do
91             COPYRIGHT=`echo "$COPYRIGHT\\n#               $DATE_SPACE $AUTHOR"`
92         done < <(echo "$OTHER_AUTHORS")
93     fi
94     echo -e "$COPYRIGHT"
95
96     # Strip old copyright info and replace with tag
97     awk 'BEGIN{incopy=0}{if(match($0, "^# Copyright")>0){incopy=1; print "-xyz-COPYRIGHT-zyx-"}else{if(incopy=0){print $0}else{if(match($0, "^#          ")==0){incopy=0; print $0}}}}' "$file" > "$TMP"
98
99     # Replace tag in with new string
100     sed -i "s/^-xyz-COPYRIGHT-zyx-$/$COPYRIGHT/" "$TMP"
101     cp "$TMP" "$file"
102 done
103
104 rm -f "$TMP"