add-copyright.sh 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/sh
  2. TEMPNAME="copyright_script_temp_file"
  3. COPYNAME="copyright_script_copyright_notice"
  4. URL="http://opensimulator.org/"
  5. PROJNAME="OpenSim"
  6. cat > ${COPYNAME} <<EOF
  7. /*
  8. * Copyright (c) Contributors, ${URL}
  9. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions are met:
  13. * * Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. * * Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in the
  17. * documentation and/or other materials provided with the distribution.
  18. * * Neither the name of the ${PROJNAME} Project nor the
  19. * names of its contributors may be used to endorse or promote products
  20. * derived from this software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS \`\`AS IS'' AND ANY
  23. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  24. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  25. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  26. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  27. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  28. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  29. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  31. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. */
  33. EOF
  34. has_bom() {
  35. CHARS=`hexdump -c $1 | head -n1 | cut -d\ -f1-4`
  36. BOMMARK="0000000 357 273 277"
  37. if [ "${CHARS}" == "${BOMMARK}" ]; then
  38. echo 1
  39. else
  40. echo 0
  41. fi
  42. }
  43. for f in `find . -iname "*.cs"`; do
  44. head -n2 $f | tail -n1 > ${TEMPNAME}
  45. grep -q Copyright ${TEMPNAME}
  46. if [ $? == 1 ]; then
  47. BOMSTATUS=`has_bom $f`
  48. rm ${TEMPNAME}
  49. if [ ${BOMSTATUS} == 1 ]; then
  50. echo -ne \\0357\\0273\\0277 > ${TEMPNAME}
  51. fi
  52. cat ${COPYNAME} >> ${TEMPNAME}
  53. if [ ${BOMSTATUS} == 1 ]; then
  54. cat $f | perl -p -e "s/^\\xEF\\xBB\\xBF//" >> ${TEMPNAME}
  55. else
  56. cat $f >> ${TEMPNAME}
  57. fi
  58. mv ${TEMPNAME} $f
  59. fi
  60. done
  61. rm -f ${COPYNAME} ${TEMPNAME}