# $Id: PKGBUILD 372764 2018-08-19 09:50:45Z seblu $
# Maintainer: Sébastien Luttringer
# Contributor: Paul Mattal <paul@archlinux.org>

pkgname=mailman
pkgver=2.1.29
pkgrel=1
pkgdesc='The GNU Mailing List Manager'
arch=(x86_64)
license=('GPL')
url='http://www.list.org/'
# we need to have the mailman user to build mailman
makedepends=('mailman')
depends=('glibc' 'python2' 'smtp-server' 'python2-dnspython' 'systemd')
# 'Defaults.py' should not be changed by users; 'mm_cfg.py' should instead.
backup=('usr/lib/mailman/Mailman/mm_cfg.py')
install=$pkgname.install
source=("https://launchpad.net/mailman/2.1/$pkgver/+download/mailman-$pkgver.tgz"{,.asc}
        'mailman.profile.sh'
        'mailman.profile.csh'
        'mailman.sysusers'
        'mailman.service'
        'mailman-checkdbs.service'
        'mailman-checkdbs.timer'
        'mailman-cullbadshunt.service'
        'mailman-cullbadshunt.timer'
        'mailman-disabled.service'
        'mailman-disabled.timer'
        'mailman-gatenews.service'
        'mailman-gatenews.timer'
        'mailman-mailpasswds.service'
        'mailman-mailpasswds.timer'
        'mailman-nightlygzip.service'
        'mailman-nightlygzip.timer'
        'mailman-senddigests.service'
        'mailman-senddigests.timer'
        '01-mailman-2.1-build.patch'
        )
validpgpkeys=('C638CAEF0AC21563736B5A22555B975E953B8693') # Mark Sapiro <mark@msapiro.net>
md5sums=('463ce7efb4e6f214f28ef17dbe0b7b79'
         'SKIP'
         'a9c71ec940c56173415fbd49087d10b0'
         '85a8c30ffc444e677b286f54df530482'
         '5ced9364c38ee40046007ee9587b1228'
         'f3ea6ef02ab135274406ce52ea8bbb7b'
         '13b248799ec93250dca5458af842dffd'
         'd38ca2687bc1c7ca29e4d1af441b5f17'
         'd71b28a3d494b440fb1578364fd80236'
         '58718e2d6b68d8df1d9ff2bd5770ff58'
         'a705ef30ef02c281b34b41e88de767ae'
         '0ee3a7e6d2d3aff76a235d1afad2ac95'
         'df24d28d015cef1fc5b1ea10b43eb92a'
         '61670d3c175556ff4c8a5d8f3078dc1e'
         'ed8858c034aef43a36b5c99f0faabf36'
         '43cb4ab9cc2c4d840a398ec4ae0a53b2'
         '998d3d57353a0cc6d4c742a9607c2108'
         '3af65082d3cd4d5746944890c7a72962'
         '350dac1e350691e3d9cb8f99fd4b669a'
         '52917f62441ac5d950789e8f8af28f09'
         'ed04d062379eb21e39ce1e70e6b1ade2')

prepare() {
  cd $pkgname-$pkgver

  # apply patch from the source array (should be a pacman feature)
  local filename
  for filename in "${source[@]}"; do
    if [[ "$filename" =~ \.patch$ ]]; then
      msg2 "Applying patch ${filename##*/}"
      patch -p1 -N -i "$srcdir/${filename##*/}"
    fi
  done

  # some files in mailman doesn't use configure parameter
  msg2 'Fix python2 sheebang'
  find . -type f -exec \
    sed -i '1s,^#! \?/usr/bin/\(env \|\)python$,#!/usr/bin/python2,' {} \;
}

build() {
  cd $pkgname-$pkgver
  ./configure \
    --without-permcheck \
    --prefix=/usr/lib/mailman \
    --with-var-prefix=/var/lib/mailman \
    --with-mail-gid=mailman \
    --with-username=mailman \
    --with-groupname=mailman \
    --with-cgi-gid=http \
    --with-python=/usr/bin/python2 \
    --with-mailhost=localhost \
    --with-urlhost=localhost
  make
}

package() {
  cd $pkgname-$pkgver
  make DESTDIR="$pkgdir" install

  # let's follow Fedora FHS way; Gentoo does it the other way round

  # Create a link so that the config file mm_cfg.py appears in config
  # directory /etc/mailman. We don't put mm_cfg.py in the config directory
  # because its executable code (python file) and the security policy wants
  # to keep executable code out of /etc and inside of a lib directory instead,
  # and because traditionally mm_cfg.py was in the Mailman subdirectory and
  # experienced mailman admins will expect to find it there. But having it
  # "appear" in the config directory is good practice and heading in the
  # right direction for FHS compliance.
  install -d -m755 "$pkgdir/etc/$pkgname"
  ln -sv /usr/lib/mailman/Mailman/mm_cfg.py "$pkgdir/etc/$pkgname/mm_cfg.py"
  # fix some permissions to satisfy check_perms
  chown -R mailman:mailman "$pkgdir"/{usr/lib/mailman,var/lib/mailman,etc/mailman/*}
  chown http:mailman "$pkgdir"/var/lib/mailman/archives/private
  chmod 2770 "$pkgdir"/var/lib/mailman/archives/private
  chmod 2755 "$pkgdir"/usr/lib/mailman/cgi-bin/*
  chmod 2755 "$pkgdir"/usr/lib/mailman/mail/mailman
  cd "$srcdir"
  # profiles
  install -Dm 755 $pkgname.profile.sh "$pkgdir/etc/profile.d/$pkgname.sh"
  install -Dm 755 $pkgname.profile.csh "$pkgdir/etc/profile.d/$pkgname.csh"
  # systemd timers and services
  install -t "${pkgdir}/usr/lib/systemd/system/" \
    -vDm644 ${pkgname}*.{service,timer}
  # sysusers.d
  install -vDm 644 $pkgname.sysusers \
    "$pkgdir/usr/lib/sysusers.d/$pkgname.conf"
}

# vim:set ts=2 sw=2 et:
