#!/bin/sh
# print-duplex.sh - simple wrapper to print duplex
#  https://opensource.com/article/20/4/print-duplex-bash-script
# https://crystalfaeries.net/posix/bin/print-duplex
# 
cat<<EOF
$1 ($pages pages)
-------------------------------------------------------------------------------
Printing odd pages first
Please wait for job to finish printing...
-------------------------------------------------------------------------------
EOF

lpr -P "HP_LaserJet_CP1525nw" -o page-set=odd "$1"
sleep $pages

cat<<EOF
===============================================================================
Put paper back into the printer in EXACT OUTPUT ORDER (face down in tray)
then press ENTER
===============================================================================
EOF

pages=$( pdfinfo "$1" | awk '/^Pages:/ {print $2}' )

if [ $(( $pages % 2 )) -ne 0 ] ; then
  echo '!! Remove the last page - this document has an odd number of pages'
fi

echo -n '>'
read x

cat<<EOF
-------------------------------------------------------------------------------
Printing even pages
Please wait for job to finish printing...
-------------------------------------------------------------------------------
EOF

lpr -P "HP_LaserJet_CP1525nw" -o page-set=even -o outputorder=reverse "$1"


