From 3f17541d73d217a27185d279c159f81612aab5cb Mon Sep 17 00:00:00 2001
From: Kevin Mihelich <kevin@archlinuxarm.org>
Date: Sat, 28 Nov 2020 19:04:25 +0000
Subject: [PATCH] extra/cups to 2.3.3op1-1

---
 extra/cups/PKGBUILD                   | 46 +++++++++++++--------------
 extra/cups/cups-freebind.patch        | 15 +++++++++
 extra/cups/cups-systemd-service.patch | 14 --------
 3 files changed, 37 insertions(+), 38 deletions(-)
 create mode 100644 extra/cups/cups-freebind.patch
 delete mode 100644 extra/cups/cups-systemd-service.patch

diff --git a/extra/cups/PKGBUILD b/extra/cups/PKGBUILD
index 705c8d359..5a5899225 100644
--- a/extra/cups/PKGBUILD
+++ b/extra/cups/PKGBUILD
@@ -6,9 +6,10 @@
 
 pkgbase="cups"
 pkgname=('libcups' 'cups')
-_commit=63ffc5cd75e474e475bb3bcd70fb4e62bd836770 # master 2020-11-25
-pkgver=2.3.3+121+g63ffc5cd7
+#_commit=be75d5d99a54c5f62608f7b9e98748d4c7045ec1 # master 2020-11-27
+pkgver=2.3.3op1
 pkgrel=1
+epoch=1
 arch=('x86_64')
 license=('Apache' 'custom')
 #url="https://www.cups.org/"
