1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
|
#!/bin/sh
# paperconfig: configuration of system paper name
#
# Copyright (C) 1996, Yves Arrouye <arrouye@debian.org>
# 2001, Adrian Bunk <bunk@fs.tum.de>
# 2021-2022, Reuben Thomas <rrt@sc3d.org>
#
# This file is part of the libpaper Debian package.
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 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
# <https://www.gnu.org/licenses/gpl-2.0.html>.
sysconfdir="/etc"
PAPERSIZE="$sysconfdir/papersize"
PAPERRUNPARTSDIR="$sysconfdir/paper.d"
PAPER_PROGRAM="/usr/bin/paper"
usage() {
echo "Usage: `basename $0` [--version|--help|--paper NAME|--choose]"
cat <<EOF
Options: -V, --version print version information and exit
-h, --help print this help and exit
-p, --paper NAME specify the paper to use
-c, --choose choose paper interactively
EOF
exit $1
}
choose=0
if [ "$#" -eq 0 ]; then
exec "$PAPER_PROGRAM" --no-size
fi
while [ $# -ne 0 ]; do
case "$1" in
-V|--version)
echo "`basename $0` version 2" \
"by Yves Arrouye <arrouye@debian.org>"
exit 0
;;
-h|--help)
usage 0
;;
-p|--paper)
test $# -gt 1 || usage
paper="$2"
shift
;;
-c|--choose)
choose=1
;;
*)
usage 1
;;
esac
shift
done
invalidpaper() {
! "$PAPER_PROGRAM" --no-size "$1" 2>/dev/null 1>&2
}
setpaper() {
paperright=`"$PAPER_PROGRAM" --no-size "$1" 2>/dev/null`
ok=0
if 2>/dev/null echo "$paperright" >${PAPERSIZE}.new; then
if 2>/dev/null mv -f ${PAPERSIZE}.new $PAPERSIZE; then
if 2>/dev/null chmod 644 $PAPERSIZE; then
ok=1
fi
fi
fi
if [ $ok -eq 0 ]; then
echo `basename $0`: cannot create $PAPERSIZE
exit 2
else
if [ -d $PAPERRUNPARTSDIR ]; then
run-parts $PAPERRUNPARTSDIR
fi
fi
}
if [ ! -z "$paper" ]; then
if invalidpaper $paper; then
>&2 echo `basename $0`: \"$paper\" is not a known paper name
exit 3
fi
setpaper "$paper"
exit 0
fi
knownpapers="`"$PAPER_PROGRAM" --all --no-size`"
prompt=
width=72
paper=`"$PAPER_PROGRAM" --no-size 2>/dev/null || true`
dftpaper=`"$PAPER_PROGRAM" --no-size`
if [ $choose -eq 1 ]; then
echo
LESS="-X -E $LESS"
export LESS
(
cat <<EOF
The system paper can be chosen from many known papers that are
currently recognized:
EOF
echo "$knownpapers" | sed 's/^/ /'
echo
) | /usr/bin/sensible-pager
: ${paper:=$dftpaper}
echo -n "Default paper name? [$paper] "
read ans
: ${ans:=$paper}
paper=$ans
while invalidpaper "$paper"; do
if [ -z "$paper" ]; then
echo "Please choose a paper from the available papers list."
else
echo "Unknown paper \"$paper\"," \
"please choose one from the available papers list."
fi
paper=$dftpaper
echo -n "Default paper name? [$paper] "
read ans
paper=$ans
done
fi
if invalidpaper "$paper"; then
echo "Invalid paper \"$paper\": not setting the system default."
exit 4
elif [ "`"$PAPER_PROGRAM" --no-size 2>/dev/null`" != "$paper" ] || grep -q "[# ]" $PAPERSIZE; then
setpaper "$paper"
fi
|