cups/overlay/usr/local/bin/entrypoint

32 lines
778 B
Plaintext
Raw Permalink Normal View History

2024-10-25 17:27:47 +00:00
#!/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..."
2024-10-25 17:27:47 +00:00
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 &
2024-10-25 17:27:47 +00:00
child=$!
# Wait for the CUPS process
wait "$child"