1
0
Fork 0
easejs/tools/copyright

121 lines
3.1 KiB
Plaintext
Raw Permalink Normal View History

#!/bin/bash
# Updates copyright of various source files and commits to repository
#
# Copyright (C) 2013, 2014 Free Software Foundation, Inc.
#
# This file is part of GNU ease.js.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Please note that this file will update itself. Further, it will only
# update files that state ``this file is part of ease.js''.
#
# This script will look up the modification dates from the file commits and
# update the copyright line accordingly. Since the history must not include
# the copyright update itself, this script will also perform the commit
# (feel free to amend afterward) to ensure consistency in future filtering.
#
# This should be run from the tools directory.
##
owner="${@:?Missing copyright owner}"
# refuse to run on a dirty tree
if [ -n "$( git status --short | grep -v ^?? )" ]; then
echo 'Please stash or commit your changes.' >&2
exit 1
fi
# safety check
wd="$(pwd)"
[ "${wd##*/}" == tools ] || {
echo 'Please run from within tools directory' >&2
exit 1
}
# enable extglob for !()
shopt -s extglob || {
echo 'extglob unsupported' >&2
exit 1
}
# we will be updating all files that contain this line
ident='This \(file\|document\) is part of \(the \)\?GNU ease.js'
ignorepath='.git|build|webroot|node_modules'
files=$( grep -rl "$ident" ../!($ignorepath) )
(
echo 'The following files will be updated to reflect modification years:'
echo
echo "$files"
) | less -EX
read -p 'Are you sure you want to continue (y/N)? ' c
[[ "$c" == [yY] ]] || {
echo 'Aborting.' >&2
exit 1
}
copyupdate()
{
local years="$1"
local file="$2"
sed -i "s/\(. \+Copyright (C) \).*\$/\\1$years $owner/" "$file"
}
getyears()
{
grep -vF '[copyright]'$'\n''[no-copyright]' \
| cut -d' ' -f4 \
| sort -u \
| tr '\n' , \
| sed 's/,/, /g;s/, $//'
}
# have at it
for file in $files; do
ext="${file##*/*.}"
echo -n "updating $file..."
# determine copyrightable years from commit log and format as year1, year2,
# ..., yearn (TODO: join consecutive years with dash)
years="$(
git log --format='%aD %s' --follow -- "$file" \
| getyears
)"
# no years, then no history
if [ -z "$years" ]; then
echo 'unknown; skipped.'
continue
fi
# perform copyright update
copyupdate "$years" "$file"
echo "$years."
done
# general license templates will contain all copyright years
years="$(
git log --format='%aD %s' \
| getyears
)"
copyupdate "$years" license.tpl
copyupdate "$years" license-min.tpl
# commit
git commit -am '[copyright] Copyright update'