#!/bin/bash

# This script updates zzzfm.pot and modifies comments

curdir=`pwd`
if [ "$(basename "$curdir")" != "po" ] || [ ! -e POTFILES.in ]; then
    echo "zzzfm: update-pot: This script must be run from zzzfm's po subdirectory"
    exit 1
fi

# get configure version
ver=`grep -m 1 "^AC_INIT(\[zzzfm\], \[" "../configure.ac" \
			| sed "s/AC_INIT(\[zzzfm\], \[\(.*\)\])/\1/"`
if [ "$ver" = "" ]; then
	echo "zzzfm: update-pot: cannot get configure.ac version"
	exit 1
fi

rm -f zzzfm.pot
intltool-update --pot
if [ $? -ne 0 ] || [ ! -s zzzfm.pot ]; then
	echo "zzzfm: update-pot: error creating zzzfm.pot"
	exit 2
fi
sed -i 's/# zzzFM PO Template\./# zzzFM PO Template/' zzzfm.pot
sed -i "/# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER/d" zzzfm.pot
sed -i 's/# This file is distributed under the same license as the PACKAGE package\./# This file is distributed under the same copyright and license as the zzzFM\x0A# package./' zzzfm.pot
sed -i s/'"Project-Id-Version: PACKAGE VERSION\\n"'/"\"Project-Id-Version: zzzfm ${ver}\\\n\""/ zzzfm.pot
sed -i s/'"POT-Creation-Date: .*\\n"'/"\"POT-Creation-Date: $(date -u '+%Y-%m-%d %H:%M+0000')\\\n\""/ zzzfm.pot

head -n 20 zzzfm.pot
echo
# Check for unincluded files because this warning causes a Debian build error
intltool-update --maintain
