add-copyright.sh 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. */
  34. EOF
  35. has_bom() {
  36. CHARS=`hexdump -c $1 | head -n1 | cut -d\ -f1-4`
  37. BOMMARK="0000000 357 273 277"
  38. if [ "${CHARS}" == "${BOMMARK}" ]; then
  39. echo 1
  40. else
  41. echo 0
  42. fi
  43. }
  44. for f in `find . -iname "*.cs"`; do
  45. head -n2 $f | tail -n1 > ${TEMPNAME}
  46. grep -q Copyright ${TEMPNAME}
  47. if [ $? == 1 ]; then
  48. BOMSTATUS=`has_bom $f`
  49. rm ${TEMPNAME}
  50. if [ ${BOMSTATUS} == 1 ]; then
  51. echo -ne \\0357\\0273\\0277 > ${TEMPNAME}
  52. fi
  53. cat ${COPYNAME} >> ${TEMPNAME}
  54. if [ ${BOMSTATUS} == 1 ]; then
  55. cat $f | perl -p -e "s/^\\xEF\\xBB\\xBF//" >> ${TEMPNAME}
  56. else
  57. cat $f >> ${TEMPNAME}
  58. fi
  59. mv ${TEMPNAME} $f
  60. fi
  61. done
  62. rm -f ${COPYNAME} ${TEMPNAME}