#!/usr/bin/env bash # HEADER #======================================================================= # # qrcode -- make a QR code for a given URL. # # SYNOPSIS # qrcode output # # DESCRIPTION # Shell script to make a PDF file with a QR code corresponding to a # given URL. It uses LaTeX to get a nicer output than `qrencode`. # # POSITIONAL ARGUMENT # URL # # OPTIONS # -h|--help display this help and exit # -o|output PDF outfile name # # EXAMPLE # $ qrcode nmesnier.free.fr -o QR.pdf # # DEPENDENCIES # - latex, dvips, ps2pdf (ghostscript) # - GNU coreutils # # Copyright (C) 2020 Nicolas Mesnier # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License version 3 or # above as published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # #======================================================================= # END_OF_HEADER #----------------------------------------------------------------------- Help(){ # Read header to display help and version BOH=$(head -200 ${0} | grep -n "^# HEADER" | cut -f1 -d:) EOH=$(head -200 ${0} | grep -n "^# END_OF_HEADER" | cut -f1 -d:) head -$(($EOH-1)) ${0} | tail -$(($EOH-$BOH-1)) \ | grep -e "^#$" -e "^# " | sed -e "s/^#=*//g" } #----------------------------------------------------------------------- __MakeQR__(){ # Input: # $1: URL # $2: PDF file name # Output: # PDF file URL=${1} QRFILE=${2%.pdf*} echo $QRFILE if [ ${URL:0:4} != "http" ];then URL="http://"${URL} fi cat > ${QRFILE}".tex" <&2 exit 1 fi done #----------------------------------------------------------------------- # *** run #----------------------------------------------------------------------- if [ ! -z "${URL}" ];then __MakeQR__ ${URL} ${OUTFILE} fi #====================================================================eof # vim: set tw=72 ts=4 sw=4 nu: