Whamcloud - gitweb
LU-228 kernel update [RHEL5 U6 2.6.18-238.9.1.el5]
[fs/lustre-release.git] / build / updatecw.sh
1 #!/bin/bash
2 # Update existing Sun copyright notices to Oracle copyright notices
3 # Does not add copyright notices to files that are missing them
4 #
5 # Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
6 #
7
8 TMP=${TMP:-/tmp}
9 TMPFILE=$(mktemp $TMP/updatecopy.XXXXXX)
10 NOW=$(date +%Y)
11
12 SUNCOPY="Copyright.*Sun Micro.*"
13 ORACOPY="Copyright.*Oracle.*"
14 LECDATE="2010-02-15"
15  
16 git ls-files build ldiskfs libcfs lnet lustre snmp |grep -v ${0##*/} | while read FILE; do
17     # Pick only files that have changed since LECDATE
18     if [ -n "$(git log -n1 --since=$LECDATE  $FILE)" ]; then
19         OLDCOPY="$(egrep "$SUNCOPY|$ORACOPY" $FILE | sed 's/.*Copy/Copy/')"
20         if [ -z "$OLDCOPY" ]; then
21             case $FILE in
22                 *.[ch]) echo "$FILE: no Copyright" && continue ;;
23                 *) continue ;;
24             esac
25         else
26         # skip files that already have a copyright for this year
27             echo "$OLDCOPY" | grep -q "$NOW.*Oracle" && continue
28         fi
29
30         # Get commit dates
31         git log --follow --pretty=format:%ci $FILE | cut -d- -f1 > $TMPFILE
32         NEWYEAR=$(head -1 $TMPFILE)
33         OLDYEAR=$(tail -1 $TMPFILE)
34         rm $TMPFILE
35
36         [ $NEWYEAR == $OLDYEAR ] && YEAR="$NEWYEAR" || YEAR="$OLDYEAR, $NEWYEAR"
37
38         NEWCOPY="Copyright (c) $YEAR, Oracle and/or its affiliates. All rights reserved."
39
40         # If the copyright isn't different (excluding whitespace), don't change it.
41         [ "$OLDCOPY" == "$NEWCOPY" ] && continue
42
43         [ ! -w $FILE ] && echo "Unable to write to $FILE" && exit 1
44
45         echo "$FILE: Copyright $YEAR"
46         sed -e "s#$ORACOPY#$NEWCOPY#" -e "s#$SUNCOPY#$NEWCOPY#" $FILE > $FILE.tmp
47         cp $FILE.tmp $FILE      # preserve owner/mode
48         rm $FILE.tmp
49     fi
50 done