Debian Codegraph @

debian/local/update-fonts-alias

raw symbols SCIP
1 #!/bin/shscip-shell filesystem . . `/bin/sh`.
2
3 # $Id: update-fonts-alias 189 2005-06-11 00:04:27Z branden $
4
5 # This program compiles fonts.alias files for X font directories; see
6 # mkfontdir(1x) for a description of the format of fonts.alias files.
7
8 # Copyright 1999, 2001, 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 <https://www.gnu.org/copyleft/gpl.txt>.
12
13 PROGNAME=${0##*/}
14
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=$(sttyscip-shell system . . stty. size 2>/dev/nullscip-shell filesystem . . `/dev/null`. | awkscip-shell system . . awk. '{print $2}') || truescip-shell system . . true.
20 if ! exprscip-shell system . . expr. "$DEFCOLUMNS" : "[[:digit:]]\+$" >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1; then
21 DEFCOLUMNS=80
22 fi
23
24 # Display a message, wrapping lines at the terminal width.
25 messagescip-shell shell xfonts-utils 1:7.7+7 message(). () {
26 echoscip-shell system . . echo. "$*" | fmtscip-shell system . . fmt. -t -w ${COLUMNS:-$DEFCOLUMNS}
27 }
28
29 # Display a warning message.
30 warnscip-shell shell xfonts-utils 1:7.7+7 warn(). () {
31 messagescip-shell shell xfonts-utils 1:7.7+7 message(). "warning: $*" >&2
32 }
33
34 # Display an error message and exit.
35 diescip-shell shell xfonts-utils 1:7.7+7 die(). () {
36 messagescip-shell shell xfonts-utils 1:7.7+7 message(). "fatal error: $*" >&2
37 exit 1
38 }
39
40 # Display a usage message.
41 usagescip-shell shell xfonts-utils 1:7.7+7 usage(). () {
42 if [scip-shell system . . `[`. -n "$*" ]; then
43 messagescip-shell shell xfonts-utils 1:7.7+7 message(). "usage error: $*"
44 fi
45 catscip-shell system . . cat. <<EOF
46 Usage: $PROGNAME [OPTIONS] DIRECTORY ...
47 $PROGNAME { -h | --help }
48 This program combines X font alias information from several packages into a
49 single file that is placed in each specified X font directory DIRECTORY. This
50 utility is primarily useful to Debian package maintainer scripts. See
51 update-fonts-alias(8) for more information.
52 Options:
53 -h, --help display this usage message and exit
54 -i, --include ALIAS-FILE drop ALIAS-FILE from exlude list if any
55 -x, --exclude ALIAS-FILE add ALIAS-FILE to exclude list
56 EOF
57 }
58
59 X11R7_LAYOUT=
60 INCLUDE_ALIAS=
61 EXCLUDE_ALIAS=
62 EXCLUDE_CONF=/var/lib/xfonts/excluded-aliasesscip-shell filesystem . . `/var/lib/xfonts/excluded-aliases`.
63
64 # Validate options.
65 while [scip-shell system . . `[`. $# -gt 0 ]; do
66 case "$1" in
67 -h|--help)
68 usagescip-shell shell xfonts-utils 1:7.7+7 usage().
69 exit 0
70 ;;
71 -7|--x11r7-layout)
72 X11R7_LAYOUT=true
73 shift
74 ;;
75 -i|--include)
76 if [scip-shell system . . `[`. $# -lt 2 ]; then
77 usagescip-shell shell xfonts-utils 1:7.7+7 usage(). "alias file to include is missing" >&2
78 exit 2
79 fi
80 INCLUDE_ALIAS="$INCLUDE_ALIAS $2"
81 shift 2
82 ;;
83 -x|--exclude)
84 if [scip-shell system . . `[`. $# -lt 2 ]; then
85 usagescip-shell shell xfonts-utils 1:7.7+7 usage(). "alias file to exclude is missing" >&2
86 exit 2
87 fi
88 EXCLUDE_ALIAS="$EXCLUDE_ALIAS $2"
89 shift 2
90 ;;
91 -*)
92 usagescip-shell shell xfonts-utils 1:7.7+7 usage(). "unrecognized option" >&2
93 exit 2
94 ;;
95 *)
96 break
97 ;;
98 esac
99 done
100
101 if [scip-shell system . . `[`. $# -eq 0 ]; then
102 usagescip-shell shell xfonts-utils 1:7.7+7 usage(). "one or more font directories must be specified" >&2
103 exit 2
104 fi
105
106 # Remove aliases to be included from exclude list
107 for f in $INCLUDE_ALIAS; do
108 sedscip-shell system . . sed. -i "\\,^$f$,d" $EXCLUDE_CONF
109 done
110 # Add aliases to be excluded to exclude list
111 for f in $EXCLUDE_ALIAS; do
112 sedscip-shell system . . sed. -i "\\,^$f$,d" $EXCLUDE_CONF
113 echoscip-shell system . . echo. "$f" >> $EXCLUDE_CONF
114 done
115
116 while [scip-shell system . . `[`. -n "$1" ]; do
117 # Try to be clever about the argument; were we given an absolute path?
118 if exprscip-shell system . . expr. "$1" : "/.*" >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1; then
119 # Yes; an absolute path to an X font directory was provided.
120 X11R7DIR=$1
121 ETCDIR=/etc/X11/fonts/${X11R7DIR##*/}
122 ETC7DIR=/etc/X11/fonts/X11R7/${X11R7DIR##*/}
123 if [scip-shell system . . `[`. "$X11R7DIR" = "$ETCDIR" ] || [scip-shell system . . `[`. "$X11R7DIR" = "$ETC7DIR" ]; then
124 # We were given an /etc directory as an argument.
125 diescip-shell shell xfonts-utils 1:7.7+7 die(). "path to X font directory must be used"
126 else
127 warnscip-shell shell xfonts-utils 1:7.7+7 warn(). "absolute path $X11R7DIR was provided"
128 fi
129 else
130 # No; a relative path was provided -- assume we were given just the
131 # basename.
132 X11R7DIR=/usr/share/fonts/X11/$1
133 ETCDIR=/etc/X11/fonts/$1
134 ETC7DIR=/etc/X11/fonts/X11R7/$1
135 fi
136
137 shift
138
139 # Confirm that the directories to be operated on exist.
140 VALIDSRC=
141 if [scip-shell system . . `[`. -d "$ETCDIR" ]; then
142 VALIDSRC=yes
143 else
144 warnscip-shell shell xfonts-utils 1:7.7+7 warn(). "$ETCDIR does not exist or is not a directory"
145 fi
146 if [scip-shell system . . `[`. -d "$ETC7DIR" ]; then
147 VALIDSRC=yes
148 else
149 if [scip-shell system . . `[`. -n "$X11R7_LAYOUT" ]; then
150 warnscip-shell shell xfonts-utils 1:7.7+7 warn(). "$ETC7DIR does not exist or is not a directory"
151 fi
152 fi
153
154 VALIDDEST=
155 if [scip-shell system . . `[`. -d "$X11R7DIR" ]; then
156 VALIDDEST=yes
157 else
158 warnscip-shell shell xfonts-utils 1:7.7+7 warn(). "$X11R7DIR does not exist or is not a directory"
159 fi
160
161 if [scip-shell system . . `[`. -z "$VALIDSRC" ] || [scip-shell system . . `[`. -z "$VALIDDEST" ]; then
162 continue
163 fi
164
165 if [scip-shell system . . `[`. -n "$X11R7DIR" ] && [scip-shell system . . `[`. -d "$X11R7DIR" ]; then
166 # Write the new alias file in a temporary location in case we are
167 # interrupted.
168 catscip-shell system . . cat. >"$X11R7DIR/fonts.alias.update-new" <<EOF
169 !! fonts.alias -- automatically generated file. DO NOT EDIT.
170 !! To modify, see update-fonts-alias(8).
171 EOF
172 has_data=0
173 for FILE in "$ETCDIR"/*.alias "$ETC7DIR"/*.alias; do
174 [scip-shell system . . `[`. -e "$FILE" ] || continue
175
176 # Skip excluded aliases
177 grepscip-shell system . . grep. -q "^$FILE$" $EXCLUDE_CONF && continue
178
179 echoscip-shell system . . echo. "!! $FILE" >>"$X11R7DIR/fonts.alias.update-new"
180 catscip-shell system . . cat. "$FILE" >>"$X11R7DIR/fonts.alias.update-new"
181 has_data=1
182 done
183 if [scip-shell system . . `[`. $has_data -eq 1 ]; then
184 mvscip-shell system . . mv. "$X11R7DIR/fonts.alias.update-new" "$X11R7DIR/fonts.alias"
185 else
186 rmscip-shell system . . rm. -f "$X11R7DIR/fonts.alias.update-new"
187 # There are no files to process; remove any alias file already in
188 # the font directory.
189 rmscip-shell system . . rm. -f "$X11R7DIR/fonts.alias"
190 # Remove the font directory if it is empty.
191 rmdirscip-shell system . . rmdir. "$X11R7DIR" >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 || truescip-shell system . . true.
192 fi
193 fi
194 done
195
196 exit 0
197
198 # vim:set ai et sts=4 sw=4 tw=80: