#!/bin/sh
date=`date +%Y%m%d`
source version
install -d ../packages
# Make source
tar -cf ../packages/locales-${LOCALE_VERSION}-${date}-src.tar *
gzip -9 ../packages/locales-${LOCALE_VERSION}-${date}-src.tar -c \
 > ../packages/locales-${LOCALE_VERSION}-${date}-src.tar.gz
 bzip2 ../packages/locales-${LOCALE_VERSION}-${date}-src.tar
zip -9 -q -r ../packages/locales-${LOCALE_VERSION}-${date}-src.zip *
# Compile locales
for trans in `ls locale/`; do
    for string in `ls po/*.pot | sed 's/^po\///' | sed 's/.pot$//'` ; do
    if [ -f locale/${trans}/LC_MESSAGES/${string}.po ]; then
	msgfmt locale/${trans}/LC_MESSAGES/${string}.po \
	    -c -o locale/${trans}/LC_MESSAGES/${string}.mo
    fi
    done
done
# Build separate locale package
for trans in `ls locale/`; do
    if [ -f locale/${trans}/LC_MESSAGES/squirrelmail.po ]; then
	tar -cf ../packages/${trans}-${LOCALE_VERSION}-${date}.tar \
	    locale/${trans}/LC_MESSAGES/*.po \
	    locale/${trans}/LC_MESSAGES/*.mo \
	    locale/${trans}/setup.php \
	    install version ReleaseNotes.locales COPYING.locales ChangeLog.locales TRANSLATORS
	zip -9 -q ../packages/${trans}-${LOCALE_VERSION}-${date}.zip \
	    locale/${trans}/LC_MESSAGES/*.po \
	    locale/${trans}/LC_MESSAGES/*.mo \
	    locale/${trans}/setup.php \
	    install version ReleaseNotes.locales COPYING.locales ChangeLog.locales TRANSLATORS
	# sec_remove images
	if [ -f images/sec_remove_${trans}.png ]; then
	    tar -rf ../packages/${trans}-${LOCALE_VERSION}-${date}.tar \
		images/sec_remove_${trans}.png
	    zip -9 -q -g ../packages/${trans}-${LOCALE_VERSION}-${date}.zip \
		images/sec_remove_${trans}.png
	fi
	# Help
	if [ -d help/${trans} ]; then
	    tar -rf ../packages/${trans}-${LOCALE_VERSION}-${date}.tar \
		help/${trans}/*.hlp
	    zip -9 -q -g ../packages/${trans}-${LOCALE_VERSION}-${date}.zip \
		help/${trans}/*.hlp
	fi
    fi
done

# Build full locale package
tar -cf ../packages/all_locales-${LOCALE_VERSION}-${date}.tar \
    locale/*/LC_MESSAGES/*.po \
    locale/*/LC_MESSAGES/*.mo \
    locale/*/setup.php \
    images/sec_remove_*.png \
    help/*/*.hlp install version \
    ReleaseNotes.locales COPYING.locales ChangeLog.locales TRANSLATORS
zip -9 -q ../packages/all_locales-${LOCALE_VERSION}-${date}.zip \
    locale/*/LC_MESSAGES/*.po \
    locale/*/LC_MESSAGES/*.mo \
    locale/*/setup.php \
    images/sec_remove_*.png \
    help/*/*.hlp install version \
    ReleaseNotes.locales COPYING.locales ChangeLog.locales TRANSLATORS

# Pack them
for package in `ls ../packages/*-${date}.tar`; do
    gzip -9 ${package} -c > ${package}.gz
    bzip2 ${package}
done

# md5sum and sha1sum them
cd ../packages/
md5sum *-${date}.* *-${date}-* > all_locales-${LOCALE_VERSION}-${date}.md5
sha1sum *-${date}.* *-${date}-* > all_locales-${LOCALE_VERSION}-${date}.sha1

