diff --git a/cups-dev/Dockerfile b/cups-dev/Dockerfile new file mode 100644 index 0000000..1955b75 --- /dev/null +++ b/cups-dev/Dockerfile @@ -0,0 +1,50 @@ +FROM ghcr.io/hassio-addons/debian-base:7.1.0 + +LABEL io.hass.version="1.0" io.hass.type="addon" io.hass.arch="aarch64|amd64" + +# Set shell +SHELL ["/bin/bash", "-o", "pipefail", "-c"] + +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + sudo \ + locales \ + cups \ + avahi-daemon \ + libnss-mdns \ + dbus \ + colord \ + printer-driver-all \ + printer-driver-gutenprint \ + openprinting-ppds \ + hpijs-ppds \ + hp-ppd \ + hplip \ + printer-driver-foo2zjs \ + cups-pdf \ + gnupg2 \ + lsb-release \ + nano \ + samba \ + bash-completion \ + procps \ + && apt-get clean -y \ + && rm -rf /var/lib/apt/lists/* + +COPY rootfs / + +# Add user and disable sudo password checking +RUN useradd \ + --groups=sudo,lp,lpadmin \ + --create-home \ + --home-dir=/home/print \ + --shell=/bin/bash \ + --password=$(mkpasswd print) \ + print \ +&& sed -i '/%sudo[[:space:]]/ s/ALL[[:space:]]*$/NOPASSWD:ALL/' /etc/sudoers + +EXPOSE 631 + +RUN chmod a+x /run.sh + +CMD ["/run.sh"] diff --git a/cups-dev/README.md b/cups-dev/README.md new file mode 100644 index 0000000..934734f --- /dev/null +++ b/cups-dev/README.md @@ -0,0 +1,8 @@ +# homeassistant addon cups airprint +CUPS addon with working Avahi in reflector mode + +Tested with Home Assistant version **2023.9** + +CUPS administrator login: print, password: print (can be changed in the Dockerfile) + +[![Open your Home Assistant instance and show the add add-on repository dialog with a specific repository URL pre-filled.](https://my.home-assistant.io/badges/supervisor_add_addon_repository.svg)](https://my.home-assistant.io/redirect/supervisor_add_addon_repository/?repository_url=https%3A%2F%2Fgithub.com%2Fzajac-grzegorz%2Fhomeassistant-addon-cups-airprint) diff --git a/cups-dev/build.yaml b/cups-dev/build.yaml new file mode 100644 index 0000000..7e74336 --- /dev/null +++ b/cups-dev/build.yaml @@ -0,0 +1,3 @@ +build_from: + aarch64: ghcr.io/hassio-addons/debian-base:7.1.0 + amd64: ghcr.io/hassio-addons/debian-base:7.1.0 diff --git a/cups-dev/config.yaml b/cups-dev/config.yaml new file mode 100644 index 0000000..2aac76b --- /dev/null +++ b/cups-dev/config.yaml @@ -0,0 +1,21 @@ +name: CUPS +version: "1.0" +slug: cupsik +description: A CUPS print server with working AirPrint +arch: + - amd64 + - aarch64 +usb: true +init: false +homeassistant_api: true +host_network: true +ports: + 631/tcp: 631 + 631/udp: 631 +ports_description: + 631/tcp: For other devices on the local network to print to this server + 631/udp: For other devices on the local network to print to this server +# ingress: false +map: + - config:rw + diff --git a/cups-dev/icon.png b/cups-dev/icon.png new file mode 100644 index 0000000..aefa10e Binary files /dev/null and b/cups-dev/icon.png differ diff --git a/cups-dev/logo.png b/cups-dev/logo.png new file mode 100644 index 0000000..aefa10e Binary files /dev/null and b/cups-dev/logo.png differ diff --git a/cups-dev/repository.json b/cups-dev/repository.json new file mode 100644 index 0000000..440afaf --- /dev/null +++ b/cups-dev/repository.json @@ -0,0 +1,5 @@ +{ + "name": "Home Assistant CUPS + Airprint Add-On repository", + "url": "https://github.com/zajac-grzegorz/homeassistant-addon-cups-airprint", + "maintainer": "Grzegorz Zajac" +} diff --git a/cups-dev/rootfs/etc/avahi/avahi-daemon.conf b/cups-dev/rootfs/etc/avahi/avahi-daemon.conf new file mode 100644 index 0000000..58b6729 --- /dev/null +++ b/cups-dev/rootfs/etc/avahi/avahi-daemon.conf @@ -0,0 +1,69 @@ +# This file is part of avahi. +# +# avahi is free software; you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as +# published by the Free Software Foundation; either version 2 of the +# License, or (at your option) any later version. +# +# avahi is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +# License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with avahi; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +# USA. + +# See avahi-daemon.conf(5) for more information on this configuration +# file! + +[server] +#host-name=foo +#domain-name=local +#browse-domains=0pointer.de, zeroconf.org +use-ipv4=yes +use-ipv6=yes +#allow-interfaces=eth0 +#deny-interfaces=eth1 +#check-response-ttl=no +#use-iff-running=no +#enable-dbus=yes +#disallow-other-stacks=no +#allow-point-to-point=no +#cache-entries-max=4096 +#clients-max=4096 +#objects-per-client-max=1024 +#entries-per-entry-group-max=32 +ratelimit-interval-usec=1000000 +ratelimit-burst=1000 + +[wide-area] +enable-wide-area=yes + +[publish] +#disable-publishing=no +#disable-user-service-publishing=no +#add-service-cookie=no +#publish-addresses=yes +publish-hinfo=no +publish-workstation=no +#publish-domain=yes +#publish-dns-servers=192.168.50.1, 192.168.50.2 +#publish-resolv-conf-dns-servers=yes +#publish-aaaa-on-ipv4=yes +#publish-a-on-ipv6=no + +[reflector] +enable-reflector=yes +#reflect-ipv=no +#reflect-filters=_airplay._tcp.local,_raop._tcp.local + +[rlimits] +#rlimit-as= +#rlimit-core=0 +#rlimit-data=8388608 +#rlimit-fsize=0 +#rlimit-nofile=768 +#rlimit-stack=8388608 +#rlimit-nproc=3 diff --git a/cups-dev/rootfs/etc/cups/cupsd.conf b/cups-dev/rootfs/etc/cups/cupsd.conf new file mode 100644 index 0000000..fb8d207 --- /dev/null +++ b/cups-dev/rootfs/etc/cups/cupsd.conf @@ -0,0 +1,194 @@ +# +# Configuration file for the CUPS scheduler. See "man cupsd.conf" for a +# complete description of this file. +# + +# Log general information in error_log - change "warn" to "debug" +# for troubleshooting... +LogLevel warn +PageLogFormat + +# Specifies the maximum size of the log files before they are rotated. The value "0" disables log rotation. +MaxLogSize 0 + +# Default error policy for printers +ErrorPolicy retry-job + +# Only listen for connections from the local machine. +Port 631 +Listen /run/cups/cups.sock + +# Show shared printers on the local network. +Browsing Yes +BrowseLocalProtocols all + +# Default authentication type, when authentication is required... +DefaultAuthType Basic + +# Web interface setting... +WebInterface Yes + +# Timeout after cupsd exits if idle (applied only if cupsd runs on-demand - with -l) +IdleExitTimeout 60 + +# Restrict access to the server... + + Order allow,deny + Allow @LOCAL + + +# Restrict access to the admin pages... + + Order allow,deny + Allow @LOCAL + + +# Restrict access to configuration files... + + AuthType Default + Require user @SYSTEM + Order allow,deny + + +# Restrict access to log files... + + AuthType Default + Require user @SYSTEM + Order allow,deny + + +# Set the default printer/job policies... + + # Job/subscription privacy... + JobPrivateAccess default + JobPrivateValues default + SubscriptionPrivateAccess default + SubscriptionPrivateValues default + + # Job-related operations must be done by the owner or an administrator... + + Order deny,allow + + + + Require user @OWNER @SYSTEM + Order deny,allow + + + # All administration operations require an administrator to authenticate... + + AuthType Default + Require user @SYSTEM + Order deny,allow + + + # All printer operations require a printer operator to authenticate... + + AuthType Default + Require user @SYSTEM + Order deny,allow + + + # Only the owner or an administrator can cancel or authenticate a job... + + Require user @OWNER @SYSTEM + Order deny,allow + + + + Order deny,allow + + + +# Set the authenticated printer/job policies... + + # Job/subscription privacy... + JobPrivateAccess default + JobPrivateValues default + SubscriptionPrivateAccess default + SubscriptionPrivateValues default + + # Job-related operations must be done by the owner or an administrator... + + AuthType Default + Order deny,allow + + + + AuthType Default + Require user @OWNER @SYSTEM + Order deny,allow + + + # All administration operations require an administrator to authenticate... + + AuthType Default + Require user @SYSTEM + Order deny,allow + + + # All printer operations require a printer operator to authenticate... + + AuthType Default + Require user @SYSTEM + Order deny,allow + + + # Only the owner or an administrator can cancel or authenticate a job... + + AuthType Default + Require user @OWNER @SYSTEM + Order deny,allow + + + + Order deny,allow + + + +# Set the kerberized printer/job policies... + + # Job/subscription privacy... + JobPrivateAccess default + JobPrivateValues default + SubscriptionPrivateAccess default + SubscriptionPrivateValues default + + # Job-related operations must be done by the owner or an administrator... + + AuthType Negotiate + Order deny,allow + + + + AuthType Negotiate + Require user @OWNER @SYSTEM + Order deny,allow + + + # All administration operations require an administrator to authenticate... + + AuthType Default + Require user @SYSTEM + Order deny,allow + + + # All printer operations require a printer operator to authenticate... + + AuthType Default + Require user @SYSTEM + Order deny,allow + + + # Only the owner or an administrator can cancel or authenticate a job... + + AuthType Negotiate + Require user @OWNER @SYSTEM + Order deny,allow + + + + Order deny,allow + + + diff --git a/cups-dev/rootfs/etc/s6-overlay/s6-rc.d/avahi-daemon/dependencies.d/dbus-daemon b/cups-dev/rootfs/etc/s6-overlay/s6-rc.d/avahi-daemon/dependencies.d/dbus-daemon new file mode 100644 index 0000000..e69de29 diff --git a/cups-dev/rootfs/etc/s6-overlay/s6-rc.d/avahi-daemon/run b/cups-dev/rootfs/etc/s6-overlay/s6-rc.d/avahi-daemon/run new file mode 100644 index 0000000..8594ce5 --- /dev/null +++ b/cups-dev/rootfs/etc/s6-overlay/s6-rc.d/avahi-daemon/run @@ -0,0 +1,11 @@ +#!/usr/bin/with-contenv bashio + +ulimit -n 1048576 + +bashio::log.info "Starting Avahi daemon from S6" + +until [ -e /run/dbus/system_bus_socket ]; do + sleep 1s +done + +avahi-daemon diff --git a/cups-dev/rootfs/etc/s6-overlay/s6-rc.d/avahi-daemon/type b/cups-dev/rootfs/etc/s6-overlay/s6-rc.d/avahi-daemon/type new file mode 100644 index 0000000..5883cff --- /dev/null +++ b/cups-dev/rootfs/etc/s6-overlay/s6-rc.d/avahi-daemon/type @@ -0,0 +1 @@ +longrun diff --git a/cups-dev/rootfs/etc/s6-overlay/s6-rc.d/cups-server/dependencies.d/avahi-daemon b/cups-dev/rootfs/etc/s6-overlay/s6-rc.d/cups-server/dependencies.d/avahi-daemon new file mode 100644 index 0000000..e69de29 diff --git a/cups-dev/rootfs/etc/s6-overlay/s6-rc.d/cups-server/run b/cups-dev/rootfs/etc/s6-overlay/s6-rc.d/cups-server/run new file mode 100644 index 0000000..dc2dff1 --- /dev/null +++ b/cups-dev/rootfs/etc/s6-overlay/s6-rc.d/cups-server/run @@ -0,0 +1,12 @@ +#!/usr/bin/with-contenv bashio + +ulimit -n 1048576 + +bashio::log.info "Starting CUPS server from S6" + +until [ -e /var/run/avahi-daemon/socket ]; do + sleep 1s +done + +cupsd -f + diff --git a/cups-dev/rootfs/etc/s6-overlay/s6-rc.d/cups-server/type b/cups-dev/rootfs/etc/s6-overlay/s6-rc.d/cups-server/type new file mode 100644 index 0000000..5883cff --- /dev/null +++ b/cups-dev/rootfs/etc/s6-overlay/s6-rc.d/cups-server/type @@ -0,0 +1 @@ +longrun diff --git a/cups-dev/rootfs/etc/s6-overlay/s6-rc.d/dbus-daemon/dependencies.d/initialization b/cups-dev/rootfs/etc/s6-overlay/s6-rc.d/dbus-daemon/dependencies.d/initialization new file mode 100644 index 0000000..e69de29 diff --git a/cups-dev/rootfs/etc/s6-overlay/s6-rc.d/dbus-daemon/run b/cups-dev/rootfs/etc/s6-overlay/s6-rc.d/dbus-daemon/run new file mode 100644 index 0000000..c970dc4 --- /dev/null +++ b/cups-dev/rootfs/etc/s6-overlay/s6-rc.d/dbus-daemon/run @@ -0,0 +1,7 @@ +#!/usr/bin/with-contenv bashio + +ulimit -n 1048576 + +bashio::log.info "Starting DBUS daemon from S6" + +dbus-daemon --system --nofork diff --git a/cups-dev/rootfs/etc/s6-overlay/s6-rc.d/dbus-daemon/type b/cups-dev/rootfs/etc/s6-overlay/s6-rc.d/dbus-daemon/type new file mode 100644 index 0000000..5883cff --- /dev/null +++ b/cups-dev/rootfs/etc/s6-overlay/s6-rc.d/dbus-daemon/type @@ -0,0 +1 @@ +longrun diff --git a/cups-dev/rootfs/etc/s6-overlay/s6-rc.d/initialization/dependencies.d/base b/cups-dev/rootfs/etc/s6-overlay/s6-rc.d/initialization/dependencies.d/base new file mode 100644 index 0000000..e69de29 diff --git a/cups-dev/rootfs/etc/s6-overlay/s6-rc.d/initialization/type b/cups-dev/rootfs/etc/s6-overlay/s6-rc.d/initialization/type new file mode 100644 index 0000000..bdd22a1 --- /dev/null +++ b/cups-dev/rootfs/etc/s6-overlay/s6-rc.d/initialization/type @@ -0,0 +1 @@ +oneshot diff --git a/cups-dev/rootfs/etc/s6-overlay/s6-rc.d/initialization/up b/cups-dev/rootfs/etc/s6-overlay/s6-rc.d/initialization/up new file mode 100644 index 0000000..04b5638 --- /dev/null +++ b/cups-dev/rootfs/etc/s6-overlay/s6-rc.d/initialization/up @@ -0,0 +1,4 @@ +#!/usr/bin/env bashio + +mkdir -p /var/run/dbus + diff --git a/cups-dev/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/avahi-daemon b/cups-dev/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/avahi-daemon new file mode 100644 index 0000000..e69de29 diff --git a/cups-dev/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/dbus-daemon b/cups-dev/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/dbus-daemon new file mode 100644 index 0000000..e69de29 diff --git a/cups-dev/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/initialization b/cups-dev/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/initialization new file mode 100644 index 0000000..e69de29 diff --git a/cups-dev/rootfs/run.sh b/cups-dev/rootfs/run.sh new file mode 100644 index 0000000..49e7374 --- /dev/null +++ b/cups-dev/rootfs/run.sh @@ -0,0 +1,11 @@ +#!/usr/bin/with-contenv bashio + +ulimit -n 1048576 + +until [ -e /var/run/avahi-daemon/socket ]; do + sleep 1s +done + +bashio::log.info "Starting CUPS server as CMD from S6" + +cupsd -f