# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=rsync
pkgver=3.5.0
pkgrel=0
pkgdesc="A file transfer program to keep remote files in sync"
url="https://rsync.samba.org/"
arch="all"
license="GPL-3.0-or-later"
makedepends="
	acl-dev
	attr-dev
	linux-headers
	lz4-dev
	perl
	popt-dev
	xxhash-dev
	zlib-dev
	zstd-dev
	"
checkdepends="bash python3"
subpackages="$pkgname-doc $pkgname-openrc rrsync::noarch"
source="https://download.samba.org/pub/rsync/rsync-$pkgver.tar.gz
	dont-use-nobody.patch
	test-misc-coverage-no-glibc.patch
	rsyncd.initd
	rsyncd.confd
	rsyncd.conf
	rsyncd.logrotate
	"
provider_priority=900

# secfixes:
#   3.5.0-r0:
#     - CVE-2026-53783
#     - CVE-2026-53784
#     - CVE-2026-53785
#     - CVE-2026-53786
#     - CVE-2026-53788
#     - CVE-2026-53789
#     - CVE-2026-53790
#     - CVE-2026-53791
#     - CVE-2026-53792
#     - CVE-2026-53793
#     - CVE-2026-53794
#     - CVE-2026-53795
#     - CVE-2026-53796
#     - CVE-2026-53797
#     - CVE-2026-53798
#     - CVE-2026-53799
#     - CVE-2026-53800
#     - CVE-2026-53801
#     - CVE-2026-53802
#     - CVE-2026-53803
#     - CVE-2026-70452
#     - CVE-2026-70453
#     - CVE-2026-70454
#     - CVE-2026-70455
#     - CVE-2026-70456
#     - CVE-2026-70457
#     - CVE-2026-70458
#     - CVE-2026-70459
#     - CVE-2026-70460
#     - CVE-2026-70461
#     - CVE-2026-70462
#     - CVE-2026-70463
#     - CVE-2026-70464
#   3.4.3-r0:
#     - CVE-2026-29518
#     - CVE-2026-43617
#     - CVE-2026-43618
#     - CVE-2026-43619
#     - CVE-2026-43620
#     - CVE-2026-45232
#   3.4.1-r2:
#     - CVE-2026-41035
#   3.4.1-r1:
#     - CVE-2025-10158
#   3.4.0-r0:
#     - CVE-2024-12084
#     - CVE-2024-12085
#     - CVE-2024-12086
#     - CVE-2024-12087
#     - CVE-2024-12088
#     - CVE-2024-12747
#   3.2.4-r2:
#     - CVE-2022-29154
#   3.1.2-r7:
#     - CVE-2017-16548
#     - CVE-2017-17433
#     - CVE-2017-17434
#   0:
#     - CVE-2020-14387

prepare() {
	default_prepare

	# Prevent the aports version being used
	printf '#!/bin/sh\n\necho "#define RSYNC_GITVER RSYNC_VERSION" >git-version.h\n' >mkgitver
}

build() {
	cp  rrsync.1 support/rrsync.1
	CFLAGS="$CFLAGS -flto=auto" \
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--localstatedir=/var \
		--enable-acl-support \
		--enable-xattr-support \
		--enable-xxhash \
		--with-rrsync \
		--without-included-popt \
		--without-included-zlib \
		--disable-md2man \
		--disable-openssl
		# openssl is disabled since xxh checksums are faster anyway
	make
}

check() {
	make check
}

package() {
	make DESTDIR="$pkgdir" install

	install -Dm755 "$srcdir"/rsyncd.initd "$pkgdir"/etc/init.d/rsyncd
	install -Dm644 "$srcdir"/rsyncd.conf "$pkgdir"/etc/rsyncd.conf
	install -Dm644 "$srcdir"/rsyncd.confd "$pkgdir"/etc/conf.d/rsyncd
	install -Dm644 "$srcdir"/rsyncd.logrotate "$pkgdir"/etc/logrotate.d/rsyncd
}

rrsync() {
	pkgdesc="Restricted rsync, restricts rsync to a subdir declared in .ssh/authorized_keys"
	depends="rsync python3"

	amove usr/bin/rrsync
}

sha512sums="
6c5bada017e4e5f5b451058e2d1863174a1807796525ef4188c1f40358ccbdd36604fd2275dceb1cc6a95ac04da211501553353026c48594c5a79eedb27ce68d  rsync-3.5.0.tar.gz
366e361e5d696ddcd0bb773ae4912e7b7cab81ad11123196c8b990802a14141115d1baecd28a445261d089d38964082ecdaecb6ccb43ccdabcfd7936b72d6d7e  dont-use-nobody.patch
55ca8ff6e3f404a52090bc55a9cd460de5243ab8a646e76360df3caf28b0ec882a902013c30430877e32eaf7fd98d57dc433b6c8a794ef9f65864cf56b6d592e  test-misc-coverage-no-glibc.patch
b9bf1aa02f96e4294642ead5751bd529ca1267c08e83a16342fba5736c3a8ec89568feb11fb737e974cb1bee7e00e7a8898d25844892366c6167b9ea8d1e647c  rsyncd.initd
d91337cfb57e6e3b2a8ba1e24f7d851dd927bfc327da2212b9eb0acda0e1ca2f24987f6dcc4903eccc3bf170e0f115172b3cfa5a172700495296f26302c834d7  rsyncd.confd
3db8a2b364fc89132af6143af90513deb6be3a78c8180d47c969e33cb5edde9db88aad27758a6911f93781e3c9846aeadc80fffc761c355d6a28358853156b62  rsyncd.conf
e7ff164926785c4eff2ea641c7ce2d270b25f1c26d93a6108bb6ff2c0207a28ebfd93dca39596243446ce41aceaeae62fc2b34084eb9c9086fcdbc03a657eed8  rsyncd.logrotate
"
