2 # Adds Whamcloud copyright notices to files modified by Whamcloud.
3 # Does not add copyright notices to files that are missing them
5 # Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
6 # Copyright (c) 2012, 2013, Intel Corporation.
9 TMPFILE=$(mktemp $TMP/updatecopy.XXXXXX)
10 EXCFILE=$(mktemp $TMP/excludecopy.XXXXXX)
12 DIRS=${DIRS:-"build ldiskfs libcfs lnet lustre snmp lustre-iokit"}
14 EXCLUDE=${EXCLUDE:-'e3a7c58aebafce40323db54bf6056029e5af4a70\n
15 65701b4a30efdb695776bcf690a2b3cabc928da1\n
16 f2a9374170e4522b9d2ac3b7096cf2912339d480\n
17 3f90f344ae059b30e7d23e4fe554a985eb827b02\n
18 320e014a2c93cb905637d178269b80847cb8d277\n
19 08aa217ce49aba1ded52e0f7adb8a607035123fd\n
20 2841be335687840cf98961e6c6cde6ee9312e4d7\n
21 cd8c65642f1c36b56ae74a0414a1f1f27337a662'}
23 XYRACOPY="Copyright.*Xyratex Technology Limited"
24 ORACOPY1="Copyright.*Oracle.*"
25 ORACOPY2="Use is subject to license terms."
26 #Copyright we rewrite to the current version
27 WHAMCOPY=${WHAMCOPY:-"Copyright.*Whamcloud,* Inc."}
28 INTREPCOPY=${INTREPCOPY:-"Copyright.*Intel, Inc."}
29 INTREPCOPY2=${INTREPCOPY2:-"Copyright.*Intel Corporation$"}
30 #The current copyright
31 INTCOPY=${INTCOPY:-"Copyright.*Intel Corporation."}
33 #Emails we assume ownership of
34 AUTH_WHAM=${AUTH_WHAM:-".*@whamcloud.com"}
35 AUTH_INT=${AUTH_INT:-".*@intel.com"}
38 START=${START:-"2010-06-01"}
39 ECHOE=${ECHOE:-"echo -e"}
40 [ "$($ECHOE foo)" = "-e foo" ] && ECHOE=echo
42 echo -e $EXCLUDE > $EXCFILE
44 git ls-files $DIRS | grep -v ${0##*/} | while read FILE; do
45 if [ "$FILE" == 'contrib/scripts/updatecw.sh' ]; then
46 echo $FILE": *** EDIT MANUALLY ***"
51 # Pick only files that have changed since START
52 # %ai author dates holds has bad data: April 2013
53 git log --follow --since=$START --pretty=format:"%ae %ci %H" $FILE |\
54 grep -v -f $EXCFILE |\
55 awk "/$AUTH_WHAM|$AUTH_INT/ {print substr(\$2,1,4)}"> $TMPFILE
57 # Skip files not modified by $AUTHOR
58 [ -s "$TMPFILE" ] || continue
60 OLDCOPY="$(egrep -e "$XYRACOPY|$ORACOPY1|$ORACOPY2|$WHAMCOPY|$INTCOPY"\
61 -e "$INTREPCOPY|$INTREPCOPY2" $FILE|tail -n1 | tr / .)"
63 if [ -z "$OLDCOPY" ]; then
65 *.[ch]) echo "$FILE: ** INSPECT **" && continue ;;
69 OLDCOPY=$(egrep "$WHAMCOPY|$INTCOPY|$INTREPCOPY|$INTREPCOPY2"\
70 $FILE|tail -n1|tr / .)
72 if [ -z "$(egrep "$INTCOPY|$INTREPCOPY|$INTERCOPY2|$WHAMCOPY"\
76 OLDCOPY="$(egrep "$XYRACOPY|$ORACOPY1|$ORACOPY2" $FILE |
78 elif [ -n "$(grep -e "$INTCOPY" <<<"$OLDCOPY")" ]; then
79 # Skip files that already have a copyright for this year
80 echo "$OLDCOPY" | grep -q "$NOW" && continue
84 NEWYEAR=$(head -1 $TMPFILE)
85 OLDYEAR=$(tail -1 $TMPFILE)
87 if [ "$NEWYEAR" -lt "$OLDYEAR" ]; then
88 echo "$FILE: ** YEAR INVERSION: INSPECT **"
92 [ $NEWYEAR == $OLDYEAR ] && YEAR="$NEWYEAR" || YEAR="$OLDYEAR, $NEWYEAR"
93 COMMENT=$(echo "$OLDCOPY" | sed -e "s/^\( *[^A-Z]*\) [A-Z].*/\1/")
94 NEWCOPY=$(sed -e "s/^/$COMMENT /" -e "s/\.\*/ (c) $YEAR, /" <<<$INTCOPY)
96 # '.\"' as a COMMENT isn't escaped correctly
97 if [ "$COMMENT" == ".\\\"" ]; then # add " to fix vim
98 echo "$FILE: *** EDIT MANUALLY ***"
102 # If copyright is unchanged (excluding whitespace), we're done
103 [ "$OLDCOPY" == "$NEWCOPY" ] && continue
105 [ ! -w $FILE ] && echo "Unable to write to $FILE" && exit 1
108 echo "$FILE: Copyright $YEAR (new Copyright added)"
109 # Add a new copyright line after the existing copyright.
110 # Using a temporary file is ugly, but I couldn't get
111 # newlines into the substitution pattern for some reason,
112 # and this is not a performance-critical process.
113 $ECHOE "${COMMENT}\n${NEWCOPY}" > $TMPFILE
114 sed -e "/$OLDCOPY/r $TMPFILE" $FILE > $FILE.tmp
116 echo "$FILE: Copyright $YEAR"
117 # Replace the old copyright line with a new copyright
118 sed -e "s/.*$INTREPCOPY/$NEWCOPY/" -e "s/.*$INTCOPY/$NEWCOPY/"\
119 -e "s/.*$INTREPCOPY2/$NEWCOPY/" -e "s/.*$WHAMCOPY/$NEWCOPY/"\
122 [ -s $FILE.tmp ] && cp $FILE.tmp $FILE