Skip to content

Instantly share code, notes, and snippets.

@jpawlowski
Last active November 18, 2023 13:17
Show Gist options
  • Save jpawlowski/cd2827d46dd0c10f58c3b299ccdf8dd0 to your computer and use it in GitHub Desktop.
Save jpawlowski/cd2827d46dd0c10f58c3b299ccdf8dd0 to your computer and use it in GitHub Desktop.
Install and configure CUPS 2.1.2 on CentOS 7 (LXC running on Proxmox VE) host including AirPrint

Basic setup, e.g. enable ssh

yum -y install epel-release
yum -y upgrade
yum -y install openssh-server net-tools iputils psmisc less which man mc bash-completion bash-completion-extras bash-argsparse bind-utils traceroute htop mtr
echo "export HISTTIMEFORMAT='%F %T  '" > /etc/profile.d/history.sh
echo "export HISTIGNORE='ls -l:pwd:date:'" >> /etc/profile.d/history.sh
echo "export HISTCONTROL=ignoredups" >> /etc/profile.d/history.sh
systemctl enable sshd
systemctl start sshd

Build and install CUPS from source

yum -y install gcc gcc-c++ make rpm-build wget tar bzip2 gnutls-devel pam-devel dbus-devel avahi-devel systemd-devel system-config-printer-libs pygobject2 python-cups python-lxml foomatic-db-ppds ghostscript-cups cups-filesystem cups-filters cups-filters-libs cups-filters-libs cups-pdf cups-bjnp
wget https://github.com/apple/cups/releases/download/release-2.1.3/cups-2.1.3-source.tar.bz2
rpmbuild -ta --without libusb1 cups-2.1.3-source.tar.bz2
yum -y install rpmbuild/RPMS/x86_64/cups-2.1.3-1.x86_64.rpm rpmbuild/RPMS/x86_64/cups-libs-2.1.3-1.x86_64.rpm rpmbuild/RPMS/x86_64/cups-devel-2.1.3-1.x86_64.rpm rpmbuild/RPMS/x86_64/cups-lpd-2.1.3-1.x86_64.rpm
rm -rf rpmbuild

Configure CUPS

/etc/xinetd.d/cups-lpd

echo "service printer" > /etc/xinetd.d/cups-lpd
echo "{" >> /etc/xinetd.d/cups-lpd
echo "        socket_type = stream" >> /etc/xinetd.d/cups-lpd
echo "        protocol = tcp" >> /etc/xinetd.d/cups-lpd
echo "        wait = no" >> /etc/xinetd.d/cups-lpd
echo "        user = lp" >> /etc/xinetd.d/cups-lpd
echo "        group = sys" >> /etc/xinetd.d/cups-lpd
echo "        passenv =" >> /etc/xinetd.d/cups-lpd
echo "        server = /usr/lib/cups/daemon/cups-lpd" >> /etc/xinetd.d/cups-lpd
echo "        server_args = -o document-format=application/octet-stream" >> /etc/xinetd.d/cups-lpd
echo "}" >> /etc/xinetd.d/cups-lpd

/etc/cups/cupsd.conf

cat /etc/cups/cupsd.conf.default | grep -v "Listen" > /etc/cups/cupsd.conf
echo "
Port 631
SSLPort 443
AutoPurgeJobs Yes
BrowseWebIF Off
DefaultPaperSize A4
DefaultShared Yes
ErrorPolicy retry-job
ServerAdmin [email protected]
ServerAlias demucvclp01prn.prd.loc.example.com cups.loc.example.com cups.example.com
ServerTokens ProductOnly
" >> /etc/cups/cupsd.conf

sed -i "s/<\/Location>/  Allow @LOCAL\n<\/Location>/g" /etc/cups/cupsd.conf
sed -i "s/<Location \/admin>/<Location \/admin>\n  Encryption Required\n  AuthType Default\n  Require user @SYSTEM/" /etc/cups/cupsd.conf
sed -i "s/<Location \/admin\/conf>/<Location \/admin\/conf>\n  Encryption Required/g" /etc/cups/cupsd.conf
sed -i "s/<Location \/admin\/log>/<Location \/admin\/log>\n  Encryption Required/g" /etc/cups/cupsd.conf
sed -i "s/^BrowseLocalProtocols.*/BrowseProtocols all/" /etc/cups/cupsd.conf
sed -i "s/^Browsing.*/Browsing On/" /etc/cups/cupsd.conf
sed -i "s/^WebInterface.*/WebInterface Yes/" /etc/cups/cupsd.conf

/etc/pam.d/cups (fix for pam_unknown.so)

echo "auth    required        pam_unix.so nodelay" > /etc/pam.d/cups
echo "account required        pam_unix.so" >> /etc/pam.d/cups
chmod 644 /etc/pam.d/cups

Install lighttpd to redirect port 80 to 443