@@ -19,7 +20,8 @@ makedepends=('libtiff' 'libpng' 'acl' 'pam' 'xdg-utils' 'krb5' 'gnutls'
              'avahi'  'hicolor-icon-theme' 'systemd' 'libxcrypt' 'inetutils' 'libpaper'
              'git')
 source=(#https://github.com/apple/cups/releases/download/v${pkgver}/cups-${pkgver}-source.tar.gz{,.sig}
-        "git+https://github.com/OpenPrinting/cups#commit=$_commit"
+        https://github.com/OpenPrinting/cups/releases/download/v${pkgver}/cups-${pkgver}-source.tar.gz{,.sig}
+        #"git+https://github.com/OpenPrinting/cups#commit=$_commit"
         cups.logrotate
         cups.pam
         cups.sysusers
@@ -27,30 +29,30 @@ source=(#https://github.com/apple/cups/releases/download/v${pkgver}/cups-${pkgve
         cups-no-export-ssllibs.patch
         cups-1.6.2-statedir.patch
         # bugfixes
-        cups-systemd-service.patch
+        cups-freebind.patch
         guid.patch)
-sha256sums=(#'261fd948bce8647b6d5cb2a1784f0c24cc52b5c4e827b71d726020bcc502f3ee'
+sha256sums=('5cf7988081d9003f589ba173b37bc2bbf81db43bb94e5e7d3e7d4c0afb0f9bc2'
             'SKIP'
             'd87fa0f0b5ec677aae34668f260333db17ce303aa1a752cba5f8e72623d9acf9'
             '57dfd072fd7ef0018c6b0a798367aac1abb5979060ff3f9df22d1048bb71c0d5'
             '06173dfaea37bdd9b39b3e09aba98c34ae7112a2f521db45a688907d8848caa2'
             'ff3eb0782af0405f5dafe89e04b1b4ea7a49afc5496860d724343bd04f375832'
             '23349c96f2f7aeb7d48e3bcd35a969f5d5ac8f55a032b0cfaa0a03d7e37ea9af'
-            '2abd918d5a5e38762ae7c2a3a443a7b9e8d9980fbe693a4b60415b18a80ebd83'
+            '3385047b9ac8a7b13aeb8f0ca55d15f793ce7283516db0155fe28a67923c592d'
             'd4537526c1e075866ae22ad263da000fc2a592d36c26b79a459a1cfdade2bb2d')
 validpgpkeys=('3737FD0D0E63B30172440D2DDBA3A7AB08D76223') # CUPS.org (CUPS.org PGP key) <security@cups.org>
 validpgpkeys+=('45D083946E3035282B3CCA9AF434104235DA97EB') # "CUPS.org <security@cups.org>"
 validpgpkeys+=('845464660B686AAB36540B6F999559A027815955') # "Michael R Sweet <michael.r.sweet@gmail.com>"
 
 
-pkgver() {
-  cd $pkgbase
-  git describe --tags | sed 's/-/+/g' | sed 's/v//'
-}
+#pkgver() {
+#  cd $pkgbase
+#  git describe --tags | sed 's/-/+/g' | sed 's/v//'
+#}
 
 prepare() {
 
-  cd "${pkgbase}" #-${pkgver}
+  cd "${pkgbase}"-${pkgver}
 
   # improve build and linking
   # Do not export SSL libs in cups-config
@@ -59,25 +61,21 @@ prepare() {
   patch -Np1 -i "${srcdir}"/cups-1.6.2-statedir.patch
 
   # bug fixes
-  # make sure network is online or cups would ne a restart to be reachable over network
+
   # https://github.com/OpenPrinting/cups/issues/53
-  patch -Np1 -i "${srcdir}"/cups-systemd-service.patch
+  # use IP_FREEBIND, because cupsd cannot bind to not yet existing IP address
+  patch -Np1 -i "${srcdir}"/cups-freebind.patch
 
   # FS#56818 - https://github.com/apple/cups/issues/5236
   patch -Np1 -i "${srcdir}"/guid.patch
 
-  # set MaxLogSize to 0 to prevent using cups internal log rotation
-#  sed -i -e '5i\ ' conf/cupsd.conf.in
-#  sed -i -e '6i# Disable cups internal logging - use logrotate instead' conf/cupsd.conf.in
-#  sed -i -e '7iMaxLogSize 0' conf/cupsd.conf.in
-
   # Rebuild configure script for not zipping man-pages.
   aclocal -I config-scripts
   autoconf -I config-scripts
 }
 
 build() {
-  cd "${pkgbase}" #-${pkgver}
+  cd "${pkgbase}"-${pkgver}
 
   # The build system uses only DSOFLAGS but not LDFLAGS to build some libraries.
   export DSOFLAGS=${LDFLAGS}
@@ -108,7 +106,7 @@ build() {
 }
 
 check() {
-  cd "${pkgbase}" #-${pkgver}
+  cd "${pkgbase}"-${pkgver}
 #  make -k check || /bin/true
 #  make check
 }
@@ -117,12 +115,12 @@ package_libcups() {
 pkgdesc="The CUPS Printing System - client libraries and headers"
 depends=('gnutls' 'libtiff>=4.0.0' 'libpng>=1.5.7' 'krb5' 'avahi' 'libusb' 'libxcrypt')
 
-  cd ${pkgbase} #-${pkgver}
+  cd ${pkgbase}-${pkgver}
   make BUILDROOT="${pkgdir}" install-headers install-libs
   # put this into the libs pkg to make other software find the libs(no pkg-config file included)
   mkdir -p "${pkgdir}"/usr/bin
-#  install -m755 "${srcdir}"/"${pkgbase}"-${pkgver}/cups-config "${pkgdir}"/usr/bin/cups-config
-  install -m755 "${srcdir}"/"${pkgbase}"/cups-config "${pkgdir}"/usr/bin/cups-config
+  install -m755 "${srcdir}"/"${pkgbase}"-${pkgver}/cups-config "${pkgdir}"/usr/bin/cups-config
+#  install -m755 "${srcdir}"/"${pkgbase}"/cups-config "${pkgdir}"/usr/bin/cups-config
 
   # add license + exception
   install -m644 -Dt "${pkgdir}/usr/share/licenses/${pkgname}" {LICENSE,NOTICE}
@@ -146,7 +144,7 @@ optdepends=('ipp-usb: allows to send HTTP requests via a USB connection on devic
             'colord: for ICC color profile support'
             'logrotate: for logfile rotation support')
 
-  cd "${pkgbase}" #-${pkgver}
+  cd "${pkgbase}"-${pkgver}
   make BUILDROOT="${pkgdir}" install-data install-exec
 
   # this one we ship in the libcups pkg
diff --git a/extra/cups/cups-freebind.patch b/extra/cups/cups-freebind.patch
new file mode 100644
index 000000000..6d9ba430b
--- /dev/null
+++ b/extra/cups/cups-freebind.patch
@@ -0,0 +1,15 @@
+diff -up cups-2.0.2/cups/http-addr.c.freebind cups-2.0.2/cups/http-addr.c
+--- cups-2.0.2/cups/http-addr.c.freebind	2015-02-10 14:46:33.000000000 +0100
++++ cups-2.0.2/cups/http-addr.c	2015-02-10 14:50:35.074759141 +0100
+@@ -186,6 +186,10 @@ httpAddrListen(http_addr_t *addr,	/* I -
+   val = 1;
+   setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, CUPS_SOCAST &val, sizeof(val));
+ 
++#ifdef __linux
++  setsockopt(fd, IPPROTO_IP, IP_FREEBIND, CUPS_SOCAST &val, sizeof(val));
++#endif /* __linux */
++
+ #ifdef IPV6_V6ONLY
+   if (addr->addr.sa_family == AF_INET6)
+     setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, CUPS_SOCAST &val, sizeof(val));
+diff -up cups-2.0.2/scheduler/listen.c.freebind cups-2.0.2/scheduler/listen.c
diff --git a/extra/cups/cups-systemd-service.patch b/extra/cups/cups-systemd-service.patch
deleted file mode 100644
index d68cad703..000000000
--- a/extra/cups/cups-systemd-service.patch
+++ /dev/null
@@ -1,14 +0,0 @@
---- cups-2.3.0/scheduler/cups.service.in	2019-08-23 17:19:38.000000000 +0200
-+++ cups-2.3.0/scheduler/cups.service.in.new	2019-08-25 20:20:25.805339727 +0200
-@@ -1,8 +1,9 @@
- [Unit]
- Description=CUPS Scheduler
- Documentation=man:cupsd(8)
--After=network.target sssd.service ypbind.service
-+After=network-online.target sssd.service ypbind.service
- Requires=cups.socket
-+Wants=network-online.target
-
- [Service]
- ExecStart=@sbindir@/cupsd -l
-