#Packager: George Vlahavas <vlahavas~at~gmail~dot~com>
# Adapted to thunderbird by Didier Spaier <didier~at~slint~dot~fr> 
# Make sure you delete all *.xpi files from the source directory before
# creating a package for a new thunderbird version
# TODO: put the list of locales in a separate file.
# No fa.xpi package available for download on 23/11/2016
# "http://download-installer.cdn.mozilla.net/pub/thunderbird/releases/$pkgver/linux-x86_64/xpi/fa.xpi"

pkgname=mozilla-thunderbird
pkgver=$PKGVER
#_majorver=`echo $pkgver | sed "s/\(.*\)\.\(.*\)\.\(.*\)esr/\1esr/"`
_majorver=$pkgver
pkgrel=1slint
arch=i686
source=("http://download-installer.cdn.mozilla.net/pub/thunderbird/releases/$pkgver/linux-$arch/en-US/thunderbird-$pkgver.tar.bz2"
	"http://download-installer.cdn.mozilla.net/pub/thunderbird/releases/$pkgver/linux-i686/xpi/ar.xpi"
	"http://download-installer.cdn.mozilla.net/pub/thunderbird/releases/$pkgver/linux-i686/xpi/bg.xpi"
	"http://download-installer.cdn.mozilla.net/pub/thunderbird/releases/$pkgver/linux-i686/xpi/cs.xpi"
	"http://download-installer.cdn.mozilla.net/pub/thunderbird/releases/$pkgver/linux-i686/xpi/da.xpi"
	"http://download-installer.cdn.mozilla.net/pub/thunderbird/releases/$pkgver/linux-i686/xpi/de.xpi"
	"http://download-installer.cdn.mozilla.net/pub/thunderbird/releases/$pkgver/linux-i686/xpi/en-US.xpi"
	"http://download-installer.cdn.mozilla.net/pub/thunderbird/releases/$pkgver/linux-i686/xpi/en-GB.xpi"
	"http://download-installer.cdn.mozilla.net/pub/thunderbird/releases/$pkgver/linux-i686/xpi/el.xpi"
	"http://download-installer.cdn.mozilla.net/pub/thunderbird/releases/$pkgver/linux-i686/xpi/es-AR.xpi"
	"http://download-installer.cdn.mozilla.net/pub/thunderbird/releases/$pkgver/linux-i686/xpi/es-ES.xpi"
	"http://download-installer.cdn.mozilla.net/pub/thunderbird/releases/$pkgver/linux-i686/xpi/et.xpi"
	"http://download-installer.cdn.mozilla.net/pub/thunderbird/releases/$pkgver/linux-i686/xpi/fi.xpi"
	"http://download-installer.cdn.mozilla.net/pub/thunderbird/releases/$pkgver/linux-i686/xpi/fr.xpi"
	"http://download-installer.cdn.mozilla.net/pub/thunderbird/releases/$pkgver/linux-i686/xpi/hr.xpi"
	"http://download-installer.cdn.mozilla.net/pub/thunderbird/releases/$pkgver/linux-i686/xpi/hu.xpi"
	"http://download-installer.cdn.mozilla.net/pub/thunderbird/releases/$pkgver/linux-i686/xpi/id.xpi"
	"http://download-installer.cdn.mozilla.net/pub/thunderbird/releases/$pkgver/linux-i686/xpi/it.xpi"
	"http://download-installer.cdn.mozilla.net/pub/thunderbird/releases/$pkgver/linux-i686/xpi/ja.xpi"
	"http://download-installer.cdn.mozilla.net/pub/thunderbird/releases/$pkgver/linux-i686/xpi/ko.xpi"
	"http://download-installer.cdn.mozilla.net/pub/thunderbird/releases/$pkgver/linux-i686/xpi/lt.xpi"
	"http://download-installer.cdn.mozilla.net/pub/thunderbird/releases/$pkgver/linux-i686/xpi/nb-NO.xpi"
	"http://download-installer.cdn.mozilla.net/pub/thunderbird/releases/$pkgver/linux-i686/xpi/nn-NO.xpi"
	"http://download-installer.cdn.mozilla.net/pub/thunderbird/releases/$pkgver/linux-i686/xpi/nl.xpi"
	"http://download-installer.cdn.mozilla.net/pub/thunderbird/releases/$pkgver/linux-i686/xpi/pl.xpi"
	"http://download-installer.cdn.mozilla.net/pub/thunderbird/releases/$pkgver/linux-i686/xpi/pt-BR.xpi"
	"http://download-installer.cdn.mozilla.net/pub/thunderbird/releases/$pkgver/linux-i686/xpi/pt-PT.xpi"
	"http://download-installer.cdn.mozilla.net/pub/thunderbird/releases/$pkgver/linux-i686/xpi/ro.xpi"
	"http://download-installer.cdn.mozilla.net/pub/thunderbird/releases/$pkgver/linux-i686/xpi/ru.xpi"
	"http://download-installer.cdn.mozilla.net/pub/thunderbird/releases/$pkgver/linux-i686/xpi/sk.xpi"
	"http://download-installer.cdn.mozilla.net/pub/thunderbird/releases/$pkgver/linux-i686/xpi/sl.xpi"
	"http://download-installer.cdn.mozilla.net/pub/thunderbird/releases/$pkgver/linux-i686/xpi/sr.xpi"
	"http://download-installer.cdn.mozilla.net/pub/thunderbird/releases/$pkgver/linux-i686/xpi/sv-SE.xpi"
	"http://download-installer.cdn.mozilla.net/pub/thunderbird/releases/$pkgver/linux-i686/xpi/tr.xpi"
	"http://download-installer.cdn.mozilla.net/pub/thunderbird/releases/$pkgver/linux-i686/xpi/uk.xpi"
	"http://download-installer.cdn.mozilla.net/pub/thunderbird/releases/$pkgver/linux-i686/xpi/vi.xpi"
	"http://download-installer.cdn.mozilla.net/pub/thunderbird/releases/$pkgver/linux-i686/xpi/zh-CN.xpi"
	"http://download-installer.cdn.mozilla.net/pub/thunderbird/releases/$pkgver/linux-i686/xpi/zh-TW.xpi"
	"mozilla-thunderbird.desktop"
	"langpacks.js")
docs=("readme.txt" "install" "copying" "changelog" "authors" "news" "todo")
options=('noextract')

doinst() {
# update the mime desktop database
if [ -x /usr/bin/update-desktop-database ]; then
	/usr/bin/update-desktop-database -q
fi
# update the mime database
if [ -x /usr/bin/update-mime-database ]; then
	/usr/bin/update-mime-database usr/share/mime > /dev/null 2>&1
fi
}

slackdesc=\
(
#|-----handy-ruler------------------------------------------------------|
"mozilla-thunderbird (Mozilla Thunderbird mail application)"
""
"Mozilla Thunderbird is a redesign of the Mozilla mail component"
"written using the XUL user interface language.  Thunderbird makes"
"emailing safer, faster, and easier than ever before with the"
"industry's best implementations of features such as intelligent spam"
"filters, built-in RSS reader, quick search, and much more."
""
"Visit the Mozilla Thunderbird project online:"
"  http://www.mozilla.org/projects/thunderbird/"
)


build() {
	# extract the thunderbird tarball
	cd $startdir/src
	tar xf thunderbird-$pkgver.tar.bz2
	cd $startdir/src/thunderbird
	mkdir -p $startdir/pkg/usr/lib${LIBDIRSUFFIX}/thunderbird-$_majorver
	cp -R ./* $startdir/pkg/usr/lib${LIBDIRSUFFIX}/thunderbird-$_majorver/
	mkdir -p $startdir/pkg/usr/bin
	mkdir -p $startdir/pkg/usr/share/applications
	# fix mozilla-thunderbird.desktop
	sed "/Encoding/d;s:/usr/share/pixmaps/thunderbird.png:thunderbird:" $startdir/src/mozilla-thunderbird.desktop > $startdir/src/thunderbird.desktop
	mv $startdir/src/thunderbird.desktop $startdir/pkg/usr/share/applications/mozilla-thunderbird.desktop
	mkdir -p $startdir/pkg/usr/share/icons/hicolor/{16x16,22x22,24x24,32x32,48x48,256x256}/apps
	cp $startdir/src/thunderbird/chrome/icons/default/default16.png $startdir/pkg/usr/share/icons/hicolor/16x16/apps/thunderbird.png
	cp $startdir/src/thunderbird/chrome/icons/default/default22.png $startdir/pkg/usr/share/icons/hicolor/22x22/apps/thunderbird.png
	cp $startdir/src/thunderbird/chrome/icons/default/default24.png $startdir/pkg/usr/share/icons/hicolor/24x24/apps/thunderbird.png
	cp $startdir/src/thunderbird/chrome/icons/default/default32.png $startdir/pkg/usr/share/icons/hicolor/32x32/apps/thunderbird.png
	cp $startdir/src/thunderbird/chrome/icons/default/default48.png $startdir/pkg/usr/share/icons/hicolor/48x48/apps/thunderbird.png
	cp $startdir/src/thunderbird/chrome/icons/default/default256.png $startdir/pkg/usr/share/icons/hicolor/256x256/apps/thunderbird.png
	cp $startdir/src/langpacks.js $startdir/pkg/usr/lib${LIBDIRSUFFIX}/thunderbird-$_majorver/defaults/pref/

	# locales
	for locale in `basename -a -s ".xpi" $startdir/src/*.xpi`; do
		mkdir -p $startdir/pkg/usr/lib${LIBDIRSUFFIX}/thunderbird-$_majorver/extensions/langpack-${locale}\@thunderbird.mozilla.org
		unzip -q $startdir/src/${locale}.xpi -d $startdir/pkg/usr/lib${LIBDIRSUFFIX}/thunderbird-$_majorver/extensions/langpack-${locale}\@thunderbird.mozilla.org/
	done
	(
	cd $startdir/pkg/usr/bin
	ln -sf /usr/lib${LIBDIRSUFFIX}/thunderbird-$_majorver/thunderbird thunderbird
	)

	mkdir -p $startdir/pkg/usr/lib${LIBDIRSUFFIX}/mozilla/plugins
	(
	cd $startdir/pkg/usr/lib${LIBDIRSUFFIX}/thunderbird-$_majorver
	ln -s ../mozilla/plugins plugins
	)

	# hopefully, disable updates
	rm $startdir/pkg/usr/lib${LIBDIRSUFFIX}/thunderbird-$_majorver/update-settings.ini
	rm $startdir/pkg/usr/lib${LIBDIRSUFFIX}/thunderbird-$_majorver/updater.ini
	rm $startdir/pkg/usr/lib${LIBDIRSUFFIX}/thunderbird-$_majorver/updater
	for locale in `basename -a -s ".xpi" $startdir/src/*.xpi`; do
		rm $startdir/pkg/usr/lib${LIBDIRSUFFIX}/thunderbird-$_majorver/extensions/langpack-${locale}\@thunderbird.mozilla.org/chrome/${locale}/locale/${locale}/mozapps/extensions/update.*
		rm -rf $startdir/pkg/usr/lib${LIBDIRSUFFIX}/thunderbird-$_majorver/extensions/langpack-${locale}@thunderbird.mozilla.org/chrome/${locale}/locale/${locale}/mozapps/update
	done
}
