#!/bin/sh
#
# Runs an automated search for licensing information within a source package.
# This is a useful starting point for a full license audit.
#
# Written to help with KDE packaging.  Looks for:
#
# - License headers in source files (.c, .cpp, .cc, .C, .h)
# - Explicit license files (COPYING, LICENSE)
# - License tags in .plugin and .desktop files
# - License_* arguments to KAboutData constructors
# - Legal notices in docbook documentation
#
# Usage:
#
#   Run this script from the top-level source directory.  Information
#   will be written to standard output.  There will be a lot of it, so
#   you will probably want to redirect standard output elsewhere.
#
# Example:
#
#   /path/to/source-licenseinfo > ../licenses
#
# Changes:
#
#   14 Mar 2005: Initial implementation
#
# Copyright (c) 2005, Ben Burton <bab@debian.org>
#
# 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 2 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.

if ! [ -e configure -o -e admin/Makefile.common -o -d debian ]; then
  echo "This script must be run from the top-level source directory."
  exit 1
fi

if [ ! -x /usr/bin/licensecheck ]; then
  echo "This script requires the licensecheck script."
  echo "Please install the kdesdk-scripts package."
  exit 1
fi

echo "Running licensecheck over C/C++ sources..."
echo

for i in `find . -name "*.c" -o -name "*.cpp" -o -name "*.cc" -o -name "*.C" -o -name "*.h"`; do
  licensecheck $i
done

echo
echo "Searching for license files (COPYING / LICENSE)..."
echo

find . -name COPYING -o -name LICENSE

echo
echo "Searching for license tags in .plugin and .desktop files..."
echo

grep -i license `find . -name "*.plugin" -o -name "*.desktop"`

echo
echo "Searching for license arguments in KAboutData constructors..."
echo

grep License_ `find . -name "*.cpp" -o -name "*.cc" -o -name "*.C" -o -name "*.h"`

echo
echo "Searching for legal notices in documentation..."
echo

grep -i legalnotice `find . -name "*.docbook"`

cat <<__EOT__

All done.

Please note that these results are not authoritative.  They are merely
a useful starting point for constructing a copyright file.

Amongst other things, the following issues need to be dealt with by hand:

- Sources for which licensecheck outputs "unknown" or "no_copyright"
  need to be hand-examined;
- Scripts (such as sh/perl/python scripts) have not been checked at all;
- License information is sometimes contained in README or other text
  files, which have not been checked.

__EOT__

exit 0
