# Maintainer (Arch): Xavier Devlamynck <magicrhesus@ouranos.be>
# Contributors (Arch): Keshav P R, atommix aka Aleks Lifey, Xavion, Ananda Samaddar, Dan Serban, Xyne
# Contributor: Andreas Grapentin <andreas@grapentin.org>
# Contributor: André Silva <emulatorman@hyperbola.info>
# Contributor: Márcio Silva <coadde@hyperbola.info>

# parabola changes and rationale:
#  - removing support for possibly unsafe protocols
#  - fix usage of "open source" and "linux" terms

pkgname=jitsi
pkgver=2.10.5550
pkgrel=7
pkgrel+=.nonprism1
pkgdesc="An audio/video SIP VoIP phone and instant messenger written in Java (formerly SIP-Communicator), without support for unsafe and dangerous for privacy protocols"
arch=('any')
url="http://jitsi.org"
license=('Apache')
depends=('java-runtime=8')
makedepends=('ant' 'java-environment=8')
options=(!strip !emptydirs zipman !libtool docs)
source=("https://download.jitsi.org/jitsi/src/jitsi-src-${pkgver}.zip"
		jitsi.desktop
		jitsi.sh
		nonprism.patch)
sha256sums=('cdfc6f038d1b877c42d26dba1864ac7c6b554dd55c18767a29f2db3618647287'
            '61e3bec3470790fa067f87d978016ec4452a6fd3dfba2c9afa5245b58d3cb19d'
            'b22ae316fece079ce7f56060f79722d74867562ec12b9a5279d144eb359587c9'
            '437c550c93688efb7f5bec5564093193a663257f9f455fcd5551106db23b2ed3')

prepare() {
  cd $srcdir/$pkgname

  # remove Open Source term
  sed -i 's|Open Source / ||;
          s|open source / ||;
          s|Open Source|Free Software|;
          s|open source|free software|;
         ' $(grep -ril 'open source')
  sed -i 's|OpenSource / ||;
          s|opensource / ||;
          s|OpenSource|FreeSoftware|;
          s|opensource|freesoftware|;
         ' $(grep -ril opensource)

  # remove Linux term
  sed -i '/, Linux/ s|Linux|GNU/Linux|;
          /And Linux/ s|Linux|GNU/Linux|;
          /and Linux/ s|Linux|GNU/Linux|;
          /For Linux/ s|Linux|GNU/Linux|;
          /for Linux/ s|Linux|GNU/Linux|;
          /Linux,/ s|Linux|GNU/Linux|;
          /Linux and/ s|Linux|GNU/Linux|;
          /Linux distribution/ s|Linux|GNU/Linux|;
          /Linux machine/ s|Linux|GNU/Linux|;
          /Linux operating/ s|Linux|GNU/Linux|;
          /Linux OS/ s|Linux|GNU/Linux|;
          /Linux specific/ s|Linux|GNU/Linux|;
          /Linux system/ s|Linux|GNU/Linux|;
          /Under Linux/ s|Linux|GNU/Linux|;
          /under Linux/ s|Linux|GNU/Linux|;
          /On Linux/ s|Linux|GNU/Linux|;
          /on Linux/ s|Linux|GNU/Linux|;
          s|GNU/GNU|GNU|;
          s|GNU/Linux kernel|Linux kernel|;
          s|GNU/Linux specific kernel|Linux specific kernel|;
         ' $(grep -rl Linux)

  # remove support for unsafe and dangerous for privacy protocols (AIM, Facebook, Google Talk, ICQ, MSN and Yahoo!)
  patch -Np1 -i $srcdir/nonprism.patch
}

build() {
  cd "${srcdir}/${pkgname}"
  # append the build revision to the jitsi version
  sed -i "s/0\.build\.by\.SVN/build.${pkgver}/" src/net/java/sip/communicator/impl/version/NightlyBuildID.java
  ant rebuild
}

package() {
  cd "${srcdir}/${pkgname}"
  find lib/ lib/bundle/ -maxdepth 1 -type f -exec install -Dm644 {} "${pkgdir}/usr/lib/${pkgname}/"{} \;
#  find lib/os-specific/linux/ -maxdepth 1 -type f -execdir install -Dm644 {} "${pkgdir}/usr/lib/${pkgname}/lib/"{} \;
  shopt -sq extglob
  find lib/native/linux$(sed 's/_/-/g' <<<${CARCH/#*(i?86|x86)/})/ -maxdepth 1 -type f -execdir install -Dm644 {} "${pkgdir}/usr/lib/${pkgname}/lib/native/"{} \;
  find sc-bundles/{,os-specific/linux/} -maxdepth 1 -type f -execdir install -Dm644 {} "${pkgdir}/usr/lib/${pkgname}/sc-bundles/"{} \;
  install -Dm755 "${srcdir}/${pkgname}.sh" "${pkgdir}/usr/bin/${pkgname}"
  install -Dm644 "${srcdir}/${pkgname}.desktop" "${pkgdir}/usr/share/applications/${pkgname}.desktop"

  cd "resources/install/debian/"
  for _file in *.{svg,xpm}; do
    install -Dm644 "$_file" "${pkgdir}/usr/share/pixmaps/${_file}"
  done
}
