#!/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.
#

ALERT_LIST=$(find ../alerts -name "*.alert" -print)
MONITOR_LIST=$(find ../monitors -name "*.monitor" -print)

function extract () {

	LIST="$1"

	for alert in ${LIST} ; do

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

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

	done
}

extract "${ALERT_LIST}" > copyright.extracted
extract "${MONITOR_LIST}" >> copyright.extracted

exit 0
