Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
NDN project license boilerplate update
#!/bin/bash
# https://gist.github.com/yoursunny/6297f3c70f5441213184
LICENSE_NFD='''/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
* Washington University in St. Louis,
* Beijing Institute of Technology,
* The University of Memphis.
*
* This file is part of NFD (Named Data Networking Forwarding Daemon).
* See AUTHORS.md for complete list of NFD authors and contributors.
*
* NFD 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.
*
* NFD 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
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.'''
LICENSE_NDNCXX='''/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2013-2019 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
* ndn-cxx library is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* ndn-cxx library 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 Lesser General Public License for more details.
*
* You should have received copies of the GNU General Public License and GNU Lesser
* General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
* <http://www.gnu.org/licenses/>.
*
* See AUTHORS.md for complete list of ndn-cxx authors and contributors.'''
LICENSE_PSYNC='''/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2019, The University of Memphis
*
* This file is part of PSync.
* See AUTHORS.md for complete list of PSync authors and contributors.
*
* PSync is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* PSync 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* PSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.'''
LICENSE_END=' */'
if git remote show origin | grep 'NFD' > /dev/null; then
LICENSE=$LICENSE_NFD
elif git remote show origin | grep 'ndn-cxx' > /dev/null; then
LICENSE=$LICENSE_NDNCXX
elif git remote show origin | grep 'PSync' > /dev/null; then
LICENSE=$LICENSE_PSYNC
LICENSE_END=' **/'
else
echo 'unknown project'
exit 1
fi
function update_license {
F=$1
echo "$LICENSE" > $F.new
awk '
BEGIN {
FS = "6175a610-db7d-4871-886e-e7931739d899"
foundLicense = "before"
nAuthors = 0
nBlanksAfter = 0
}
foundLicense == "before" && $1 !~ /^[\/ ]\*/ {
foundLicense = "just-after"
print " */"
}
foundLicense == "before" && /\* Copyright/ {
foundLicense = "in"
}
foundLicense == "in" && $1 ~ /^ \* [\\\@]author/ {
if (nAuthors++ == 0) {
print " *"
}
print
next
}
foundLicense == "in" && /^ \*[\*]?\// {
foundLicense = "just-after"
print "'"$LICENSE_END"'"
next
}
foundLicense == "just-after" && $1 == "" {
if (++nBlanksAfter == 1) {
print
}
}
foundLicense == "just-after" && $1 != "" {
foundLicense = "after"
}
foundLicense == "after" {
print
}
' $F >> $F.new
mv $F.new $F
}
BASE=$1
if [[ -z $BASE ]]; then
BASE=HEAD
fi
for F in $(git diff $BASE --name-only | grep -E '(\.hpp|\.cpp)$'); do
if [[ -f $F ]]; then
echo $F
update_license $F
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment