Skip to content

Instantly share code, notes, and snippets.

@maakuth
Created March 19, 2012 10:12
Show Gist options
  • Save maakuth/2106374 to your computer and use it in GitHub Desktop.
Save maakuth/2106374 to your computer and use it in GitHub Desktop.
Printing script for University of Jyväskylä
#!/bin/bash -e
#
# Printing made easy for your Linux laptop in the University of Jyväskylä.
# Public domain. Original work by Zouppen and cedx.
#
# Before using, send your public key to charra (to avoid password prompt)
# and put the following in your ~/.ssh/config:
#
# Host charra
# User YOUR_USERNAME
# HostName charra.it.jyu.fi
CONFIG=~/.jyu_printer
[[ -e "$CONFIG" ]] && DEFAULT=$(<"$CONFIG") || DEFAULT=jysecure-bw
case "$1" in
--choosedefault|-d)
PRINTERS=`ssh -q -e none charra "lpstat -a" | awk '{print $1}'`
echo 'Current default is "'"$DEFAULT"'".'
select PRINTER in $PRINTERS; do
if [[ -z $PRINTER ]]; then
echo
echo "That's not in the list!"
echo "Pick a number of a printer in this list."
echo
else
echo "$PRINTER" >"$CONFIG"
echo 'New default printer is "'"$PRINTER"'".'
break
fi
done
exit 0
;;
--printer|-P)
DEFAULT=$2
shift 2
;;
--help|-h|"")
echo "Printing: $0 [-P, --printer PRINTER] filename.pdf [copies]" >&2
echo " $0 -d, --choosedefault" >&2
echo >&2
echo 'Current default printer is "'"$DEFAULT"'".' >&2
exit 0
;;
esac
if [[ ! -e "$1" ]]; then
echo "File name doesn't exist. Try --help"
exit 1
fi
if [[ "$2" ]]; then
export KOPIOT="-# $2"
else
unset KOPIOT
fi
ssh -e none charra "lpr -P $DEFAULT $KOPIOT" <"$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment