diff --git a/printer.sh b/printer.sh index 4266812..9a877aa 100755 --- a/printer.sh +++ b/printer.sh @@ -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" @@ -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 @@ -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 @@ -66,13 +65,27 @@ 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}" @@ -80,7 +93,6 @@ else $DISCORDCMD \ --file "${PDFNAME}" \ - --webhook-url="$WEBHOOK" \ --username "CCDCPrinter" \ --text "${message}" \ --avatar "https://i.imgur.com/0R30ZZ5.png" \ @@ -91,4 +103,3 @@ else fi fi exit 0 -