Guest User

Untitled

a guest
Jul 18th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. GREP_STR="Copyright Veritone Corporation 2018. All rights reserved."
  4. LICENSE_HASH="# Copyright Veritone Corporation 2018. All rights reserved.
  5. # See LICENSE for more information.
  6. "
  7. LICENSE_SLASH="// Copyright Veritone Corporation 2018. All rights reserved.
  8. // See LICENSE for more information.
  9. "
  10.  
  11. dir=$1
  12.  
  13. if [[ ${dir// } = "" ]]; then
  14. echo "ERROR: No directory to scan"
  15. exit 1
  16. fi
  17.  
  18. # Handle files: .go
  19. while read -r file; do
  20. if grep "$GREP_STR" "$file" &> /dev/null; then
  21. continue
  22. fi
  23. echo "Updating: $file"
  24. echo "$LICENSE_SLASH" | cat - "$file" > _- && mv _- "$file"
  25. done <<< "$(find "$dir" -type f -name '*.go')"
  26.  
  27. # Handle files: .yml .yaml
  28. while read -r file; do
  29. if grep "$GREP_STR" "$file" &> /dev/null; then
  30. continue
  31. fi
  32. echo "Updating: $file"
  33. echo "$LICENSE_HASH" | cat - "$file" > _- && mv _- "$file"
  34. done <<< "$(find "$dir" -type f -name '*.yml' -or -name '*.yaml')"
  35.  
  36. # Handle files: .sh .bash
  37. while read -r file; do
  38. if grep "$GREP_STR" "$file" &> /dev/null; then
  39. continue
  40. fi
  41. echo "Updating: $file"
  42.  
  43. shebang=""
  44. firstLine=$(head -n 1 "$file")
  45. if echo "$firstLine" | grep '#!' &> /dev/null; then
  46. shebang=$firstLine
  47. sed '1d' < "$file" > _- && mv _- "$file"
  48. fi
  49.  
  50. printf "$shebang\\n$LICENSE_HASH" | cat - "$file" > _- && mv _- "$file"
  51. done <<< "$(find "$dir" -type f -name '*.sh' -or -name '*.bash')"
Add Comment
Please, Sign In to add comment