Skip to content

Instantly share code, notes, and snippets.

@petrsnd
Created July 22, 2022 19:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petrsnd/00d0b4bec4de76a03f7c0819a138e457 to your computer and use it in GitHub Desktop.
Save petrsnd/00d0b4bec4de76a03f7c0819a138e457 to your computer and use it in GitHub Desktop.
Fetch and RFC and make it printable as a booklet
#!/bin/bash
# Dan Peterson
# Threw out Matt's old stuff and now I just use pdfbook2 to generate the booklet
if test -t 1; then
YELLOW='\033[1;33m'
RED='\033[1;31m'
NC='\033[0m'
fi
EnsureProgramExists()
{
local prgm=`which $1`
if [ ! -x "$prgm" ]; then
>&2 echo -e "${RED}Unable to find the $1 program${NC}"
exit 2
fi
}
if [ -z $1 ]; then
echo "Print the resulting PDF 2-sided (landscape), fold it in half, and staple"
echo "the centerfold. Walla, you've got a handy booklet"
echo "Usage: $0 rfc_number"
exit 0
fi
echo "$1" | grep -q [^[:digit:]]
if [ $? -ne 1 ] ; then
>&2 echo -e "${RED}You must enter the number of an RFC${NC}"
exit 2
fi
EnsureProgramExists wget
EnsureProgramExists pdfbook2
#url="http://www.ietf.org/rfc/rfc$1.txt"
url="https://www.ietf.org/rfc/rfc$1.txt.pdf"
outfile="rfc$1.pdf"
bookfile="rfc$1-book.pdf"
wget -O $outfile "$url"
pdfbook2 $outfile
echo -e "\n${YELLOW}PDF: $outfile\nBooklet: $bookfile${NC}"
echo -e "\nPrint double-sided. Flip on the long edge when printing!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment