ps2book reads one or several PostScript files and rearranges the pages into a booklet. It is essentially a (sufficiently complex) wrapper around the two utilities psbook(1) and pstops(1) by Angus Duggan.
If no file is given, ps2book acts as a filter on stdin and writes the result to stdin_book.ps (or sends it to the printer if this was specified).
By default, a PostScript duplex `cookie' is inserted into the file, so it will print in duplex mode on PostScript printers which are capable of doing so.
You can download ps2book or read the documentation.