Created
July 18, 2018 23:19
-
-
Save rms1000watt/d55aab720612f380034cd20f535dc545 to your computer and use it in GitHub Desktop.
Update License Headers in a Directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| GREP_STR="Copyright Veritone Corporation 2018. All rights reserved." | |
| LICENSE_HASH="# Copyright Veritone Corporation 2018. All rights reserved. | |
| # See LICENSE for more information. | |
| " | |
| LICENSE_SLASH="// Copyright Veritone Corporation 2018. All rights reserved. | |
| // See LICENSE for more information. | |
| " | |
| dir=$1 | |
| if [[ ${dir// } = "" ]]; then | |
| echo "ERROR: No directory to scan" | |
| exit 1 | |
| fi | |
| # Handle files: .go | |
| while read -r file; do | |
| if grep "$GREP_STR" "$file" &> /dev/null; then | |
| continue | |
| fi | |
| echo "Updating: $file" | |
| echo "$LICENSE_SLASH" | cat - "$file" > _- && mv _- "$file" | |
| done <<< "$(find "$dir" -type f -name '*.go')" | |
| # Handle files: .yml .yaml | |
| while read -r file; do | |
| if grep "$GREP_STR" "$file" &> /dev/null; then | |
| continue | |
| fi | |
| echo "Updating: $file" | |
| echo "$LICENSE_HASH" | cat - "$file" > _- && mv _- "$file" | |
| done <<< "$(find "$dir" -type f -name '*.yml' -or -name '*.yaml')" | |
| # Handle files: .sh .bash | |
| while read -r file; do | |
| if grep "$GREP_STR" "$file" &> /dev/null; then | |
| continue | |
| fi | |
| echo "Updating: $file" | |
| shebang="" | |
| firstLine=$(head -n 1 "$file") | |
| if echo "$firstLine" | grep '#!' &> /dev/null; then | |
| shebang=$firstLine | |
| sed '1d' < "$file" > _- && mv _- "$file" | |
| fi | |
| printf "$shebang\\n$LICENSE_HASH" | cat - "$file" > _- && mv _- "$file" | |
| done <<< "$(find "$dir" -type f -name '*.sh' -or -name '*.bash')" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment