# Maintainer (arch): Guillaume ALAUX <guillaume@archlinux.org> 
# Contributor: Eric Belanger <eric@archlinux.org>
# Contributor: Sarah Hay <sarahhay@mb.sympatico.ca>
# Maintainer: Omar Vega Ramos <ovruni@gnu.org.pe>
# Contributor: bill-auger <bill-auger@programmer.net>


# parabola changes and rationale:
# - change web URL to new active fork
# - add custom animation feature (offered to upstream)


pkgname=cowsay
pkgver=3.04
pkgrel=2
pkgrel+=.parabola2
pkgdesc='Configurable talking cow (and a few other creatures)'
arch=('any')
url=https://web.archive.org/web/20120527202447/http://www.nog.net/~tony/warez/cowsay.shtml
license=('PerlArtistic' 'GPL')
depends=('perl')
depends+=('perl-term-readkey') # custom animation feature
mksource=(https://github.com/tnalpgge/rank-amateur-cowsay/archive/cowsay-$pkgver.tar.gz
          cowsay.patch)
mksource+=(0001-implement-animated-cows.patch
           0002-add-example-animated-cow.patch
           0003-implement-animation-stepping.patch
           0004-document-animated-cows-and-the-a-option.patch
           0005-clarify-licensing.patch)
source=(https://repo.parabola.nu/other/${pkgname}/${pkgname}-${pkgver}-libre.tar.gz{,.sig})
mksha512sums=('99d21ef9a7c7c76056cb7acb2c771fbdabfedde4f6edb5d3035337c59f9e88944690d1b43282c32827ad79339199716366c8be73b0dea09063ec2d52220c1b51'
              '4c70074fc88e741f2eb4daa04a55ef3ff0638bffda907fe451299aeb2271a3b09c4b73df4d3eb83f6ac91b9cb05530bb2a59df81c72602728441254624a05327')
mksha512sums+=('01952859e23aaade5f955075d7fd8a2eb8d7a03ff8aeaaa7ddbe8f91bb6abc9d3f2dce9ddebd626d9d18246f9d05eb964335b39b07f798adc206b8432338aca6'
               '1a17ca5d6e79440a4a24c8075e16b2bfc0e8056b48773d029e5ca527d03d5996e19806f0ac135595280588eacdd7f6877db6ae2f899d2fe08b0a524a756f9b09'
               'a1220623cfb9ac47fd7b1ac667a7a872b57d37a32c38f883b4803370786543de20ff1f37621a17b7ac94a844e5b1429ef66aba148ba54f5750052e7cce7af2e1'
               '9164bd67de66227798870b29b4fe05e6d99bcdf94144fec5fbd89e580251771cd13673a7bab2a56aa20ab15dbe5b87783a470347d5da33e6ded6391c7f7b093c'
               '2013d166d3303ce152615dd1273b1a1475db43ad4d545c4816e430a885a997ae95f03414ac4c048a4b213f9a50ed9df5274ee999a8bb9cd264e81572e3f79d18')
sha512sums=('1481615a923eca349f45d34bb101b964540c6b507097ad14a3d48e065455c715d12cd2d1dae6af8e6021d1e1e5716fce019ff5d283bba8934e999c39c337e396'
            SKIP)
validpgpkeys=('3954A7AB837D0EA9CFA9798925DB7D9B5A8D4B40') # bill-auger


mksource() {
  cd ${srcdir}/rank-amateur-cowsay-${pkgname}-${pkgver}

  patch -p1 -i "${srcdir}"/0001-implement-animated-cows.patch
  patch -p1 -i "${srcdir}"/0002-add-example-animated-cow.patch
  patch -p1 -i "${srcdir}"/0003-implement-animation-stepping.patch
  patch -p1 -i "${srcdir}"/0004-document-animated-cows-and-the-a-option.patch
  patch -p1 -i "${srcdir}"/0005-clarify-licensing.patch

  # remove useless files
  rm cows/*.pm

  # remove offensive[sic] and vaguely copyright-infringing cows
  rm cows/beavis.zen.cow
  rm cows/bong.cow
  mv cows/{bud-,}frogs.cow ; sed -i '/^#/d' cows/frogs.cow ;
  rm cows/ghostbusters.cow
  rm cows/head-in.cow
  rm cows/hellokitty.cow
  rm cows/luke-koala.cow
  rm cows/mutilated.cow
  rm cows/ren.cow
  rm cows/satanic.cow
  rm cows/sodomized.cow
  rm cows/stimpy.cow
  rm cows/surgery.cow
  rm cows/telebears.cow
  rm cows/vader.cow
  rm cows/vader-koala.cow

  # for some reason, arch patches this in build()
  cp "$srcdir"/cowsay.patch .
}

prepare() {
  # for some reason, arch patches this in build()
  cp rank-amateur-cowsay-${pkgname}-${pkgver}/cowsay.patch "${srcdir}"/
}

build() {
	cd rank-amateur-cowsay-${pkgname}-${pkgver}
	patch -p1 -i "$srcdir"/cowsay.patch
	sed -i 's|/man/|/share/man/|' install.sh
}

package() {
	cd rank-amateur-cowsay-${pkgname}-${pkgver}
	echo "${pkgdir}/usr" | ./install.sh
	# This one is not a valid '.cow' file
	rm "${pkgdir}"/usr/share/cows/mech-and-cow
}
