]>
Commit | Line | Data |
---|---|---|
d470d1c2 TP |
1 | #!/bin/sh -e |
2 | ||
3 | # to test POSIX-correctness, change hash-bang to /bin/bash and uncomment | |
4 | # the following line: | |
5 | ||
6 | # set -o posix | |
7 | ||
8 | # Very simple configuration script for t1lib. Checks system font | |
9 | # directory and adds anything ending in .pfa or pfb to the font | |
10 | # database. A few things borrowed from paperconfig, (C) 1996, Yves | |
11 | # Arrouye <arrouye@debian.org> | |
12 | ||
13 | # Based on script written by David Huggins-Daines <dhd@debian.org> | |
14 | ||
15 | usage() { | |
16 | cat <<EOF | |
17 | ||
18 | Usage: `basename $0` [ -v, --version ] [ -h, --help ] [ --force ] | |
19 | [ fontdirs... ] | |
20 | ||
21 | Options: -v, --version print version information and exit | |
22 | -h, --help print this help and exit | |
23 | --force force configuration | |
24 | EOF | |
25 | exit 0 | |
26 | } | |
27 | ||
28 | version=0.3 | |
29 | confdir=/etc/t1lib | |
30 | conffile=$confdir/t1lib.config | |
31 | dbase=$confdir/FontDatabase | |
32 | temp=$confdir/FontDatabase.tmp | |
33 | force=0 | |
34 | fontdirs="/usr/share/fonts/Type1" | |
35 | ||
36 | while [ $# -ne 0 ] | |
37 | do | |
38 | case "$1" in | |
39 | -v|--version) | |
40 | echo "`basename $0` version $version" | |
41 | exit 0 | |
42 | ;; | |
43 | -h|--help) | |
44 | usage | |
45 | ;; | |
46 | --force) | |
47 | force=1 | |
48 | ;; | |
49 | *) | |
50 | pat=${1%/} | |
df1e8eac | 51 | if ! grep -q -x $pat <<EOF 2>/dev/null |
d470d1c2 TP |
52 | $fontdirs |
53 | EOF | |
54 | then | |
55 | fontdirs="$fontdirs $1" | |
56 | fi | |
57 | ;; | |
58 | esac | |
59 | shift | |
60 | done | |
61 | ||
62 | # We presume that if the database exists, then so does the | |
63 | # configuration file. Hopefully this won't break anything. | |
64 | ||
65 | if [ $force -ne 1 ] && [ -e $dbase ]; then | |
66 | echo "Configuration and font database files already exist." | |
67 | echo "Run /usr/sbin/t1libconfig --force to rebuild them." | |
68 | exit 0 | |
69 | fi | |
70 | ||
71 | fontpath="" | |
72 | afmpath="" | |
73 | mkdir -p $confdir || true | |
74 | echo -n "Searching for Type 1 fonts and AFM files..." | |
75 | ||
76 | for i in $fontdirs | |
77 | do | |
78 | if [ ! -d $i ] || [ "`echo $i/*.pf[ab]`" = "$i/*.pf[ab]" ]; then | |
79 | continue | |
80 | fi | |
81 | fontpath="$fontpath$i:" | |
82 | ||
83 | for j in `find $i -name "*.afm" -type f -mindepth 1 -maxdepth 2 -printf "%h\n" | sort | uniq`; do | |
84 | afmpath="$afmpath$j:" | |
85 | done | |
86 | ||
87 | # get a listing of all the fonts in each dir | |
88 | find $i -name "*.pf[ab]" -type f -maxdepth 1 -printf '%f\n' >> $temp | |
89 | done | |
90 | fontpath=${fontpath%:} | |
91 | afmpath=${afmpath%:} | |
92 | ||
93 | if [ -z "$fontpath" ]; then | |
94 | cat <<EOF | |
95 | ||
96 | ||
97 | No Type 1 fonts were found in the expected locations. | |
98 | If you want t1lib to be aware of your fonts, you should run | |
99 | $0 with the names of your local font directories as | |
100 | arguments, or you should edit the $dbase file manually. | |
101 | See the FontDatabase(5) manual page for more information. | |
102 | ||
103 | EOF | |
104 | rm -f $temp | |
105 | else | |
106 | echo " done." | |
107 | echo -n "Building font database..." | |
108 | fontcount=`cat $temp | wc -l || true` | |
109 | echo $fontcount > $dbase | |
110 | cat $temp >> $dbase | |
111 | rm -f $temp | |
112 | echo " done." | |
113 | fi | |
114 | ||
115 | # now set the paths in the config file | |
116 | cat <<EOF >$conffile | |
117 | t1lib.config - global configuration file for t1lib. | |
118 | It was created automatically on `date` | |
119 | by the t1libconfig script. | |
120 | ||
121 | Run $0 --force to rebuild it. | |
122 | ||
123 | ENCODING=$confdir/enc | |
124 | AFM=$afmpath | |
125 | TYPE1=$fontpath | |
126 | FONTDATABASE=$dbase | |
127 | EOF | |
128 | ||
129 | exit 0 |