1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
|
#!/bin/sh -
#set -x
PATH=/usr/local/bin:/usr/local/sbin:/usr/bin
export PATH
allan=0
directory=./
vendor=arkandis
cfrtop=$(xdg-user-dir DOCUMENTS)/src/fonts/_cfr
existencs=0
docdir="doc"
afmdir="fonts/afm"
encdir="fonts/enc"
mapdir="fonts/map"
tfmdir="fonts/tfm"
truetypedir="fonts/truetype"
type1dir="fonts/type1"
vfdir="fonts/vf"
sourcedir="source"
texdir="tex"
usage="Usage: $0 [OPTION] [FILES]
Prepare a flattened file hierarchy and install fonts and support files in it in preparation for the creation of an archive for upload to CTAN.
Options:
-h --help print this message and exit
-a --adf file listing ADF files [after cd: ./adf or ../cfr/adf or hard-coded list]
-c --directory directory to switch to [current working directory]
-d --derived file listing derived files [after cd: ./der or ../cfr/der or hard-coded list]
-f --font specify font package name [truncated name of directory]
-m --manual specify manual name [font package name w/ or w/o adf appended]
-n --nonderived file listing nonderived files [after cd: ./nonder or ../cfr/nonder or hard-coded list]
-o --original file listing font vendor's files [after cd: ./ovend or ../cfr/ovend or hard-coded list]
-t --tool primary creation tool [after cd: guess fontinst or afm2pl or empty]
-v --vendor specify font vendor name [arkandis]
If no files are specified, a list is constructed from the lists of derived, nonderived and ADF or other original vendor files."
error () {
echo "$@" 1>&2
allan=$((allan+1))
usage_and_exit $allan
}
usage () {
printf %b "$usage\n"
}
usage_and_exit () {
usage
exit $1
}
ctaninst () {
ctaninstallan=0
while [ $# != 0 ]
do
if [ -e "$1" ]
then
grep -w "$1" $nonder > /dev/null
if [ $? == 0 ]
then
if [ -e "../cfr/$1" ]
then
diff "$1" "../cfr/$1" > /dev/null
if [ $? != 0 ]
then
printf %b "A non-duplicate copy of $1 already exists in ../cfr.\nUsing ../cfr.$$ for new versions.\nPlease examine manually.\n"
mkdir -p ../cfr.$$
cp -pR "$1" ../cfr.$$/
fi
else
cp -pR "$1" ../cfr/
fi
if [ -e "../cfr.$$/$1" ]
then
diff "./$1" "../cfr.$$/$1" > /dev/null
if [ $? != 0 ]
then
printf %b "A problem occurred when copying $1. This file will not be installed.\n"
problem=1
else
problem=0
fi
else
diff "./$1" "../cfr/$1" > /dev/null
if [ $? != 0 ]
then
printf %b "A problem occurred when copying $1. This file will not be installed.\n"
problem=1
else
problem=0
fi
fi
if [ $problem != 0 ]
then
allan=$((allan+1))
ctaninstallan=1
shift
continue
fi
else
grep -w "$1" $der > /dev/null
if [ $? != 0 ]
then
grep -w "$1" $adf $ovend > /dev/null
if [ $? != 0 ]
then
printf %b "$1 is not listed as a derived, non-derived or ADF/original vendor's file and will be ignored.\n"
allan=$((allan+1))
ctaninstallan=1
shift
continue
fi
fi
fi
ctansort "$1"
if [ $? != 0 ]
then
printf %b "A problem occurred sorting $1.\n"
allan=$((allan+1))
ctaninstallan=1
fi
else
printf %b "Cannot find $1. Skipping.\n"
allan=$((allan+1))
fi
shift
done
return $ctaninstallan
}
mvsubs () {
mvsubsallan=0
filestocopy=""
filestomove=""
while [ $# -gt 1 ]
do
file "$1" | grep "symbolic link" > /dev/null
if [ $? == 0 ]
then
filestocopy="$filestocopy $1"
else
filestomove="$filestomove $1"
fi
shift
done
if [ "$filestomove" != "" ]
then
mv $filestomove "$1"
if [ $? != 0 ]
then
printf %b "There was a problem moving $filestomove to $1.\n"
allan=$((allan+1))
mvsubsallan=1
fi
fi
if [ "$filestocopy" != "" ]
then
cp -p $filestocopy "$1"
if [ $? != 0 ]
then
printf %b "There was a problem copying $filestocopy to $1.\n"
allan=$((allan+1))
mvsubsallan=1
fi
fi
return $mvsubsallan
}
ctansort () {
if [ $# != 1 ]
then
printf %b "ctansort takes exactly one argument.\n"
return 1
else
if [ "$@" = "Makefile" ] || [ "$@" = "com" ] || [ "$@" = "cfr.gwneud.cyhoeddus" ]
then
mvsubs "$@" "$sourcedir/"
return $?
fi
j="${@##*\-}"
if [ "$j" = "drv.tex" ] || [ "$j" = "map.tex" ]
then
mvsubs "$@" "$sourcedir/"
return $?
fi
j="${@##*\.}"
case "$j" in
"afm")
mvsubs "$@" "$afmdir/"
return $?
;;
"enc")
mvsubs "$@" "$encdir/"
return $?
;;
"map")
mvsubs "$@" "$mapdir/"
return $?
;;
"tfm")
mvsubs "$@" "$tfmdir/"
return $?
;;
"pfb" | "pfm")
mvsubs "$@" "$type1dir/"
return $?
;;
"ttf")
mvsubs "$@" "$truetypedir/"
return $?
;;
"vf")
mvsubs "$@" "$vfdir/"
return $?
;;
"fd" | "sty")
mvsubs "$@" "$texdir/"
return $?
;;
"etx" | "lig" | "nam" | "pe" | "sfd" | "otf")
mvsubs "$@" "$sourcedir/"
return $?
;;
"txt")
mvsubs "$@" "$docdir/"
return $?
;;
*)
;;
esac
j="${@%\.*}"
case "$j" in
COPYING | NOTICE | README | manifest | "$manual")
mvsubs "$@" "$docdir/"
return $?
;;
*)
;;
esac
j="${@%%\-*}"
case "$j" in
reglyph | reset | build)
mvsubs "$@" "$sourcedir/"
return $?
;;
*)
;;
esac
printf %b "ctansort does not recognise $@. This file will not be installed.\n"
return 1
fi
}
trymkdir () {
while [ $# != 0 ]
do
mkdir -p "$1"
if [ $? != 0 ]
then
error Could not create "$1".
fi
shift
done
return 0
}
tempargs=$(getopt -o a:c:d:f:hm:n:o:t:v: --long adf:,directory:,derived:,font:,help,manual:,nonderived:,original:,tool:,vendor: -- "$@")
if [ $? != 0 ];
then
usage_and_exit
fi
eval set -- "$tempargs"
while true
do
case "$1"
in
-a | --adf)
if [ -f "$2" ]
then
adf="$2"
else
error "$2" is not a regular file.
fi
shift;
shift;;
-c | --directory)
directory="$2";
shift;
shift;;
-d | --der | --derive | --derived)
if [ -f "$2" ]
then
der="$2"
else
error "$2" is not a regular file.
fi
shift;
shift;;
-f | --font)
font="$2"
shift;
shift;;
-h | --help)
usage;
exit $allan;;
-m | --manual)
manual="${2%%\.*}";
shift;
shift;;
-n | --nonder | --nonderive | --nonderived)
if [ -f "$2" ]
then
nonder="$2"
else
error "$2" is not a regular file.
fi
shift;
shift;;
-o | --orig | --original)
if [ -f "$2" ]
then
ovend="$2"
else
error "$2" is not a regular file.
fi
shift;
shift;;
-t | --tool)
tool="$2"
shift;
shift;;
-v | --vendor)
vendor="$2";
shift;
shift;;
--)
shift;
break;;
*)
error Unrecognised option "$1".
esac
done
args="$@"
cd "$directory"
if [ $? != 0 ]
then
error Could not switch to "$directory".
fi
if [ "$font" = "" ]
then
thisdir=$(gbasename $(pwd))
font=${thisdir%%\-*}
echo Setting font directory to "$font".
fi
if [ "$manual" = "" ]
then
if [ -f "./${font}.tex" ]
then
manual="${font}"
echo Setting manual to "$manual".
elif [ -f "./${font}adf.tex" ]
then
manual="${font}adf"
echo Setting manual to "$manual".
else
printf %b "Warning! No manual found.\n"
allan=$((allan+1))
fi
fi
if [ "$(ls manifest* 2> /dev/null)" = "" ]
then
printf %b "Creating manifest.\n"
touch manifest.txt
if [ -f $cfrtop/manifest.top ]
then
cat $cfrtop/manifest.top >> manifest.txt
createmanifest=1
else
printf %b "Cannot create manifest.txt. No manifest.top found.\n"
rm manifest.txt
allan=$((allan+1))
createmanifest=0
fi
else
createmanifest=0
fi
if [ "$tool" = "" ]
then
if [ "$(ls *-drv.tex 2> /dev/null)" != "" ] || [ "$(ls *-map.tex 2> /dev/null)" != "" ]
then
tool="fontinst"
printf %b "Guessing you used fontinst for this one.\n"
elif [ "$(ls *.lig 2> /dev/null)" != "" ] || [ "$(ls Makefile 2> /dev/null)" != "" ] || [ "$(ls com 2> /dev/null)" != "" ]
then
tool="afm2pl"
printf %b "Guessing you used afm2pl for this one.\n"
else
printf %b "Cannot guess the tool used. Please specify.\n"
allan=$((allan+1))
fi
fi
if [ "$der" = "" ]
then
if [ -e "./der" ]
then
der=./der
elif [ -e "../cfr/der" ]
then
der=../cfr/der
else
printf %b "Using default list for derived files.\nPlease check ./der.\n"
if [ "$tool" = "fontinst" ]
then
ls *.enc *.tfm *.vf *.fd *.map >> ./der 2> /dev/null
elif [ "$tool" = "afm2pl" ]
then
ls *.tfm *.vf *.map >> ./der 2> /dev/null
else
printf %b "Creation tool is either unrecognised or unguessable. If the former, please populate der manually - the file I create will certainly be radically incomplete. If the latter, please specify the tool.\n"
fi
if [ -f "$manual.pdf" ]
then
echo "$manual.pdf" >> ./der
fi
der=./der
fi
fi
if [ "$nonder" = "" ]
then
if [ -e "./nonder" ]
then
nonder=./nonder
elif [ -e "../cfr/nonder" ]
then
nonder=../cfr/nonder
else
printf %b "Using default list for non-derived files.\nPlease check ./nonder.\n"
if [ "$tool" = "fontinst" ]
then
ls *[^~]*.etx reglyph*.tex reset*.mtx build*.mtx *-drv.tex *-drv.map >> ./nonder 2> /dev/null
elif [ "$tool" = "afm2pl" ]
then
ls *[^~]*.enc *[^~]*.fd *[^~]*.lig Makefile com >> ./nonder 2> /dev/null
else
printf %b "Creation tool is either unrecognised or unguessable. If the former, please populate nonder manually - the file I create will certainly be radically incomplete. If the latter, please specify the tool.\n"
fi
ls *[^~]*.nam *.pe manifest* README *.sty >> ./nonder 2> /dev/null
if [ -f "$manual.tex" ]
then
echo "$manual.tex" >> ./nonder
fi
nonder=./nonder
fi
fi
if [ "$adf" = "" ] && [ "$ovend" = "" ]
then
if [ -e "./adf" ]
then
adf=./adf
elif [ -e "../cfr/adf" ]
then
adf=../cfr/adf
elif [ -e "./ovend" ]
then
ovend=./ovend
elif [ -e "../cfr/ovend" ]
then
ovend=../cfr/ovend
elif [ "$vendor" = "arkandis" ]
then
printf %b "Using default list for ADF files.\nPlease check ./adf.\n"
ls COPYING* NOTICE* *.afm *.pfb *.pfm *.otf *.sfd >> ./adf 2> /dev/null
adf=./adf
else
printf %b "Using default list for original vendor's files.\nPlease check ./ovend.\n"
ls COPYING* NOTICE* [A-Z][A-Z\-]*[A-Z].txt *.afm *.pfb *.pfm *.otf *.ttf *.sfd >> ./ovend 2> /dev/null
ovend=./ovend
fi
fi
if [ $createmanifest == 1 ]
then
grep manifest.txt $nonder > /dev/null
if [ $? != 0 ]
then
printf %b "Adding manifest to list of nonderived files.\n"
echo manifest.txt >> $nonder
fi
cat $nonder >> manifest.txt
if [ -f $cfrtop/manifest.mid ]
then
cat $cfrtop/manifest.mid >> manifest.txt
else
printf %b "\nDerived files:\n" >> manifest.txt
fi
cat $der >> manifest.txt
fi
if [ $# == 0 ]
then
files=$(cat $der $nonder $adf $ovend)
if [ "$files" = "" ]
then
error Could not determine any files to install.
fi
else
files=$args
fi
trymkdir $docdir $texdir $afmdir $mapdir $tfmdir ../cfr
if [ "$(echo "$files" | grep '\.pfb' 2> /dev/null)" != "" ]
then
trymkdir $type1dir
fi
if [ "$(echo "$files" | grep '\.ttf' 2> /dev/null)" != "" ]
then
trymkdir $truetypedir
fi
for i in "\.etx" "\-drv\.tex" "\-map\.tex" "reglyph.*\.tex" "reset.*\.mtx" "build*\.mtx" "Makefile" "^com$" "^com " " com$" " com " "\.lig" "\.nam" "\.pe" "\.sfd" "\.otf"
do
if [ "$(echo "$files" | grep "$i" 2> /dev/null)" != "" ]
then
trymkdir $sourcedir
break
fi
done
if [ "$(echo "$files" | grep '\.enc' 2> /dev/null)" != "" ]
then
existencs=1
trymkdir $encdir
fi
if [ "$(echo "$files" | grep '\.vf' 2> /dev/null)" != "" ]
then
trymkdir $vfdir
fi
ctaninst $@ $files
if [ -e "$docdir/README" ]
then
ln -s "$docdir/"README ./
else
printf %b "Warning! No README found.\n"
allan=$((allan+1))
fi
if [ $existencs==1 ]
then
printf %b "Did you uniquify the .enc files?\nDid you add the .enc files to finstmsc.rc?\n"
fi
exit $allan
# vim: set nospell:
|