print

Print(script - auto setup (Linux & Mac) )

Introduction

Are you tired of opening the ThinLinc Client app, uploading your file, choosing the right driver, selecting the printer, printing one document, closing it all down again — and then starting from the top for the next document?

We have written a shell script that puts the institute's printers into the normal print dialog of your own system. After that it is ⌘P, pick printer, print. Nothing else. No app, no upload, no driver hunting, no VPN and no terminal.

Prerequisite: the compute-hosting setup. This script builds on the SSH access that imath-setup.sh creates — see the page imath script. Install that first, then come back here.

These scripts are tested on macOS and Linux devices. The device for Windows is not tested.


How it works

The print server print22.math.uzh.ch lives on the institute's internal network. It is not just firewalled — it is not even in public DNS. You need to be connected to the UZH Network.

Instead, the script sends your print jobs through the jump host you already have SSH access to:

imath-printing.png

printer_uzh is a small background service. It does not hold an SSH connection open. It only listens on the local port 6631; the moment a print job arrives, launchd (macOS) or systemd (Linux) starts one SSH connection, the job goes through, and the connection closes again. While you are not printing, nothing is connected — you can check that yourself with --status.

Which networks work: eduroam, the institute WLAN, a cable in the office. From outside UZH you need the UZH VPN, because the jump host itself is only reachable from a UZH network.


1. Installation

Download imath-printers.sh

chmod +x imath-printers.sh
./imath-printers.sh

It shows you every printer of the institute, numbered, and asks which ones you want:

Printers at the institute (52)

    1  g25                    2  h06                    3  h52
    4  j                      5  j-ps                   6  j04
    7  j06                    8  j08                    9  j10
  …

  Which ones do you want?
    a          all of them
    1 5 9      by number, separated by spaces
    h52 j      or simply by name
    <Enter>    cancel
  >

Options:

Command Effect
./imath-printers.sh pick printers from the list
./imath-printers.sh --uninstall remove everything it installed

It is idempotent. Running it again adds what is missing, corrects what has changed, and leaves everything else alone. Add more printers later by simply running it again with their names.


2. Everyday use

There is nothing to learn. The printers are in the print dialog of every program, exactly like a printer at home:

example.png

Paper size, duplex, trays and the finishing options are the real ones: the script asks the print server for each printer's own capabilities instead of guessing a driver.

If a job sits in the queue instead of printing, you are simply offline. It goes out by itself as soon as the machine has internet again — no need to print it a second time.


3. Documentation

For transparency — the same reason as on the compute page. This is what the script does, so that nobody has to take "just run this" on faith.

3.1 What it creates

Where What
~/Library/LaunchAgents/printer_uzh.plist (macOS) the background service, socket-activated
~/.config/systemd/user/printer_uzh.socket + printer_uzh@.service (Linux) the same thing for systemd
~/.config/imath/printers.list the list of printer queues this script created
CUPS queues one per printer you chose, pointing at ipp://localhost:6631/printers/<name>

That is all. It writes nothing into your shell configuration, installs no packages, and needs no sudo — CUPS queues belong to your user account.

~/.config/imath/printers.list is the important one: it is how the script knows which printers are its own. Printers you added yourself are never touched, not even by --uninstall.

3.2 What the installation does, step by step

  1. Check the jump host. ssh -o BatchMode=yes imath true. If that fails, the script stops and tells you to run imath-setup.sh first. Nothing has been changed at that point.
  2. Clean up an older version. If a previous, hand-made setup is still holding the port under an old name, that service and its IMATH-… queues are removed first, so the two do not fight over port 6631.
  3. Read the printer list. ssh imath "lpstat -h print22.math.uzh.ch -a" — the list comes from the print server itself, over the jump host. No tunnel is needed just to read it.
  4. Ask you which ones you want (or take --all, or the names you gave on the command line).
  5. Install the service. The service comes before the printers, because it is what gives them the local port to talk to.
  6. Add the printers: lpadmin -p <name> -E -v ipp://localhost:6631/printers/<name> -m everywhere. -m everywhere is the part that asks the server for the printer's real capabilities.
  7. Check. It sends an IPP request to localhost:6631 and reports whether the answer came back.

3.3 Where the data comes from

Everything comes from the institute's own print server, nothing is hard-coded:

The only fixed values in the script are the server name print22.math.uzh.ch, the SSH host entry imath, and the local port 6631.

3.4 What it does not do

3.5 Uninstall

./imath-printers.sh --uninstall

Removes exactly the printers listed in ~/.config/imath/printers.list, stops and deletes the printer_uzh service, and removes its log. Your own printers stay, and your SSH setup from imath-setup.sh stays as it is.


4. When something does not work

