#!/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
