# $Id: PKGBUILD 208501 2017-01-23 11:37:51Z spupykin $
# Maintainer (Arch): Sergej Pupykin <pupykin.s+arch@gmail.com>
# Contributor (Arch): Eschwartz <eschwartz93@gmail.com>
# Maintainer: André Silva <emulatorman@parabola.nu>

pkgname=icecat-noscript
pkgver=2.9.5.3
pkgrel=1
pkgdesc="Extension for icecat which disables script"
arch=('any')
url="http://noscript.net/"
license=('GPL2')
groups=('icecat-addons')
depends=('icecat')
makedepends=('unzip')
source=(https://secure.informaction.com/download/releases/noscript-${pkgver}.xpi)
noextract=("noscript-${pkgver}.xpi")
sha512sums=('580d1e3eb6547ec4e88d6a05f9c3bffbb8dda4ca8ed04164aa9bad0088ac88073753f7806f604d08bd6acda6dbeb859f2b252a5d5bb620ac2f62c6abd053279a')
whirlpoolsums=('7fabc92fed0f94ca941c7be0742383a4c3e1d9c78e7e3a4072d4d7a7e5e9a213c7b9017a425aa5a947c994af0cd96a6b741b7b31c29ff73f43738af61a02d6b5')

prepare() {
  cd "${srcdir}"
  unzip -qqo "noscript-${pkgver}.xpi" -d "noscript-${pkgver}"
}

package() {
  cd "${srcdir}"

  _extension_id="$(sed -n '/.*<em:id>\(.*\)<\/em:id>.*/{s//\1/p;q}' noscript-${pkgver}/install.rdf)"
  _extension_dest="${pkgdir}/usr/lib/icecat/browser/extensions/${_extension_id}"
  if grep '<em:unpack>true</em:unpack>' noscript-${pkgver}/install.rdf > /dev/null; then
    install -dm755 "${_extension_dest}"
    cp -R noscript-${pkgver}/* "${_extension_dest}"
    chmod -R ugo+rX "${_extension_dest}"
  else
    install -Dm644 noscript-${pkgver}.xpi "${_extension_dest}.xpi"
  fi
}