#!/usr/bin/bash
# JOBoRun		: Jwm OpenBox Obarun RUNit
# Maintainer	: Joe Bo Run <joborun@disroot.org>
# PkgSource		: url="https://gittea.disroot.org/joborun-pkg/jobextra/$pkgname"
# Website		: https://pozol.eu
#-----------------------------------------| DESCRIPTION |---------------------------------------

pkgname=unzip
pkgver=6.0
_pkgver=${pkgver/./}
pkgrel=019
pkgdesc='For extracting and viewing files in .zip archives'
url='http://infozip.sourceforge.net/UnZip.html'
arch=('x86_64')
depends=('bzip2' 'bash')
#options=('debug')  ###  uncomment this to have the debug pkg produced
source=("https://downloads.sourceforge.net/infozip/${pkgname}${_pkgver}.tar.gz"
        'https://src.fedoraproject.org/rpms/unzip/raw/rawhide/f/unzip-6.0-exec-shield.patch'
        'https://src.fedoraproject.org/rpms/unzip/raw/rawhide/f/unzip-6.0-close.patch'
        'https://src.fedoraproject.org/rpms/unzip/raw/rawhide/f/unzip-6.0-attribs-overflow.patch'
        'https://src.fedoraproject.org/rpms/unzip/raw/rawhide/f/unzip-6.0-symlink.patch'
        'https://src.fedoraproject.org/rpms/unzip/raw/rawhide/f/unzip-6.0-format-secure.patch'
        'https://src.fedoraproject.org/rpms/unzip/raw/rawhide/f/unzip-6.0-valgrind.patch'
        'https://src.fedoraproject.org/rpms/unzip/raw/rawhide/f/unzip-6.0-x-option.patch'
        'https://src.fedoraproject.org/rpms/unzip/raw/rawhide/f/unzip-6.0-overflow.patch'
        'https://src.fedoraproject.org/rpms/unzip/raw/rawhide/f/unzip-6.0-cve-2014-8139.patch'
        'https://src.fedoraproject.org/rpms/unzip/raw/rawhide/f/unzip-6.0-cve-2014-8140.patch'
        'https://src.fedoraproject.org/rpms/unzip/raw/rawhide/f/unzip-6.0-cve-2014-8141.patch'
        'https://src.fedoraproject.org/rpms/unzip/raw/rawhide/f/unzip-6.0-overflow-long-fsize.patch'
        'https://src.fedoraproject.org/rpms/unzip/raw/rawhide/f/unzip-6.0-heap-overflow-infloop.patch'
        'https://src.fedoraproject.org/rpms/unzip/raw/rawhide/f/unzip-6.0-alt-iconv-utf8.patch'
        'https://src.fedoraproject.org/rpms/unzip/raw/rawhide/f/unzip-6.0-alt-iconv-utf8-print.patch'
        'https://src.fedoraproject.org/rpms/unzip/raw/rawhide/f/0001-Fix-CVE-2016-9844-rhbz-1404283.patch'
        'https://src.fedoraproject.org/rpms/unzip/raw/rawhide/f/unzip-6.0-timestamp.patch'
        'https://src.fedoraproject.org/rpms/unzip/raw/rawhide/f/unzip-6.0-cve-2018-1000035-heap-based-overflow.patch'
        'https://src.fedoraproject.org/rpms/unzip/raw/rawhide/f/unzip-6.0-cve-2018-18384.patch'
        'https://src.fedoraproject.org/rpms/unzip/raw/rawhide/f/unzip-6.0-COVSCAN-fix-unterminated-string.patch'
        'https://src.fedoraproject.org/rpms/unzip/raw/rawhide/f/unzip-zipbomb-part1.patch'
        'https://src.fedoraproject.org/rpms/unzip/raw/rawhide/f/unzip-zipbomb-part2.patch'
        'https://src.fedoraproject.org/rpms/unzip/raw/rawhide/f/unzip-zipbomb-part3.patch'
        'https://src.fedoraproject.org/rpms/unzip/raw/rawhide/f/unzip-zipbomb-manpage.patch'
        'https://src.fedoraproject.org/rpms/unzip/raw/rawhide/f/unzip-zipbomb-part4.patch'
        'https://src.fedoraproject.org/rpms/unzip/raw/rawhide/f/unzip-zipbomb-part5.patch'
        'https://src.fedoraproject.org/rpms/unzip/raw/rawhide/f/unzip-zipbomb-part6.patch'
        'https://src.fedoraproject.org/rpms/unzip/raw/rawhide/f/unzip-zipbomb-switch.patch'
        'unzip-6.0_CVE-2021-4217.patch'
        'https://sources.debian.org/data/main/u/unzip/6.0-27/debian/patches/28-cve-2022-0529-and-cve-2022-0530.patch')

