2013-12-20 00:46:48 -05:00
|
|
|
#!/bin/bash
|
|
|
|
# Updates copyright of various source files and commits to repository
|
|
|
|
#
|
|
|
|
# Copyright (C) 2013 Mike Gerwitz
|
|
|
|
#
|
2013-12-22 09:37:21 -05:00
|
|
|
# This file is part of GNU ease.js.
|
2013-12-20 00:46:48 -05:00
|
|
|
#
|
|
|
|
# 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
|
2013-12-23 00:28:23 -05:00
|
|
|
ident='This \(file\|document\) is part of \(the \)\?GNU ease.js'
|
2013-12-20 00:46:48 -05:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2013-12-20 01:16:18 -05:00
|
|
|
copyupdate()
|
|
|
|
{
|
|
|
|
years="$1"
|
|
|
|
file="$2"
|
|
|
|
|
|
|
|
sed -i "s/\(. \+Copyright (C) \).*\$/\\1$years $owner/" "$file"
|
|
|
|
}
|
|
|
|
|
2013-12-20 00:46:48 -05:00
|
|
|
# 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=$(
|
2013-12-22 08:53:01 -05:00
|
|
|
git log --format='%aD %s' --follow -- "$file" \
|
2013-12-20 00:46:48 -05:00
|
|
|
| grep -vF '[copyright]' \
|
|
|
|
| cut -d' ' -f4 \
|
|
|
|
| sort -u \
|
|
|
|
| tr '\n' , \
|
|
|
|
| sed 's/,/, /g;s/, $//'
|
|
|
|
)
|
|
|
|
|
|
|
|
# no years, then no history
|
|
|
|
if [ -z "$years" ]; then
|
|
|
|
echo 'unknown; skipped.'
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
# perform copyright update
|
2013-12-20 01:16:18 -05:00
|
|
|
copyupdate "$years" "$file"
|
2013-12-20 00:46:48 -05:00
|
|
|
echo "$years."
|
|
|
|
done
|
|
|
|
|
2013-12-20 01:16:18 -05:00
|
|
|
# general files
|
|
|
|
year="$( date +%Y )"
|
|
|
|
copyupdate "$year" license.tpl
|
|
|
|
copyupdate "$year" license-min.tpl
|
|
|
|
|
2013-12-20 00:46:48 -05:00
|
|
|
# commit
|
|
|
|
git commit -am '[copyright] Copyright update'
|