#!/bin/bash

LANGUAGES_LIST="languages.list"
LISTS="lists"
CONTROL="debian/control"
CONTROL_IN="debian/control.in"
CONTROL_TMP=`mktemp /tmp/control.XXXXXX`

# Checking some files
[[ ! -f ${LANGUAGES_LIST} ]] && echo "Error: ${LANGUAGES_LIST} file missing, aborting." && exit 1 
[[ ! -d ${LISTS} ]] && echo "Error: ${LISTS}/ directory is missing, aborting." && exit 1
[[ ! -f ${CONTROL_IN} ]] && echo "Error: ${CONTROL_IN} file missing, aborting." && exit 1

cp ${CONTROL_IN} ${CONTROL_TMP}

# Checking whether each language in lists/ has a definition in languages.list
for lang in `ls lists`; do
	lang_entry=`grep ":.*${lang}$" ${LANGUAGES_LIST}`
	[[ -z ${lang_entry} ]] && \
		echo "Error: ${lang} missing in ${LANGUAGES_LIST}"
	lang_name=${lang_entry%%:*}

cat << __EOF >> ${CONTROL_TMP}

Package: sword-language-pack-${lang}
Architecture: all
Depends: \${sword-language-pack-${lang}:Depends}
Description: Sword modules for the ${lang_name} language
 Sword data for all supported packages for:
 ${lang_name}.
 .
 sword-language-pack-${lang} provides sword modules such as Bibles, commentaries
 and dictionaries.
 .
 It is safe to remove this package if some of the module packages are
 not desired.

__EOF


done

mv ${CONTROL_TMP} ${CONTROL}