prepare() {
	cd "${srcdir}/${pkgname}${_pkgver}"
	sed -i "/MANDIR =/s#)/#)/share/#" unix/Makefile
	patch -p1 -i ../unzip-6.0-exec-shield.patch
	patch -p1 -i ../unzip-6.0-close.patch
	patch -p1 -i ../unzip-6.0-attribs-overflow.patch
	patch -p1 -i ../unzip-6.0-symlink.patch # FS#60433
	patch -p1 -i ../unzip-6.0-format-secure.patch
	patch -p1 -i ../unzip-6.0-valgrind.patch
	patch -p1 -i ../unzip-6.0-x-option.patch
	patch -p1 -i ../unzip-6.0-overflow.patch # FS#44171
	patch -p1 -i ../unzip-6.0-cve-2014-8139.patch # FS#43300
	patch -p1 -i ../unzip-6.0-cve-2014-8140.patch # FS#43391
	patch -p1 -i ../unzip-6.0-cve-2014-8141.patch # FS#43300
	patch -p1 -i ../unzip-6.0-overflow-long-fsize.patch # FS#44171
	patch -p1 -i ../unzip-6.0-heap-overflow-infloop.patch # FS#46955
	patch -p1 -i ../unzip-6.0-alt-iconv-utf8.patch
	patch -p1 -i ../unzip-6.0-alt-iconv-utf8-print.patch
	patch -p1 -i ../0001-Fix-CVE-2016-9844-rhbz-1404283.patch
	patch -p1 -i ../unzip-6.0-timestamp.patch
	patch -p1 -i ../unzip-6.0-cve-2018-1000035-heap-based-overflow.patch # FS#69739
	patch -p1 -i ../unzip-6.0-cve-2018-18384.patch
	patch -p1 -i ../unzip-6.0-COVSCAN-fix-unterminated-string.patch
	patch -p1 -i ../unzip-zipbomb-part1.patch
	patch -p1 -i ../unzip-zipbomb-part2.patch
	patch -p1 -i ../unzip-zipbomb-part3.patch
	patch -p1 -i ../unzip-zipbomb-manpage.patch
	patch -p1 -i ../unzip-zipbomb-part4.patch
	patch -p1 -i ../unzip-zipbomb-part5.patch
	patch -p1 -i ../unzip-zipbomb-part6.patch
	patch -p1 -i ../unzip-zipbomb-switch.patch
	patch -p1 -i ../unzip-6.0_CVE-2021-4217.patch # FS#73542
	patch -p1 -F3 -i ../28-cve-2022-0529-and-cve-2022-0530.patch
}

build() {
	cd "${srcdir}/${pkgname}${_pkgver}"

	# DEFINES, make, and install args from Debian
	DEFINES='-DACORN_FTYPE_NFS -DWILD_STOP_AT_DIR -DLARGE_FILE_SUPPORT \
		-DUNICODE_SUPPORT -DUNICODE_WCHAR -DUTF8_MAYBE_NATIVE -DNO_LCHMOD \
		-DDATE_FORMAT=DF_YMD -DUSE_BZIP2 -DNOMEMCPY -DNO_WORKING_ISPRINT'

	make -f unix/Makefile prefix=/usr \
		D_USE_BZ2=-DUSE_BZIP2 L_BZ2=-lbz2 \
		LF2="$LDFLAGS" CF="$CFLAGS $CPPFLAGS -I. $DEFINES" \
		unzips
}

package() {
	cd "${srcdir}/${pkgname}${_pkgver}"
	make -f unix/Makefile prefix="${pkgdir}"/usr install
	install -Dm644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}


#---- license gpg-key sha256sums ----

license=('custom')

sha256sums=(036d96991646d0449ed0aa952e4fbe21b476ce994abc276e49d30e686708bd37 # unzip60.tar.gz
	2c55be12907c42a454b91f53de92470d4f5d52e9ba7b0eef79684bd58efd4a1e # unzip-6.0-exec-shield.patch
	10754a10be46ee8e7b9f84935e7f2087a99abd0a00dff77f97181c8fd71e0eef # unzip-6.0-close.patch
	74bc961e8013a4058687a3730590a709b7889203beb74a4a8369ba0301bef0e2 # unzip-6.0-attribs-overflow.patch
	fde8f9d6dbc5e9dc59f4497de8e4e313fd74318eaf5f33421acd74442fd10706 # unzip-6.0-symlink.patch
	8d9426bdd98cbba00c2d2e36c1dae17da069e6c85bf35811a434a8cbe704e6f4 # unzip-6.0-format-secure.patch
	da042334a1ae4a37ea0317ff27cee9eadd0af1529bd8391cde34467a377a4068 # unzip-6.0-valgrind.patch
	3007d6995eeec7fce12a41b4d37ef309ffe74cae86f952071e4653a1751f0190 # unzip-6.0-x-option.patch
	c9a863e570bdaf2637c43bf1bba3d97808a1b0504d85418f6a8550ac286788f2 # unzip-6.0-overflow.patch
	337131428f491b7030f96ee5b8ef3d8f5963730d1619b2754c624f4616d79adb # unzip-6.0-cve-2014-8139.patch
	64f64985270e026c01d2c19c6b66c218cf5bcfc7cf3d4a44e601fad41975ec73 # unzip-6.0-cve-2014-8140.patch
	b7a14c33db93d1e5b4fc6ce113b4b99ff7a81ed56f46c87e001f22ec085e0273 # unzip-6.0-cve-2014-8141.patch
	251d5755ffb1e9701434c545fcda0fbfc2a16372f9d807fd07606b1364a1b55b # unzip-6.0-overflow-long-fsize.patch
	b6f64d7b57e74ceaa794dd13a6937f063ec915343f3d5d88b0f81c919e7bf171 # unzip-6.0-heap-overflow-infloop.patch
	e64c9ddb38c2e7d08bdb80c597f32ee960e18fbe8cb982e444b1ece03ac95cec # unzip-6.0-alt-iconv-utf8.patch
	b990d8d8d8e02777999484a132170666ea736a865f9ad81da651dc63725475ff # unzip-6.0-alt-iconv-utf8-print.patch
	7d8e5c77ad99f9bf56d4cbf224b5635367feb44f81745dec84b44365f8f5eb16 # 0001-Fix-CVE-2016-9844-rhbz-1404283.patch
	ea04cfc8b7ca3b3c03117da0d891870b8c542d26188ef5593fd7e479f4f29f4e # unzip-6.0-timestamp.patch
	aced0f27191a67f9b8b3fdc5995938a64fd87cea64a0bbba2106e06137ef91c2 # unzip-6.0-cve-2018-1000035-heap-based-overflow.patch
	47e9deff12845e71de98cd19506a51c21d756a61bb67c0b17e77b84bdbe9fb84 # unzip-6.0-cve-2018-18384.patch
	866b8fc05731e4cf72f948c9540c3eb8b2372bf320442456b5b3ae9b74f0827c # unzip-6.0-COVSCAN-fix-unterminated-string.patch
	24582ff3dcd926d1a46caf8506f76999d2525dd66e36f50b25dca50799695f12 # unzip-zipbomb-part1.patch
	f88b9d4119a1e256f3335a2d2c142dd95d13d7c5f9e5ecd4371e547249f3557c # unzip-zipbomb-part2.patch
	ee9e26018190a515572b66a26118916843aa1002131a86b5c52769dc663b7acb # unzip-zipbomb-part3.patch
	ec4a8e5745e37f3d2d57c594c610b71753b77c5fb4bd92edfb0fb25ef968d13e # unzip-zipbomb-manpage.patch
	179330daaf395b631025d23ec666c227707caa8859a872cc39d3ea0e2a645e97 # unzip-zipbomb-part4.patch
	44599c80ea507c1fcfb8fb58b4c9d8d18f3157de453c1e0469a703322deb042a # unzip-zipbomb-part5.patch
	81ca46cfd3cf732de8cf78c57790ed7d5c73a5e8d41943b8f6313cede6004f3e # unzip-zipbomb-part6.patch
	59c0983b53801d3080684bc616d3570ccacfe471f3a8c442916b87f2f3bfa334 # unzip-zipbomb-switch.patch
	cb88ba5a2c9bdffd5867206a48841f638e2a7970e88cc009b90202bdca988b8b # unzip-6.0_CVE-2021-4217.patch
 	a27efd8c4950fb3d942d602ad7846996e02aafd77a8ad1e26700e42ae6c1cd37) # 28-cve-2022-0529-and-cve-2022-0530.patch

