Skip to content

Commit

Permalink
Update printer.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
spiceywasabi authored Nov 21, 2023
1 parent 9e2948b commit afb4f03
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions printer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/discord.sh"
FIXPRINT="1"


# some day we can try: https://github.com/istopwg/ippsample/


dolog() {
echo "* discord.sh $1"
logger "$1"
Expand Down Expand Up @@ -38,10 +36,7 @@ if [ -z "${PRINTER_CONF_PATH}" ]; then
fi

dolog "found printer configuration at ${PRINTER_CONF_PATH}"

# this won't work because docker is read only...
#sed -i "s/ //g" "${PRINTER_CONF_PATH}"


source "${PRINTER_CONF_PATH}"

if [ -z "${WEBHOOK}" -o -z "${TEAM_NUM}" ]; then
Expand All @@ -54,6 +49,10 @@ dolog "found WEBHOOK envvar"

dolog "has identified team as: ${TEAM_NUM}"


echo "${WEBHOOK}" > "${DISCORDPATH}/.webhook"


if [ -z "$1" ]; then
dolog "error no arguments supplied, must be called by cups pdf or ippeveprinter"
exit 1
Expand All @@ -66,21 +65,34 @@ else
PDFNAME="$1"
logger "printer.sh is starting print job at $DST"
sender="$3"

if [ ! -e "$1" ]; then
dolog "error file $1 does not exist"
else
dolog "valid file found, attempting to send"
fi

FILESIZE=$(($(stat -c '%s' $PDFNAME)/1024))

dolog "file size identified to be ${FILESIZE}"

if [ -z "$3" ]; then
sender="unknown"
fi
teaminf="(Team ${TEAM_NUM})"


teaminf=""
if [ ! -z "${TEAM_NUM}" ]; then
teaminf="(Team ${TEAM_NUM})"
fi

if [ $((RANDOM%50)) -eq 0 ]; then
if [ $((RANDOM%50)) -eq 0 ] || [ $FILESIZE -gt 8100 ]; then
message="**Discord Printer** is *jammed*! Try printing again... https://i.imgur.com/VYwZURV.gif"
else
message="**Discord Printer** recieved a new document and has made it available for you to download. (Sender: ${sender}) ${teaminf}"
fi

$DISCORDCMD \
--file "${PDFNAME}" \
--webhook-url="$WEBHOOK" \
--username "CCDCPrinter" \
--text "${message}" \
--avatar "https://i.imgur.com/0R30ZZ5.png" \
Expand All @@ -91,4 +103,3 @@ else
fi
fi
exit 0

0 comments on commit afb4f03

Please sign in to comment.