diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7d427f1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM ubuntu:noble + +LABEL org.opencontainers.image.source="https://github.com/vittee/drippybot" +LABEL org.opencontainers.image.description="DrippyBot" +LABEL org.opencontainers.image.author="Wittawas Nakkasem " +LABEL org.opencontainers.image.url="https://github.com/vittee/drippybot/blob/main/README.md" +LABEL org.opencontainers.image.licenses=MIT + +ENV TZ=UTC + +RUN apt update -y + +RUN apt install fzf cups printer-driver-escpr -y + +COPY entrypoint.sh / + +ENTRYPOINT ["/entrypoint.sh"] diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..645b99b --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +err() { + echo -e >&2 "$@" + exit 1 +} + +model() { + cupsd + lpinfo -m | fzf --tac --layout=reverse --with-nth 2.. --bind 'enter:become(echo {1})' +} + +print() { + if [ -z ${URI+_} ]; then + err No printer URI is specified + fi + + if [ -z ${MODEL+_} ]; then + err "No printer MODEL is specified\nTry running with \"model\" argument to select a supported model" + fi + + cupsd + + # Add the printer + lpadmin -p default -v "$URI" -m "$MODEL" + # Enable and accept print job + cupsaccept default + cupsenable default + # Set as a default printer + lpoptions -d default + # Send the print job + lp /usr/share/cups/data/testprint + # wait + sleep ${WAIT:-5} +} + +case "$1" in + model) + model + ;; + + bash) + bash + ;; + + print) + print + ;; + + *) + sleep infinity + ;; +esac