Created
January 28, 2022 23:03
-
-
Save bettio/9fe192d8b03411a4ffc8d3e4bc496429 to your computer and use it in GitHub Desktop.
Add Apache 2.0 license to all files without license
This file contains 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
#!/bin/bash | |
IFILE=$1 | |
./printlicense.sh $IFILE > "$IFILE.new" | |
echo "" >> "$IFILE.new" | |
cat $IFILE >> "$IFILE.new" | |
mv "$IFILE.new" $IFILE |
This file contains 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
git grep -l -I -v 'www.apache.org' | xargs -L1 ./insertlicense.sh |
This file contains 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
#!/bin/bash | |
FILE=$1 | |
FIRST_Y=`git log --diff-filter=A --follow --format=%aI -- $FILE | tail -1 | cut -d '-' -f 1` | |
LAST_Y=`git log -1 --format=%aI -- $FILE | tail -1 | cut -d '-' -f 1` | |
NAME=`git log --diff-filter=A --follow --format="%an <%ae>" -- $FILE` | |
FNAME=`basename $FILE` | |
case "${FNAME#*.}" in | |
"erl") | |
OPENING='%' | |
CLOSING='%' | |
COMMENT='%' | |
;; | |
"ex") | |
OPENING='#' | |
CLOSING='#' | |
COMMENT='#' | |
;; | |
"exs") | |
OPENING='#' | |
CLOSING='#' | |
COMMENT='#' | |
;; | |
"c") | |
OPENING='/*' | |
CLOSING=' */' | |
COMMENT=' *' | |
;; | |
*) | |
OPENING='#' | |
CLOSING='#' | |
COMMENT='#' | |
;; | |
esac | |
echo "$OPENING" >> "$FILE.new" | |
sed "s/%/$COMMENT/g" <<'END' | |
% This file is part of AtomVM. | |
% | |
END >> "$FILE.new" | |
if [ "$FIRST_Y" -eq "$LAST_Y" ]; then | |
echo "% Copyright $FIRST_Y $NAME" | sed "s/%/$COMMENT/g" | |
else | |
echo "% Copyright $FIRST_Y-$LAST_Y $NAME" | sed "s/%/$COMMENT/g" | |
fi | |
sed "s/%/$COMMENT/g" <<'END' | |
% | |
% Licensed under the Apache License, Version 2.0 (the "License"); | |
% you may not use this file except in compliance with the License. | |
% You may obtain a copy of the License at | |
% | |
% http://www.apache.org/licenses/LICENSE-2.0 | |
% | |
% Unless required by applicable law or agreed to in writing, software | |
% distributed under the License is distributed on an "AS IS" BASIS, | |
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
% See the License for the specific language governing permissions and | |
% limitations under the License. | |
% | |
% SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later | |
END | |
echo "$CLOSING" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment