#!/bin/bash

TMP=$(mktemp -d)
cd $TMP
unzip /home/e-smith/files/shares/wpkg/files/softwares/thunderbird_addons/sogo-integrator*sogo-demo.xpi 2>&1 > /dev/null

HOSTNAME=$(/sbin/e-smith/db configuration get SystemName)
DOMAINNAME=$(/sbin/e-smith/db configuration get DomainName)

cat <<HERE > ./chrome/content/extensions.rdf
<?xml version="1.0"?>
<!DOCTYPE RDF>
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:isi="http://inverse.ca/sogo-integrator/"
  xmlns:em="http://www.mozilla.org/2004/em-rdf#"
  xmlns:NC="http://home.netscape.com/NC-rdf#">
  <Seq about="http://inverse.ca/sogo-integrator/extensions"
    isi:updateURL="https://$HOSTNAME.$DOMAINNAME/plugins/updates.php?plugin=%ITEM_ID%&amp;version=%ITEM_VERSION%&amp;platform=%PLATFORM%">
    <li>
      <Description
        em:id="sogo-integrator@inverse.ca"
        em:name="SOGo Integrator"/>
    </li>
    <li>
      <Description
        em:id="sogo-connector@inverse.ca"
        em:name="SOGo Connector"/>
    </li>
  </Seq>
</RDF>
HERE

rm -f $TMP/defaults/preferences/*.js
rm -rf $TMP/custom/sogo-demo

rm -f /home/e-smith/files/shares/wpkg/files/softwares/thunderbird_addons/sogo-integrator.xpi
zip -r /home/e-smith/files/shares/wpkg/files/softwares/thunderbird_addons/sogo-integrator.xpi ./ 2>&1 > /dev/null
rm -rf $TMP/