2 # t2/scripts/Create-CopyPatch
3 # Copyright (C) 2004 - 2025 The T2 SDE Project
4 # Copyright (C) 1998 - 2003 ROCK Linux Project
5 # SPDX-License-Identifier: GPL-2.0
6 # --- T2-COPYRIGHT-END ---
10 copynotepatch
=$tmpfile.
patch
11 rocknote
=$tmpfile.rock
15 cat << EOT > $copynote
20 cp $copynote $copynotepatch
22 cat << EOT >> $copynote
23 SPDX-License-Identifier: GPL-2.0
26 cat << EOT >> $copynotepatch
27 SPDX-License-Identifier: GPL-2.0 or patched project license
30 echo "Creating copy.patch ..." >&2
33 if [ "$1" = "-svn" ]; then
38 set architecture
/. misc
/. package
/.
scripts
/. target
/.
40 # check if file or package name was given
43 if [ -f $i -o -d $i ]; then
44 files
="$files ${i#./}"
45 elif [ -d package
/*/$i ]; then
46 for each
in `echo package/*/$i`; do
47 [[ $each = *~
]] && continue
48 files
="$files $each/."
51 echo Cannot
find \'$i\', ignoring.
1>&2
58 bash
scripts
/xfind.sh $
* -type f
! -name "*~" ! -name Create-CopyPatch |
sed 's,/\./,/,g' |
59 while read filename
; do
60 # determine the comment mode first
64 */Makefile|
*.sh|
*.pl|
*.
in|
*.hlp|
*.conf
) mode
=sh
;;
65 *.cron|
*.postinstall|
*.init
) mode
=sh
;;
66 *.h|
*.c|
*.cc|
*.cpp|
*.
lex|
*.y|
*.spec|
*.tcx|
*.tmpl|
*.tcc
) mode
=c
;;
69 *scripts
/[A-Z
][a-z-
]*|
*/parse-config
*) mode
=sh
;;
70 *patch|
*diff|
*patch.
*) mode
=sh
;;
74 #echo "Mode type: $mode"
76 grep -q -- '--- NO-\(T2\|ROCK\)-COPYRIGHT.* ---' "$filename" && continue
81 if head -n 1 "$filename" |
grep -q '^#!'; then
84 case "`sed -n 's/^ *\([^ ]\+\) .*COPYRIGHT-.*BEGIN .*/\1/p' "$filename"`" in
90 if [ "$mode" == none
]; then
91 echo "Unknown type for $filename" 1>&2
96 # make a copy in the case we have no matching conditional below
97 sed 's,\(ROCK\|T2\)-COPYRIGHT-NOTE,T2-COPYRIGHT,g' "$filename" > "$oldfile"
99 tag
=$
(sed -n -e '/^\(.*\)--- T2-COPYRIGHT-.*BEGIN ---.*/{s//\1/;p;q;}' "$oldfile")
102 if [ -n "$tag" ]; then
103 # has a note, catch copyrights
104 oldcopyright
=`sed -e '/--- T2-COPYRIGHT-.*BEGIN ---/,/--- T2-COPYRIGHT-.*END ---/!d' \
105 -e '/.*\(Copyright (C) .*\)/!d;s//\1/;' \
106 -e 's/Clifford Wolf/ROCK Linux Project/' \
112 if echo "$oldcopyright" |
grep -q 'T2 SDE'; then
113 # if has T2 copyright, renew if necesary
114 since
=$
(echo "$oldcopyright" |
sed -n -e 's,.* (C) \([^ ]*\) .*T2 SDE.*,\1,p')
116 if [ $since -lt $thisyear ]; then
117 copyright
=`echo "$oldcopyright" | sed -e \
118 "s,.*T2 SDE.*,Copyright (C) $since - $thisyear The T2 SDE Project,"`
120 copyright
="$oldcopyright"
124 if [ "$usesvn" = 1 ]; then
125 since
=`TZ=UTC svn log -q "$filename" 2> /dev/null |
126 grep -a '^r' | tail -n 1 | cut -d'|' -f3 | cut -c2-5`
128 # but until 2003 we were ROCK Linux, so
129 if [ ${since:-2004} -lt 2004 ]; then
130 oldcopyright
="Copyright (C) $since - 2003 ROCK Linux Project"
137 # prepare a copyright tag
138 if [ ${since:-1} -lt $thisyear ]; then
139 copyright
="Copyright (C) ${since:-ESVNTO} - $thisyear The T2 SDE Project"
141 copyright
="Copyright (C) $thisyear The T2 SDE Project"
143 copyright
="$copyright${oldcopyright:+\\n$oldcopyright}"
148 if [ -z "$tag" ]; then
149 # doesn't have a note
150 if head -n 1 "$filename" |
grep -a -q '^#!'; then
161 pretag
='/*' posttag
=' */'
175 }$tag--- T2-COPYRIGHT-BEGIN ---\\
176 $tag--- T2-COPYRIGHT-END ---\\
177 ${posttag:+$posttag\\
181 mangled_filename
=`echo "$filename" |
182 sed 's,package/\([^/]*\)/\(.*\),package/*/\2,'`
188 # implant T2 copy note
190 grep -a -B 1000000 -- '--- T2-COPYRIGHT-.*BEGIN ---' $oldfile
192 if [ "$filename" != "${filename%/*.diff}" -o \
193 "$filename" != "${filename%/*.patch}" -o \
194 "$filename" != "${filename%/*.patch.*}" ]; then
195 sed -e "s,@@FILENAME@@,$mangled_filename,; \
196 s,@@COPYRIGHT@@,${copyright//
197 /\\n},;" $copynotepatch
199 sed -e "s,@@FILENAME@@,$mangled_filename,; \
200 s,@@COPYRIGHT@@,${copyright//
203 # we need a separated sed call because $rockcopyright adds a new line
204 } |
sed -e "s,^,$tag,"
206 grep -a -A 1000000 -- '--- T2-COPYRIGHT-.*END ---' $oldfile
209 # create the difference
210 if ! cmp -s $oldfile $newfile; then
211 echo "Creating patch for $filename." >&2
212 diff -ua "./$filename" $newfile |
213 sed -e "2 s,$newfile,./$filename,"
216 echo "WARNING: No Copyright tags in $filename found!" >&2
220 rm -f $tmpfile{,.note
,.
patch,.rock
,.old
,.new
}