# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgname=openssh
pkgver=8.7p1
pkgrel=1
pkgdesc='Free version of the SSH connectivity tools'
url='https://www.openssh.com/portable.html'
license=('custom:BSD')
arch=('i686' 'x86_64')
groups=('net-utils')
depends=('heimdal' 'libedit' 'libcrypt' 'openssl')
makedepends=('heimdal-devel' 'libedit-devel' 'libcrypt-devel' 'openssl-devel')
source=("https://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/${pkgname}-${pkgver}.tar.gz"{,.asc}
        openssh-7.3p1-msys2.patch
        openssh-7.3p1-msys2-setkey.patch
        openssh-7.3p1-msys2-drive-name-in-path.patch)
sha256sums=('7ca34b8bb24ae9e50f33792b7091b3841d7e1b440ff57bc9fabddf01e2ed1e24'
            'SKIP'
            'd03aabd023ddb655f3c7fe82df489e73d01c0311e8e3fa055e6c91f9cb0f35d0'
            '25079cf4a10c1ab70d60302bccaabee513762520dffd7c35285f7aae3ea36087'
            '903b3eee51e492a125cab9c724ad967450307d53e457f025e4432b81cb145af5')
validpgpkeys=('7168B983815A5EEF59A4ADFD2A3F414E736060BA') # Damien Miller <djm@mindrot.org>

backup=('etc/ssh/ssh_config' 'etc/ssh/sshd_config')

prepare() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  patch -p1 -i ${srcdir}/openssh-7.3p1-msys2.patch
  patch -p1 -i ${srcdir}/openssh-7.3p1-msys2-setkey.patch
  patch -p1 -i ${srcdir}/openssh-7.3p1-msys2-drive-name-in-path.patch
  autoreconf -fvi
}

build() {
  cd "${srcdir}/${pkgname}-${pkgver}"

  TEST_SSH_UTF8=no \
  ./configure \
    --build=${CHOST} \
    --prefix=/usr \
    --sbindir=/usr/bin \
    --libexecdir=/usr/lib/ssh \
    --sysconfdir=/etc/ssh \
    --localstatedir=/var \
    --with-libedit \
    --with-kerberos5=/usr \
    --without-hardening \
    --disable-security-key \
    --disable-strip

  make
}

check() {
  cd "${srcdir}/${pkgname}-${pkgver}"

  make tests ||
  grep $USER /etc/passwd | grep -q /bin/false
  # connect.sh fails when run with stupid login shell
}

package() {
  cd "${srcdir}/${pkgname}-${pkgver}"

  make DESTDIR="${pkgdir}" install

  #ln -sf ssh.1.gz "${pkgdir}"/usr/share/man/man1/slogin.1.gz
  install -Dm644 LICENCE "${pkgdir}/usr/share/licenses/${pkgname}/LICENCE"

  install -Dm755 contrib/findssl.sh "${pkgdir}"/usr/bin/findssl.sh
  install -Dm755 contrib/ssh-copy-id "${pkgdir}"/usr/bin/ssh-copy-id
  install -Dm644 contrib/ssh-copy-id.1 "${pkgdir}"/usr/share/man/man1/ssh-copy-id.1

  #rm -f "${pkgdir}"/etc/ssh/sshd_config
  #rm -f "${pkgdir}"/usr/bin/sshd.exe
  #rm -f "${pkgdir}"/usr/sbin/sshd.exe
  #rm -f "${pkgdir}"/usr/lib/ssh/sftp-server.exe
}