Symptom Cause and remedy
Run imath-setup.sh first The SSH access is missing. Install the compute-hosting setup, then run this again.
The job waits in the queue You are offline, or not on a UZH network. Connect to eduroam, or switch on the VPN; the job goes out by itself.
--status says the tunnel does not answer Something else is using port 6631, or the service did not start. Run the script again — it rewrites the service.
The printer is there but prints nothing Check in --status whether the queue is idle or disabled. A disabled queue: cupsenable <name>.
A printer is missing from the list ./imath-printers.sh --list shows everything the institute has; add it by name.

linux

Printing via UZHPrintPlus

Offical ZI Page: UZH Print Plus

Printing is possible via WLAN UZH, but not via WLAN EduRoam.

Printing via MATH/DM3L-Print server

Printing is possible via LAN aswell as WLAN UZH & EduRoam

IMATH-Account required.  Create I-MATH Account

Adding Printers

Institute
UPP 
Authentication

image.png

Booklet Printing

Only available on specific UPP Printer-Queues (jcolor_booklet & kcolor_booklet)

Troubleshooting

mac

Printing via UZHPrintPlus

Offical ZI Page: UZH Print Plus

Printing is possible via WLAN UZH, but not via WLAN EduRoam.


Printing via MATH/DM3L-Print server

Printing is possible via LAN aswell as WLAN UZH & EduRoam

IMATH-Account required.  Create I-MATH Account

Setup 

11.png

image.png

image.png

Booklets

Only available on specific UPP Printer-Queues (jcolor_booklet & kcolor_booklet)

Overview-Print

Printing I-MATH vs. UZH Printplus (UPP)

At the institute there are two printing solutions available: I-MATH-based and UZH Printplus (UPP)-based.

  I-MATH UPP
Printer All printers & copiers Copiers k, kcolor and j, jcolor. Thinlinc Print Dialog: UZHPrintPlus
UZH wide - yes
Cost Low. I-MATH pays the infrastructure High. UZH
Scan Only a few dedicated rooms (not public) k / kcolor, j / jcolor - use your UZH badge, free
Paying see below UZH Printplus
Requirements I-MATH Account (or guest) UZH Account & Badge

Printing 

Please review the specific page:

Printer Names

Public printers

Printer Location Color Remarks
h52 Y27 H52 No  
j11 Y27 J11 No  
k49 Y27 K49 No  
k49color Y27 K49 Yes
j J floor No Stapling, booklet print, A3 format
jcolor J Floor Yes Stapling, booklet print, A3 format
jcolor_booklet J Floor Yes Only booklet print
k K floor No Stapling, booklet print, A3 format
kcolor K floor Yes Stapling, booklet print, A3 format
kcolor_booklet K floor Yes Only booklet print

Credit System

All printers of the institute are connected to a central print server, which logs and counts all print jobs. Before a print is sent to a printer, the system gets the page number and job settings, calculates the costs and checks permissions and credits for the sender. After a successful printing, the credits will be subtracted.

Credits and free printing black and white color
members of the institute* free free**
students*** costs costs

Prices for all printers with different settings!

Charging/Checking Credits

Booklets

Printers / Copiers 'jcolor' and 'kcolor' are capable to fold and stamp printouts to create booklets / brochures.

Poster Printing (large)

Troubleshooting

Text replaced by □ 

image.png

In case you printed on k, kcolor, j, jcolor and the text on the printout is replaced by squares or weird characters, do the following:

windows

Printing via UZHPrintPlus

Offical ZI Page: UZH Print Plus

Printing is possible via WLAN UZH, but not via WLAN EduRoam.

Printing via MATH/DM3L-Print server

Printing is possible via LAN aswell as WLAN UZH & EduRoam

IMATH-Account required.  Create I-MATH Account

Setup

image.png

image.png

image.png

image.png

image.png

Booklets

Only available on specific UPP Printer-Queues (jcolor_booklet-win & kcolor_booklet-win)

Example:

image.png

thinlinc

The thinlinc environment provides a simple printing solution for workstations and personal devices.

Create own printer instances

Create own printer instances with personal settings. Such instances are only available via command line.


[user@host
# Create an instance 'jcolor/bw', which prints to 'jcolor', but always in b/w:
$ lpoptions -p jcolor/bw -o ColorModel=Gray

# To use the new instance:
$ lp -d jcolor/bw output.pdf

# Show all printer, incl. instances:
$ lpstat -t

# The local instances are saved under
~/.cups/lpoptions

Printing with Command Line

Description Syntax / Example
List all printers lpstat -a
Show default printer lpstat -d
Set default printer lpoptions -d
Ex: lpoptions -d k
Print lp [-d ]
Ex: lp -d h52 paper.pdf
Print several copies (see notes) lp -n [-d ]
Ex: lp -n 5 paper.pdf
Print several copies (see notes) in the order 1,2,3... lp -o Collate=True -n
Ex: lp -o Collate=true -n 5 paper.pdf
Print several copies with staples (see notes) lp -d -o RepeatJob= -o StaplePos=1PLU
Ex: lp -d j -o RepeatJob=10 -o StaplePos=1PLU exam.pdf
Print 2 pages on one site lp -o number-up=2
Ex: lp -p number-up=2 paper.pdf
Printing one sided on a duplex printer lp -o duplex=None
Ex: lp -o duplex=None paper.pdf
Printing duplex with turning on short edge lp -o duplex=DuplexTumble
Ex: lp -o duplex=DuplexTumble paper.pdf
Printing transparencies lp -o media=Transparency
Ex: lp -o media=Transparency
Printing with stapling (see note 1) - only j, jcolor, k, kcolor lp -d jcolor -o StapleType=StapleON -o StaplePos=(1PLU|1PRU|1PLB|1PRB|2PL|2PR|2PU|2PB)
Ex: lp -d jcolor -o Duplex=None -o StapleType=StapleON -o StaplePos=1PLU -o sides=one-sided
Printing booklet via jcolor_booklet and kcolor_booklet (see note 3) lp -d -o print-color-mode=Color|Grayscale
Ex: lp -d jcolor_booklet -o print-color-mode=Color -o PageSize=A5 paper.pdf
Printing booklet via j-ps and k-ps (see note 3) lp -d -o BindMode=SaddleStitch -o Duplex=None -o Booklet=Left -o print-color-mode=Color
Ex: lp -d jcolor -o PageSize=A5 -o BindMode=SaddleStitch -o Duplex=None -o Booklet=Left -o Finishing=Col -o print-color-mode=Color paper.pdf

Note 1: Pay attention on combining copies and stapling. If you like to print a PDF (e.g. 4 pages) 10 times, do NOT use the -n parameter. The whole printjob, 4 pages * 10 copies, will be stapled together (only one)!

Solution: Use the 'Repeat Job' option in the advanced tab of the print dialog

Note 2: Do not print many copies at once, because it requires a lot of resources of the printer.

Solution: Use the lpRepeat script instead (with the -s parameter to specify a delay):


$ lpRepeat -d h52 -n 30 -s 15 big_file.pdf

Note 3: Booklet printing can be simplified with the lpBooklet script:


# Color print
$ lpBooklet -d jcolor -f booklet.pdf

# Black & white print
$ lpBooklet -d j -f booklet.pdf

Option values

Duplex: one/two sided print

Value Meaning
None One sided
!DuplexTumble Two sided along long edge
!DuplexNoTumble Two sided along short edge

StaplePos: staple position

Value Portrait mode Landscape mode
!PosNone No staple No staple
1PLU Upper left Upper right
1PRU Upper right Bottom right
1PLB Bottom left Upper left
1PRB Bottom right Bottom left
2PL Left x2 Upper x2
2PR Right x2 Bottom x2
2PU Upper x2 Right x2
2PB Bottom x2 Left x2
SDL Middle x2 Middle x2

Printing with graphical interface (evince PDF viewer)

Stapling

In the print preview dialog select j, jcolor, k, or kcolor and on the tab 'Advanced'

  1. choose the position of a staple (here upper left corner)
  2. specify Repeat Job if you need more than one copy

print-staples-pcl-advanced.png

Note: do not specify Copies on the General tab to print several stapled copies! If you do so, all copies are stapled together!

Booklet

In the print preview dialog select jcolor_booklet or kcolor_booklet - these printers are already configured for booklet printing.

Alternatively, select j, jcolor, k, or kcolor and choose the following options:

  1. Left binding for Booklet Printing on the tab Finishing
  2. Saddle Stitch for Staple Position on the tab Advanced

print-booklet-pcl-finishing.pngprint-booklet-pcl-advanced.png

Note: booklet printing requires A4 or A5 format.

Printing exams - lpSequential

If you have a personalized exam, one PDF for all students, and you like to print it and the output should be:

than use the lpSequential script (commandline).


# K Floor (k)
$ lpSequential -o Duplex=None -o StaplePos=1PLU -o StapleType=StapleON -o sides=one-sided <file.pdf> k <pages per exam> <start page to print from> <delay in seconds>
# J Floor (jcolor_booklet) - with color
$ lpSequential -o Duplex=None -o StaplePos=1PLU -o StapleType=StapleON -o sides=one-sided -o print-color-mode=Color <file.pdf> jcolor <pages per exam> <start page to print from> <delay in seconds>

Example:

Staple lpSequential -o Duplex=None -o StaplePos=1PLU -o StapleType=StapleON -o sides=one-sided exam.pdf k 16 1 0 printer 'k', 16 pages per exam, starting at 1, no delay
Shifting lpSequential -o Duplex=None -o sides=one-sided exam.pdf jcolor 8 33 5 printer 'jcolor', 8 pages per exam, starting at 33, 5 seconds delay