//sbin/sbin/sbin/sbin/sbin/sbin/sbin/#! /bin/sh
# paperconfig: configuration of system paper name
#
# Copyright (C) 1996, Yves Arrouye
# 2001, Adrian Bunk
usage() {
if [ "$1" = -h ]
then
exec 1>&2
echo -n U
else
echo -n u
fi
echo "sage: `basename $0` [ -v, --version ] [ -h, --help ] [ -p, --paper name | --force ]"
if [ "$1" = -h ]
then
cat <"
exit 0
;;
-h|--help)
usage -h
;;
-p|--paper)
test $# -gt 1 || usage
paper="$2"
shift
;;
--force)
force=1
;;
*)
usage
;;
esac
shift
done
invalidpaper() {
! paperconf "$1" 2>/dev/null 1>&2
}
format() {
_maxwidth=$1; shift
_start="$1"; shift
_cline=
for w
do
if [ `echo "$_start$_cline$w " | wc -c` -ge 0$_maxwidth ]
then
echo "$_cline"
_cline=
_start=
fi
_cline="$_cline$w "
done
if [ -n "$_cline" ]
then
echo "$_cline"
fi
unset _maxwidth _cline _start
}
# "chmod 644" added below, to assure that the conf file is created
# with the right access permissions (MP 13/05/2000)
setpaper() {
paperright=`paperconf "$1" 2>/dev/null`
ok=0
if 2>/dev/null echo "$paperright" >${PAPERCONF}.new
then
if 2>/dev/null mv -f ${PAPERCONF}.new $PAPERCONF
then
if 2>/dev/null chmod 644 $PAPERCONF
then
ok=1
fi
fi
fi
if [ $ok -eq 0 ]
then
echo `basename $0`: cannot create $PAPERCONF
exit 2
else
#
# Added code for calling back applications when
# papersize changes. See bug #345466
# eppesuig@debian.org, 2006-01-05
if [ -d ${PAPERDIR} ]
then
run-parts ${PAPERDIR}
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="`paperconf -a`"
prompt=
width=72
# "|| true" added below, to assure that the script does not fail even if
# called with bash -e. (MP 22/08/98)
paper=`paperconf 2>/dev/null || true`
dftpaper=`paperconf -d`
if [ $force -eq 1 ] || [ ! -e $PAPERCONF ] || invalidpaper $paper
then
papers="`format $width \"\" $knownpapers`"
echo
if [ -x /usr/bin/pager ]
then
: ${PAGER:=/usr/bin/pager}
fi
if [ -x /bin/more ]
then
: ${PAGER:=/bin/more}
fi
: ${PAGER:=cat}
LESS="-X -E $LESS"
export LESS
(
cat </dev/null`" != "$paper" ] || grep -q "[# ]" $PAPERCONF
then
setpaper "$paper"
fi
exit 0