copyright.sh 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/bin/bash
  2. YEAR=`date "+%Y"`
  3. COPYRIGHT=""
  4. COPYRIGHT+="/*"$'\n'
  5. COPYRIGHT+=" * Copyright 2014-$YEAR The GmSSL Project. All Rights Reserved."$'\n'
  6. COPYRIGHT+=" *"$'\n'
  7. COPYRIGHT+=" * Licensed under the Apache License, Version 2.0 (the "License"); you may"$'\n'
  8. COPYRIGHT+=" * not use this file except in compliance with the License."$'\n'
  9. COPYRIGHT+=" *"$'\n'
  10. COPYRIGHT+=" * http://www.apache.org/licenses/LICENSE-2.0"$'\n'
  11. COPYRIGHT+=" */"
  12. COPYRIGHT_FILE=copyright.txt
  13. echo "$COPYRIGHT" > $COPYRIGHT_FILE
  14. TEMP_FILE=tempfile.temp
  15. touch $TEMP_FILE
  16. copyright_start_string="/*"
  17. copyright_end_string="*/"
  18. function modify_copyright(){
  19. file_path=$1
  20. copyright_start_line=`grep -n "/\*" $file_path | head -1 | cut -d ':' -f 1`
  21. copyright_end_line=`grep -n "\*/" $file_path | head -1| cut -d ':' -f 1`
  22. echo $file_path $copyright_start_line $copyright_end_line
  23. if [[ $copyright_start_line && $copyright_end_line ]];then
  24. sed -i $copyright_start_line,$copyright_end_line'd' $file_path
  25. fi
  26. cat $COPYRIGHT_FILE > $TEMP_FILE
  27. cat $file_path >> $TEMP_FILE
  28. mv $TEMP_FILE $file_path
  29. }
  30. function getDir() {
  31. for filename in $1/*
  32. do
  33. if [[ -d $filename ]];
  34. then
  35. getDir $filename
  36. else
  37. if [[ "${filename##*.}" == 'h' || "${filename##*.}" == 'c' ]]
  38. then
  39. modify_copyright $filename
  40. #sed -i "1i\/*$filename*/" $filename
  41. fi
  42. fi
  43. done
  44. }
  45. getDir ..
  46. rm -f $COPYRIGHT_FILE