3 # Copyright (C) 2009 W. Trevor King <wking@drexel.edu>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
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.
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 # Update copyright information in source code with information from
20 # the bzr repository. Run from the BE repository root.
22 # Replaces everything starting with '^# Copyright' and continuing with
23 # '^#' with an auto-generated copyright blurb. If you want to add
24 # #-commented material after a copyright blurb, please insert a blank
25 # line between the blurb and your comment (as in this file), so the
26 # next run of update_copyright.sh doesn't clobber your comment.
28 # usage: update_copyright.sh [files ...]
30 # If no files are given, a list of files to update is generated
38 FILES=`grep -rc "# Copyright" . | grep -v ':0$' | cut -d: -f1`
42 # This program is free software; you can redistribute it and/or modify
43 # it under the terms of the GNU General Public License as published by
44 # the Free Software Foundation; either version 2 of the License, or
45 # (at your option) any later version.
47 # This program is distributed in the hope that it will be useful,
48 # but WITHOUT ANY WARRANTY; without even the implied warranty of
49 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
50 # GNU General Public License for more details.
52 # You should have received a copy of the GNU General Public License along
53 # with this program; if not, write to the Free Software Foundation, Inc.,
54 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA."
55 # escape newlines and special characters
56 SED_RM_TRAIL_END='s/[\]n$//' # strip trailing newline escape
57 SED_ESC_SPECIAL='s/\([()/]\)/\\\1/g' # escape special characters
58 ESCAPED_TEXT=`echo "$COPYRIGHT_TEXT" | awk '{printf("%s\\\\n", $0)}' | sed "$SED_RM_TRAIL_END" | sed "$SED_ESC_SPECIAL"`
60 # adjust the AUTHORS file
61 AUTHORS=`bzr log | grep '^ *committer\|^ *author' | cut -d: -f2 | sed 's/ <.*//;s/^ *//' | sort | uniq`
62 AUTHORS=`echo "$AUTHORS" | grep -v 'j\^\|wking\|John Doe\|gianluca'` # remove non-names
63 echo "Bugs Everywhere was written by:" > AUTHORS
64 echo "$AUTHORS" >> AUTHORS
66 CURRENT_YEAR=`date +"%Y"`
67 TMP=`mktemp BE_update_copyright.XXXXXXX`
72 if [ "${file:0:5}" == "./.be" ]; then
75 if [ "${file:0:6}" == "./.bzr" ]; then
78 if [ "${file:0:7}" == "./build" ]; then
81 if [ "$file" == "./COPYING" ]; then
84 if [ "$file" == "./update_copyright.sh" ]; then
87 if [ "$file" == "./xml/catmutt" ]; then
90 echo "Processing $file"
92 # Get author history from bzr
93 AUTHORS=`bzr log "$file" | grep "^ *author: \|^ *committer: " | cut -d: -f2 | sed 's/^ *//;s/ *$//' | sort | uniq`
95 continue # bzr doesn't version that file
97 ORIG_YEAR=`bzr log "$file" | grep "^ *timestamp: " | tail -n1 | sed 's/^ *//;' | cut -b 16-19`
99 # Tweak the author list to make up for problems in the bzr
100 # history, change of email address, etc.
102 # Consolidate Chris Ball
103 GREP_OUT=`echo "$AUTHORS" | grep 'Chris Ball <cjb@laptop.org>'`
104 if [ -n "$GREP_OUT" ]; then
105 AUTHORS=`echo "$AUTHORS" | grep -v '^Chris Ball <cjb@thunk.printf.net>$'`
108 # Consolidate Aaron Bentley
109 AUTHORS=`echo "$AUTHORS" | sed 's/<abentley@panoramicfeedback.com>/and Panometrics, Inc./'`
110 GREP_OUT=`echo "$AUTHORS" | grep 'Aaron Bentley and Panometrics, Inc.'`
111 if [ -n "$GREP_OUT" ]; then
112 AUTHORS=`echo "$AUTHORS" | grep -v '^Aaron Bentley <aaron.bentley@utoronto.ca>$'`
115 # Consolidate Ben Finney
116 AUTHORS=`echo "$AUTHORS" | sed 's/John Doe <jdoe@example.com>/Ben Finney <ben+python@benfinney.id.au>/'`
117 GREP_OUt=`echo "$AUTHORS" | grep 'Ben Finney <ben+python@benfinney.id.au>'`
118 if [ -n "$GREP_OUT" ]; then
119 AUTHORS=`echo "$AUTHORS" | grep -v '^Ben Finney <benf@cybersource.com.au>$'`
122 # Consolidate Trevor King
123 AUTHORS=`echo "$AUTHORS" | grep -v "wking <wking@mjolnir>"`
125 # Consolidate Gianluca Montecchi
126 AUTHORS=`echo "$AUTHORS" | grep -v "gianluca"`
129 AUTHORS=`echo "$AUTHORS" | sort | uniq`
131 # Generate new Copyright string
132 if [ "$ORIG_YEAR" == "$CURRENT_YEAR" ]; then
133 DATE_RANGE="$CURRENT_YEAR"
136 DATE_RANGE="${ORIG_YEAR}-${CURRENT_YEAR}"
139 NUM_AUTHORS=`echo "$AUTHORS" | wc -l`
140 FIRST_AUTHOR=`echo "$AUTHORS" | head -n 1`
141 COPYRIGHT="# Copyright (C) $DATE_RANGE $FIRST_AUTHOR"
142 if [ $NUM_AUTHORS -gt 1 ]; then
143 OTHER_AUTHORS=`echo "$AUTHORS" | tail -n +2`
144 while read AUTHOR; do
145 COPYRIGHT=`echo "$COPYRIGHT\\n# $DATE_SPACE $AUTHOR"`
146 done < <(echo "$OTHER_AUTHORS")
148 COPYRIGHT=`echo "$COPYRIGHT\\n$ESCAPED_TEXT"`
150 # Strip old copyright info and replace with tag
151 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"
153 # Replace tag in with new string
154 sed -i "s/^-xyz-COPYRIGHT-zyx-$/$COPYRIGHT/" "$TMP"