yum -y install lighttpd
sed -i "s/^#  \"mod_redirect\",.*/  \"mod_redirect\",/g" /etc/lighttpd/modules.conf
echo "$SERVER["socket"] == ":80" {" >> /etc/lighttpd/lighttpd.conf
echo "  $HTTP["host"] =~ ".*" {" >> /etc/lighttpd/lighttpd.conf
echo "    url.redirect = (".*" => "https://%0$0")" >> /etc/lighttpd/lighttpd.conf
echo "  }" >> /etc/lighttpd/lighttpd.conf
echo "}" >> /etc/lighttpd/lighttpd.conf

AirPrint

Note: rm -rf /etc/avahi/services && /usr/local/bin/airprint-generate.py --cups -d /etc/avahi/services needs to be re-run every time after printers were installed (or significantly changed, e.g. name).

wget -O /usr/share/cups/mime/apple.convs --no-check-certificate https://raw.github.com/jpawlowski/airprint-generate/master/apple.convs
wget -O /usr/local/bin/airprint-generate.py --no-check-certificate https://raw.github.com/jpawlowski/airprint-generate/master/airprint-generate.py
wget -O /usr/local/bin/avahisearch.py --no-check-certificate https://raw.github.com/jpawlowski/airprint-generate/master/avahisearch.py
chmod 755 /usr/local/bin/airprint-generate.py /usr/local/bin/avahisearch.py
rm -rf /etc/avahi/services && /usr/local/bin/airprint-generate.py --cups -d /etc/avahi/services

Enable and start systemd services

systemctl enable org.cups.cupsd.service
systemctl start org.cups.cupsd.service
systemctl disable xinetd
systemctl stop xinetd
systemctl enable avahi-daemon
systemctl start avahi-daemon
systemctl enable lighttpd
systemctl start lighttpd

Optional for my personal setup

Install Canon UFRII Linux drivers

Download Linux_UFRII_PrinterDriver_V320_us_EN.tar.gz and put it to /usr/local/src. Extract and cd to Linux_UFRII_PrinterDriver*

yum -y install beecrypt
bash install.sh
@rhaidvogl
Copy link

Thanks for this instruction.
I've tried it out, but when i install cups there is a dependency error:

yum -y install rpmbuild/RPMS/x86_64/cups-2.1.3-1.x86_64.rpm rpmbuild/RPMS/x86_64/cups-libs-2.1.3-1.x86_64.rpm rpmbuild/RPMS/x86_64/cups-devel-2.1.3-1.x86_64.rpm rpmbuild/RPMS/x86_64/cups-lpd-2.1.3-1.x86_64.rpm
...
...
--> Finished Dependency Resolution
Error: Package: 1:cups-client-1.6.3-35.el7.x86_64 (@base)
           Requires: cups-libs(x86-64) = 1:1.6.3-35.el7
           Removing: 1:cups-libs-1.6.3-35.el7.x86_64 (@base)
               cups-libs(x86-64) = 1:1.6.3-35.el7
           Updated By: 1:cups-libs-2.1.3-1.x86_64 (/cups-libs-2.1.3-1.x86_64)
               cups-libs(x86-64) = 1:2.1.3-1
Error: Package: gtk2-2.24.31-1.el7.i686 (@base)
           Requires: libcups.so.2
           Removing: 1:cups-libs-1.6.3-35.el7.i686 (@base)
               libcups.so.2
           Updated By: 1:cups-libs-2.1.3-1.x86_64 (/cups-libs-2.1.3-1.x86_64)
               Not found

I've tried to find a solution but with no result.
I'm running CentOS 7.6.1810.
Please can you help me?

@osufnl499
Copy link

I'm coming across the same error you have:
Error: Package: 1:cups-client-1.6.3-35.el7.x86_64 (@base)
Requires: cups-libs(x86-64) = 1:1.6.3-35.el7
Removing: 1:cups-libs-1.6.3-35.el7.x86_64 (@base)
cups-libs(x86-64) = 1:1.6.3-35.el7
Updated By: 1:cups-libs-2.1.3-1.x86_64 (/cups-libs-2.1.3-1.x86_64)
cups-libs(x86-64) = 1:2.1.3-1

Ever find a fix?

@rhaidvogl
Copy link

Unfortunately not.

@VitaliyKorzhov
Copy link

Hello!
I have a different situation
Android phones see printers
Macs see printers
IPhones do not see printers
I can not understand why
have any idea?

@yk-rh
Copy link

yk-rh commented Aug 22, 2020

wget https://github.com/apple/cups/releases/download/v2.3.3/cups-2.3.3-source.tar.gz
rpmbuild -ts ./cups-2.3.3-source.tar.gz
sudo yum install mock
mock --init
mock --install libusbx-devel
mock --no-clean --rebuild ./rpmbuild/SRPMS/cups-2.3.3-0.src.rpm
sudo rpm -e --nodeps cups-ipptool cups-client paps
sudo yum -y install /var/lib/mock/epel-7-x86_64/result/{cups,cups-devel,cups-libs,cups-lpd}-2.3.3-0.x86_64.rpm

@adrianzhang
Copy link

Really good document. I followed the instructions and successfully upgraded CUPS on CentOS7, than you guy!

@ColinOppenheim
Copy link

ColinOppenheim commented Apr 27, 2021

I'm curious does this container need to be privileged or in Proxmox's terms NOT unprivileged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment