#!/usr/bin/env sh # shellcheck disable=SC3040 set -eo pipefail # Function to handle SIGTERM terminate() { echo "Received SIGTERM, shutting down CUPS..." kill -TERM "$child" 2>/dev/null wait "$child" exit 0 } # Set up SIGTERM trap trap terminate TERM if [ -n "$CUPS_ADMIN_USERNAME" ] && [ -n "$CUPS_ADMIN_PASSWORD" ]; then if ! id -u "$CUPS_ADMIN_USERNAME" >/dev/null 2>&1; then echo "Creating user $CUPS_ADMIN_USERNAME..." adduser -S -H -G lpadmin "$CUPS_ADMIN_USERNAME" echo "$CUPS_ADMIN_USERNAME:$CUPS_ADMIN_PASSWORD" | chpasswd 2>/dev/null fi fi # Start CUPS in the background and get its PID /usr/sbin/cupsd -f -c /cups/conf/cupsd.conf -s /cups/conf/cups-files.conf & child=$! # Wait for the CUPS process wait "$child"