addPrintJob 686 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/bin/sh
  2. if [[ ! -d ~/prints/ ]] ; then
  3. echo "~/prints/ does not exist as a directory." >&2
  4. exit 1
  5. fi
  6. if [[ ! -e ~/prints/default ]] ; then
  7. echo "~/prints/default does not exist." >&2
  8. exit 1
  9. fi
  10. if [[ $# -lt 1 ]] ; then
  11. echo "$0 fileName options*" >&2
  12. exit 1
  13. fi
  14. FILENAME=$1
  15. shift
  16. COUNT=1
  17. DIRNAME=$(printf "${HOME}/prints/p%04d/" ${COUNT})
  18. until [[ ! -e $DIRNAME ]]
  19. do
  20. DIRNAME=$(printf "${HOME}/prints/p%04d/" ${COUNT})
  21. COUNT=$(( COUNT + 1 ))
  22. done
  23. echo ${DIRNAME}
  24. mkdir -p ${DIRNAME}
  25. cp "${FILENAME}" "${DIRNAME}/$(basename "${FILENAME}")"
  26. basename "${FILENAME}" > "${DIRNAME}/file"
  27. if [[ $# -gt 0 ]] ; then
  28. echo $@ > "${DIRNAME}/options"
  29. fi