# Maintainer: Brett Cornwall <ainola@archlinux.org>
# Contributor: Gaetan Bisson <bisson@archlinux.org>
# Contributor: Allan McRae <allan@archlinux.org>
# Committer: dorphell <dorphell@gmx.net>

pkgname=screen
pkgver=5.0.1
pkgrel=3
pkgdesc='Full-screen window manager that multiplexes a physical terminal'
url='https://www.gnu.org/software/screen/'
arch=('x86_64' 'aarch64')
license=('GPL-3.0-or-later')
depends=(
    'libcrypt.so'
    'libncursesw.so'
    'libpam.so'
    'libutempter'
)
makedepends=(
    'git'
)
source=("git+https://https.git.savannah.gnu.org/git/screen.git#tag=v.${pkgver}"
        'tmpfiles.d'
        'pam.d')
sha256sums=('ab8109790f3b0f9719cb8f8b51ffd9c7a3f0cbcca426c9abf0a8185d637e9eef'
            '1f33ce4faca7bd05dd80403411af31e682d5d23e79558e884ae5a35f1dd96223'
            '971c25929ea97422c09e10679ab98e9e6c59295aae1a4a9970909d2206e23090')
backup=('etc/screenrc' 'etc/pam.d/screen')
options=('!makeflags')

_ptygroup=5 #the UID of our PTY/TTY group

prepare() {
  cd ${pkgname}/src
  autoreconf -fiv
}

build() {
  cd ${pkgname}/src

  # PTY mode set to 0620 explicitly:
  # https://security.opensuse.org/2025/05/12/screen-security-issues.html#3c-screen-by-default-creates-world-writable-ptys-cve-2025-46803
  ./configure \
    --prefix=/usr \
    --mandir=/usr/share/man \
    --infodir=/usr/share/info \
    --enable-colors256 \
    --enable-pam \
    --enable-rxvt_osc \
    --enable-utmp \
    --enable-telnet \
    --with-pty-group=$_ptygroup \
    --with-pty-mode=0620 \
    --with-socket-dir=/run/screens \
    --with-sys-screenrc=/etc/screenrc \
  make
}

package() {
  cd ${pkgname}/src
  make DESTDIR="${pkgdir}" install
  # Remove setuid bit. Note that this will disable some functionality, such as
  # multi-user.
  chmod 755 "${pkgdir}"/usr/bin/screen-${pkgver}

  install -Dm644 ../../pam.d "${pkgdir}"/etc/pam.d/screen
  install -Dm644 ../../tmpfiles.d "${pkgdir}"/usr/lib/tmpfiles.d/screen.conf

  install -Dm644 etc/etcscreenrc "${pkgdir}"/etc/screenrc
  install -Dm644 etc/screenrc "${pkgdir}"/etc/skel/.screenrc
}
