PageRenderTime 1986ms CodeModel.GetById 37ms RepoModel.GetById 4ms app.codeStats 0ms

/brlcad/tags/rel-7-12-6/sh/copyright.sh

https://bitbucket.org/vrrm/brl-cad-copy-for-fast-history-browsing-in-git
Shell | 189 lines | 111 code | 16 blank | 62 comment | 8 complexity | 6e7c88a8db5cba876c2c5c9512f97b66 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, LGPL-2.1, Apache-2.0, AGPL-3.0, LGPL-3.0, GPL-3.0, MPL-2.0-no-copyleft-exception, CC-BY-SA-3.0, 0BSD, BSD-3-Clause
  1. #!/bin/sh
  2. # C O P Y R I G H T . S H
  3. # BRL-CAD
  4. #
  5. # Copyright (c) 2004-2008 United States Government as represented by
  6. # the U.S. Army Research Laboratory.
  7. #
  8. # Redistribution and use in source and binary forms, with or without
  9. # modification, are permitted provided that the following conditions
  10. # are met:
  11. #
  12. # 1. Redistributions of source code must retain the above copyright
  13. # notice, this list of conditions and the following disclaimer.
  14. #
  15. # 2. Redistributions in binary form must reproduce the above
  16. # copyright notice, this list of conditions and the following
  17. # disclaimer in the documentation and/or other materials provided
  18. # with the distribution.
  19. #
  20. # 3. The name of the author may not be used to endorse or promote
  21. # products derived from this software without specific prior written
  22. # permission.
  23. #
  24. # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
  25. # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  26. # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  27. # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  28. # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29. # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  30. # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  31. # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  32. # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  33. # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  34. # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. #
  36. ###
  37. #
  38. # This script updates BRL-CAD Copyright notices to include the current
  39. # year in the copyright lines. If provided an argument, the script
  40. # will process just a single file so that it may be used in
  41. # conjunction with find or be used to update files manually.
  42. #
  43. ###
  44. files="$*"
  45. # force locale setting to C so things like date output as expected
  46. LC_ALL=C
  47. # if we weren't already provided with a list of files, generate a list
  48. # of files to check, excluding directories that are not BRL-CAD source
  49. # files, CVS foo, or known binary files.
  50. if [ "x$files" = "x" ] ; then
  51. files="`find . -type f | \
  52. grep -v '/.#' | \
  53. grep -v '.deps/' | \
  54. grep -v '.libs/' | \
  55. grep -v '.svn/' | \
  56. grep -v 'CVS' | \
  57. grep -v 'Makefile$' |\
  58. grep -v 'Makefile.in$' |\
  59. grep -v 'autom4te.cache' | \
  60. grep -v 'config.cache' | \
  61. grep -v 'config.status' | \
  62. grep -v 'misc/enigma/' | \
  63. grep -v 'misc/vfont/' | \
  64. grep -v 'other/' | \
  65. grep -v '\.bak$' |\
  66. grep -v '\.bmp$' |\
  67. grep -v '\.dll$' |\
  68. grep -v '\.g$' | \
  69. grep -v '\.gif$' |\
  70. grep -v '\.ico$' |\
  71. grep -v '\.jpg$' |\
  72. grep -v '\.lo$' |\
  73. grep -v '\.log' |\
  74. grep -v '\.mpg$' |\
  75. grep -v '\.o$' |\
  76. grep -v '\.old$' |\
  77. grep -v '\.pdf$' |\
  78. grep -v '\.pix' |\
  79. grep -v '\.png$' |\
  80. grep -v '#$' |\
  81. grep -v '~$' \
  82. `"
  83. fi
  84. # process the files
  85. for file in $files ; do
  86. echo -n $file
  87. # sanity checks
  88. if [ -d "$file" ] ; then
  89. echo ""
  90. echo "WARNING: $file is a directory, skipping"
  91. continue
  92. elif [ ! -f "$file" ] ; then
  93. echo ""
  94. echo "WARNING: $file does not exist, skipping"
  95. continue
  96. elif [ ! -r "$file" ] ; then
  97. echo ""
  98. echo "WARNING: $file is not readable"
  99. continue
  100. elif [ ! -w "$file" ] ; then
  101. echo ""
  102. echo "WARNING: $file is not writeable"
  103. continue
  104. fi
  105. echo -n "."
  106. if [ -f "$file.copyright.new" ] ; then
  107. # echo ""
  108. # echo "WARNING: $file.copyright.new is in the way (moving it to .bak)"
  109. mv $file.copyright.new $file.copyright.new.bak
  110. elif [ -f "$file.copyright.old" ] ; then
  111. # echo ""
  112. # echo "WARNING: $file.copyright.old is in the way (moving it to .bak)"
  113. mv $file.copyright.old $file.copyright.old.bak
  114. fi
  115. echo -n "."
  116. year=`date +%Y`
  117. sed "s/[cC][oO][pP][yY][rR][iI][gG][hH][tT] \{0,1\}(\{0,1\}[cC]\{0,1\})\{0,1\}.\{0,1\} \{0,1\}\([0-9][0-9][0-9][0-9]\) \{0,1\}-\{0,1\} \{0,1\}[0-9]\{0,1\}[0-9]\{0,1\}[0-9]\{0,1\}[0-9]\{0,1\}\([ .;]\{1,\}\)\(.*United \{1,\}States\)/Copyright (c) \1-$year\2\3/" < $file > $file.copyright.new
  118. echo -n "."
  119. modified=no
  120. filediff="`diff $file $file.copyright.new`"
  121. if [ "x$filediff" = "x" ] ; then
  122. echo -n "."
  123. rm -f $file.copyright.new
  124. elif [ ! "x`echo $filediff | grep \"No newline at end of file\"`" = "x" ] ; then
  125. echo ". `basename $file` has no newline -- SKIPPING"
  126. rm -f $file.copyright.new
  127. continue
  128. elif [ ! "x`echo $filediff | grep \"Binary files\"`" = "x" ] ; then
  129. echo ". `basename $file` is binary -- SKIPPING"
  130. rm -f $file.copyright.new
  131. continue
  132. else
  133. echo -n "."
  134. modified=yes
  135. mv $file $file.copyright.old
  136. mv $file.copyright.new $file
  137. fi
  138. if [ "x$modified" = "xyes" ] ; then
  139. # make sure it's not a current year
  140. sed "s/Copyright ([cC]) $year-$year/Copyright (c) $year/" < $file > $file.copyright.new
  141. echo -n "."
  142. filediff="`diff $file $file.copyright.new`"
  143. if [ "x$filediff" = "x" ] ; then
  144. echo -n "."
  145. rm -f $file.copyright.new
  146. elif [ ! "x`echo $filediff | grep \"No newline at end of file\"`" = "x" ] ; then
  147. echo -n "."
  148. rm -f $file.copyright.new
  149. elif [ ! "x`echo $filediff | grep \"Binary files\"`" = "x" ] ; then
  150. echo -n "."
  151. rm -f $file.copyright.new
  152. else
  153. echo -n "."
  154. modified=no
  155. mv $file $file.repeat.copyright.old
  156. mv $file.copyright.new $file
  157. fi
  158. if [ "x$modified" = "xyes" ] ; then
  159. echo -n ". `basename $file` is MODIFIED"
  160. fi
  161. fi
  162. echo ""
  163. done # iteration over files
  164. echo ""
  165. echo "Done."
  166. # Local Variables:
  167. # mode: sh
  168. # tab-width: 8
  169. # sh-indentation: 4
  170. # sh-basic-offset: 4
  171. # indent-tabs-mode: t
  172. # End:
  173. # ex: shiftwidth=4 tabstop=8