# Contributor: Leonardo Arena <rnalrd@alpinelinux.org>
# Contributor: Natanael Copa <ncopa@alpinelinux.org>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=rt4
pkgver=4.4.2
pkgrel=0
pkgdesc="Request Tracker - issue and bug tracker"
pkgusers="rt4"
pkggroups="rt4"
url="https://bestpractical.squarespace.com/request-tracker"
arch="noarch"
license="GPL-2.0-or-later"
depends="perl
	perl-term-readkey
	perl-cache-simple-timedexpiry
	perl-class-accessor
	perl-dbi
	perl-dbd-pg
	perl-dbd-mysql
	perl-devel-globaldestruction
	perl-devel-stacktrace
	perl-digest-sha1
	perl-email-address
	perl-getopt-long
	perl-locale-maketext-fuzzy
	perl-locale-maketext-lexicon
	perl-log-dispatch
	perl-mime-tools
	perl-net-cidr
	perl-regexp-common-net-cidr
	perl-sub-exporter
	perl-text-password-pronounceable
	perl-text-template
	perl-text-wrapper
	perl-time-hires
	perl-time-modules
	perl-tree-simple
	perl-universal-require
	perl-xml-rss
	perl-text-wikiformat
	perl-convert-color
	perl-data-ical
	perl-mime-types
	perl-html-format
	perl-html-rewriteattributes>=0.05
	perl-html-tree
	perl-html-mason
	perl-javascript-minifier
	perl-cgi
	perl-cgi-psgi
	perl-cgi-emulate-psgi
	perl-html-mason-psgihandler
	perl-apache-session
	perl-starlet
	perl-html-parser
	perl-file-sharedir
	perl-module-versions-report
	perl-list-moreutils
	perl-css-squish
	perl-dbix-searchbuilder
	perl-regexp-ipv6
	perl-text-quoted
	perl-html-scrubber
	perl-html-quoted
	perl-datetime-locale
	perl-fcgi
	perl-fcgi-procmanager
	perl-datetime
	perl-json
	perl-ipc-run3
	perl-plack
	perl-dbix-searchbuilder
	perl-mailtools
	perl-crypt-eksblowfish
	perl-datetime-format-natural
	perl-data-guid
	perl-html-formattext-withlinks-andtables
	perl-role-basic
	perl-module-refresh
	perl-date-extract
	perl-html-formattext-withlinks
	perl-email-address-list
	perl-text-quoted
	perl-locale-maketext-fuzzy
	perl-date-manip
	perl-symbol-global-name
	perl-crypt-ssleay
	perl-mozilla-ca
	perl-lwp-protocol-https
	perl-crypt-ssleay
	perl-crypt-x509
	perl-file-which
	perl-string-shellquote
	perl-lwp-protocol-https
	perl-data-page-pageset
	perl-business-hours
	perl-scope-upper
	perl-html-formattext-withlinks-andtables
	perl-css-minifier-xs
	perl-net-ip
	perl-javascript-minifier-xs
	ttf-droid
	"

makedepends="autoconf"
install="$pkgname.pre-install $pkgname.pre-upgrade"
source="https://download.bestpractical.com/pub/rt/release/rt-$pkgver.tar.gz
	0001-email-allow-envelope-from-overriding-from-templates.patch
	rt-varpath.patch
	rt-autoconf-version.patch
	"
builddir="$srcdir"/rt-$pkgver

prepare() {
	default_prepare

	sed -i -e 's_$RT::BasePath/share/fonts/_/usr/share/fonts/TTF/_g' \
		"$builddir"/etc/RT_Config.pm*

	cat <<-'EOF' >> config.layout
	# Alpine directory layout.
	<Layout Alpine>
	  prefix:		/usr
	  exec_prefix:		${prefix}
	  bindir:		${exec_prefix}/bin
	  sbindir:		${exec_prefix}/sbin
	  sysconfdir:		/etc/rt4
	  mandir:		${prefix}/share/man
	  plugindir:		${prefix}/lib/rt4/plugins
	  libdir:		${prefix}/lib/rt4/
	  datadir:		${prefix}/share/rt4
	  htmldir:		${datadir}/html
	  fontdir:		${datadir}/fonts
	  lexdir:		${datadir}/po
	  staticdir:		${datadir}/static
	  manualdir:		${datadir}/doc
	  localstatedir:	/var
	  logfiledir:		${localstatedir}/log
	  masonstatedir:	${localstatedir}/cache/mason_data
	  sessionstatedir:	${localstatedir}/cache/session_data
	  customdir:		${prefix}/local
	  custometcdir:		${customdir}/etc
	  customhtmldir:	${customdir}/html
	  customlexdir:		${customdir}/po
	  customlibdir:		${customdir}/lib
	  customplugindir:	${customdir}/plugins
	</Layout>
	EOF
}

build() {
	cd "$builddir"
	autoconf
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--enable-layout=Alpine \
		--with-rt-group=rt4 \
		--with-web-group=rt4 \
		--with-web-user=rt4 \
		--disable-gpg \
		--disable-graphviz
	make testdeps
	make
}

package() {
	cd "$builddir"

	make -j1 DESTDIR="$pkgdir" install

	# delete the droid fonts as we get them from ttf-droid
	rm -rf "$pkgdir"/usr/share/rt4/fonts/ \
		"$pkgdir"/usr/local
}

sha512sums="23e318d10c49d39c1542664efa2b9f98d1dcd613c279dc8ceca0ad9aed89a5d989316e833492ed3281543ec85f6e0f5141a86f70852776bf0d54166aa126431e  rt-4.4.2.tar.gz
010bcdaab295086e69ecbf066becd718d9c33507cc9685bdb2a8c251d21bbfbc0f5b21b476d38df1b06a093678d550c1542c775dd6fc61295ea267a419a9867e  0001-email-allow-envelope-from-overriding-from-templates.patch
62308220d00e11059491533e87fb7378226609fcef332c31b2db75ba32bbbf3343cd0eb7fd53288f62700ee456669f216bd78550fb1cd7e5d4fe85ef41976c0c  rt-varpath.patch
cac79f231e1b1915962de8e4a86812fcaa0f1f64384a34557fac860c0fb0ae33d5dfd2371c30c07310391735e7348022e62bd5d453674a41ac7e77865d79dab9  rt-autoconf-version.patch"
