Debian Codegraph @

src/a2ps-lpr-wrapper

raw
1 #!/bin/sh
2 #
3 # a2ps-lpr-wrapper - lp/lpr wrapper script for GNU a2ps
4
5 set -e
6
7 usage() {
8 echo "Usage: $(basename "$0") [-d printer] [FILE...]" >&2
9 exit 1
10 }
11
12 printer=""
13 while getopts d: flag; do
14 case "$flag" in
15 d) printer=$OPTARG ;;
16 *) usage ;;
17 esac
18 done
19 shift $((OPTIND - 1))
20
21 # If lp (from CUPS) exists, just use it.
22 if command -pv lp > /dev/null; then
23 printer_opt=-d
24 command="lp"
25 elif command -pv lpr >/dev/null; then
26 # In case lp is not available, then fall back to lpr.
27 printer_opt=-P
28 command="lpr"
29 elif command -pv rlpr >/dev/null; then
30 # In case lpr is not available, then fall back to rlpr.
31 printer_opt=-P
32 command="rlpr"
33 else
34 # If none of lp, lpr and rlpr is available, then fail
35 echo "$0: no program found to print files"
36 exit 1
37 fi
38
39 # Run the command
40 opts=""
41 if [ "$printer" != "" ]; then
42 opts="$printer_opt $printer"
43 fi
44 command -p "$command" $opts "$@"