#!/bin/sh
# Heavily based on the Slackware 13.0 SlackBuild
# http://www.mozilla.org/projects/calendar/sunbird/
# Packager Davide Locatelli (l.davide_AT_tiscali.it)

CWD=`pwd`
TMP=${TMP:-/tmp/txz}
PKG=$TMP/package-mozilla-sunbird

# This is not a source build script.  Rather, it builds a Slackware
# package from the official binary tarball available from mozilla.org.
# Using the official binaries seems like the most direct way to satify
# the Mozilla project's concerns about quality control (and thus to
# provide the most quality-certified package possible), and therefore
# be able to use the official trademarks and logos.
#
# Thanks to the folks at the Mozilla Foundation for permission to
# distribute this, and for all the great work!  :-)

NAME=mozilla-sunbird-en-us
VERSION=0.9
ARCH=${ARCH:-i686}
BUILD=3dav

if [ ! -d $TMP ]; then
  mkdir -p $TMP
fi

rm -rf $PKG
mkdir -p $PKG/usr/lib

( cd $PKG/usr/lib
  tar xzf $CWD/sunbird-$VERSION.en-US.linux-i686.tar.gz
  mv sunbird sunbird-$VERSION
  ln -sf sunbird-$VERSION sunbird
  cd sunbird-$VERSION
  zcat $CWD/sunbird.diff.gz | patch -p1 --verbose --backup --suffix=.orig
# A little hack to prevent errors on the first run. Actually the included
# extensions does nothing.
  ( cd extensions
    for i in \{*
    do
      touch "$i"/chrome.manifest
    done
  )
)

mkdir -p $PKG/usr/bin

( cd $PKG/usr/bin
  ln -sf /usr/lib/sunbird-$VERSION/sunbird .
)

mkdir -p $PKG/usr/doc/$NAME-$VERSION
mkdir -p $PKG/usr/lib/mozilla/plugins
mkdir -p $PKG/usr/share/applications
cat $CWD/mozilla-sunbird.desktop > $PKG/usr/share/applications/mozilla-sunbird.desktop
mkdir -p $PKG/usr/share/pixmaps
cat $CWD/sunbird.png > $PKG/usr/share/pixmaps/sunbird.png
mkdir $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cat $CWD/slack-desc > $PKG/usr/doc/$NAME-$VERSION/slack-desc
cat $CWD/$NAME.SlackBuild > $PKG/usr/doc/$NAME-$VERSION/$NAME.SlackBuild
cd $PKG
chown -R root:root .
makepkg -l y -c n $CWD/$NAME-$VERSION-$ARCH-$BUILD.txz

# Clean up the extra stuff:
if [ "$1" = "--cleanup" ]; then
  if [ "$TMP" != "/" ]; then
    rm -rf $TMP
  fi
fi
