Browse Source

Add addPrintJob and printQueue commands

Samuel W. Flint 6 years ago
parent
commit
edacc15680
2 changed files with 59 additions and 0 deletions
  1. 38 0
      addPrintJob
  2. 21 0
      printQueue

+ 38 - 0
addPrintJob

@@ -0,0 +1,38 @@
+#!/bin/sh
+
+if [[ ! -d ~/prints/ ]] ; then
+    echo "~/prints/ does not exist as a directory." >&2
+    exit 1
+fi
+
+if [[ ! -e ~/prints/default ]] ; then
+    echo "~/prints/default does not exist." >&2
+    exit 1
+fi
+
+if [[ $# -lt 1 ]] ; then
+    echo "$0 fileName options*" >&2
+    exit 1
+fi
+
+FILENAME=$1
+shift
+
+COUNT=1
+DIRNAME=$(printf "${HOME}/prints/p%04d/" ${COUNT})
+
+until [[ ! -e $DIRNAME ]]
+do
+    DIRNAME=$(printf "${HOME}/prints/p%04d/" ${COUNT})
+    COUNT=$(( COUNT + 1 ))
+done
+
+echo ${DIRNAME}
+mkdir -p ${DIRNAME}
+
+cp "${FILENAME}" "${DIRNAME}/$(basename "${FILENAME}")"
+basename "${FILENAME}" > "${DIRNAME}/file"
+
+if [[ $# -gt 0 ]] ; then
+    echo $@ > "${DIRNAME}/options"
+fi

+ 21 - 0
printQueue

@@ -0,0 +1,21 @@
+#!/bin/sh
+
+if [[ $(ls ~/prints/p* 2>/dev/null | wc -l) -eq 0 ]] ; then
+    echo "No queued printjobs"
+    exit
+fi
+
+if [[ ! -e ~/prints/default ]] ; then
+    echo "~/prints/default does not exist" >&2
+    exit
+fi
+
+for JOB in ~/prints/p* ; do
+    FILE="${JOB}/$(cat "${JOB}/file")"
+    OPTIONS=$(cat ~/prints/default)
+    if [[ -e "${JOB}/options" ]] ; then
+        OPTIONS=$(cat "${JOB}/options")
+    fi
+    lpremote ${FILE} ${OPTIONS}
+    rm -r ${JOB}
+done