#!/bin/sh # paperconfig: configuration of system paper name # # Copyright (C) 1996, Yves Arrouye # 2001, Adrian Bunk # 2021-2022, Reuben Thomas # # 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 # . 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 <" 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 </dev/null`" != "$paper" ] || grep -q "[# ]" $PAPERSIZE; then setpaper "$paper" fi