#!/usr/bin/env bash
#
# Copyright: Dario Minnucci <midget@debian.org>
# License: GPL-2+
#
# This script tries to extract licenses from *.alert and *.monitor 
# files and updates debian/copyright.extracted file for easier 
# composition of the debian/copyright file.
#

LIST=$(find ../ -type f -name "*" -print)

function extract () {

	LIST="$1"

	for filename in ${LIST} ; do

		FILES=$(echo ${filename} | sed 's/\.\.\///g')
		COPYRIGHT=$(cat $filename | grep "Copyright\|copyright\COPYRIGHT" | sed 's/^#//g' | sed 's/Copyright//g' | sed 's/(C)//g')
		LICENSE=$(cat $filename | grep "License\|license")

		echo
		echo "Files: ${FILES}"
		echo "Copyright: ${COPYRIGHT}"
		echo "License: ${LICENSE}"
		echo
		echo "--------------------------------------------------------------------------------"

	done
}

extract "${LIST}" > copyright.extracted

exit 0

