3
# $Id: update-fonts-scale 189 2005-06-11 00:04:27Z branden $
5
# This program generates fonts.scale files for X font directories; see
6
# mkfontdir(1x) for a description of the format of fonts.scale files.
8
# Copyright 1999-2002, 2004 Branden Robinson.
9
# Copyright 2006 Steve Langasek.
10
# Licensed under the GNU General Public License, version 2. See the file
11
# /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
15
# Query the terminal to establish a default number of columns to use for
16
# displaying messages to the user. This is used only as a fallback in the event
17
# the COLUMNS variable is not set. ($COLUMNS can react to SIGWINCH while the
18
# script is running, and this cannot, only being calculated once.)
19
DEFCOLUMNS=$(stty size 2>/dev/null | awk '{print $2}') || true
20
if ! expr "$DEFCOLUMNS" : "[[:digit:]]\+$" >/dev/null 2>&1; then
24
# Display a message, wrapping lines at the terminal width.
26
echo "$*" | fmt -t -w ${COLUMNS:-$DEFCOLUMNS}
29
# Display a debugging message.
31
if [ -n "$DEBUG" ]; then
32
message "note: $*" >&2
36
# Display a warning message.
38
message "warning: $*" >&2
41
# Display an error message and exit.
43
message "fatal error: $*" >&2
47
# Display a usage message.
50
message "usage error: $*"
53
Usage: $PROGNAME DIRECTORY ...
54
$PROGNAME { -h | --help }
55
This program combines scalable X font information from several packages into a
56
single file that is placed in each specified X font directory DIRECTORY. This
57
utility is primarily useful to Debian package maintainer scripts. See
58
update-fonts-scale(8) for more information.
60
-h, --help display this usage message and exit
80
usage "unrecognized option" >&2
86
usage "one or more font directories must be specified" >&2
91
# Try to be clever about the argument; were we given an absolute path?
92
if expr "$1" : "/.*" >/dev/null 2>&1; then
93
# Yes; an absolute path to an X font directory was provided.
95
ETCDIR=/etc/X11/fonts/${X11R7DIR##*/}
96
ETC7DIR=/etc/X11/fonts/X11R7/${X11R7DIR##*/}
97
if [ "$X11R7DIR" = "$ETCDIR" ] || [ "$X11R7DIR" = "$ETC7DIR" ]; then
98
# We were given an /etc directory as an argument.
99
die "path to X font directory must be used"
101
warn "absolute path $X11R7DIR was provided"
104
# No; a relative path was provided -- assume we were given just the
106
X11R6DIR=/usr/lib/X11/fonts/$1
107
X11R7DIR=/usr/share/fonts/X11/$1
108
ETCDIR=/etc/X11/fonts/$1
109
ETC7DIR=/etc/X11/fonts/X11R7/$1
114
# Confirm that the directories to be operated on exist.
116
if [ -d "$ETCDIR" ]; then
119
warn "$ETCDIR does not exist or is not a directory"
121
if [ -d "$ETC7DIR" ]; then
124
if [ -n "$X11R7_LAYOUT" ]; then
125
warn "$ETC7DIR does not exist or is not a directory"
130
for DIR in "$X11R7DIR" "$X11R6DIR"; do
131
[ -n "$DIR" ] || continue
132
if [ -d "$DIR" ]; then
135
warn "$DIR does not exist or is not a directory"
139
if [ -z "$VALIDSRC" ] || [ -z "$VALIDDEST" ]; then
143
# Are there any files to process?
144
if [ "$(echo "$ETCDIR"/*.scale "$ETC7DIR"/*.scale)" != "$ETCDIR/*.scale $ETC7DIR/*.scale" ]
146
for XDIR in "$X11R7DIR" "$X11R6DIR"; do
147
if [ -z "$XDIR" ] || ! [ -d "$XDIR" ]; then
150
for SCALEFILE in "$ETCDIR"/*.scale "$ETC7DIR"/*.scale; do
151
[ -e "$SCALEFILE" ] || continue
152
# Only write fonts to the .scale file that actually exist, so
153
# that removed-but-not-purged scalable font packages do not
154
# register nonexistent fonts; this has the desirable side effect
155
# that the count at the top of the file is also omitted.
157
# XXX: This technique will be tricked into yielding false
158
# negatives if the font filename has whitespace in it.
159
while read FONTFILE FONTNAME; do
160
if [ -f "$XDIR/$FONTFILE" ]; then
161
echo "$FONTFILE $FONTNAME" \
162
>>"$XDIR/fonts.scale.update-tmp"
164
trace "$SCALEFILE references nonexistent font file" \
165
"$FONTFILE; skipping"
169
if [ -e "$XDIR/fonts.scale.update-tmp" ]; then
170
# Write the new scale file to a temporary location in case we
171
# are interrupted. Write the new count to the top of file. Use
172
# cat and pipe to wc so wc doesn't report the filename.
173
cat "$XDIR/fonts.scale.update-tmp" | wc -l | tr -d '[:blank:]' \
174
>"$XDIR/fonts.scale.update-new"
175
cat "$XDIR/fonts.scale.update-tmp" \
176
>>"$XDIR/fonts.scale.update-new"
177
mv "$XDIR/fonts.scale.update-new" "$XDIR/fonts.scale"
178
rm "$XDIR/fonts.scale.update-tmp"
180
# No font in the processed *.scale files was in the current
181
# directory, so remove fonts.scale.
182
rm -f "$XDIR/fonts.scale"
186
for XDIR in "$X11R7DIR" "$X11R6DIR"; do
187
if [ -z "$XDIR" ] || ! [ -d "$XDIR" ]; then
190
# No files to process; remove any fonts.scale file already in the
192
rm -f "$XDIR/fonts.scale"
193
# Remove the font directory if it is empty.
194
rmdir "$XDIR" >/dev/null 2>&1 || true
201
# vim:set ai et sts=4 sw=4 tw=80: