update-license-headers.sh 714 B

12345678910111213141516
  1. #!/bin/bash
  2. # Updates a file's license header to the first year a commit touched it.
  3. # Example: find -name \*.cpp -o -name \*.h|xargs -n1 -P8 /path/to/Tools/update-license-headers.sh
  4. filename=$1
  5. echo "Updating $filename..."
  6. year=$(git log --diff-filter=A --follow --format=%ad --date=short "$1"|tail -n1|cut -d- -f1)
  7. if [[ "$(head -n1 "$filename" | grep Copyright)" == "" ]]
  8. then
  9. tmp="$(mktemp)"
  10. echo -e "// Copyright $year Dolphin Emulator Project\n// Licensed under GPLv2+\n// Refer to the license.txt file included.\n"|cat - "$filename" >"$tmp"
  11. mv "$tmp" "$filename"
  12. else
  13. sed -ri "1 s|// Copyright ([0-9-]+) Dolphin Emulator Project|// Copyright $year Dolphin Emulator Project|" "$filename"
  14. fi