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
|
@rem = '--*-Perl-*--
@echo off
perl -x -S %0 %*
goto endofperl
@rem ';
#!/usr/bin/env perl
#line 8
$^W=1;
## getnonfreefonts
## Copyright 2006 Reinhard Kotucha <reinhard.kotucha@web.de>
#
# This work may be distributed and/or modified under the
# conditions of the LaTeX Project Public License, either version 1.3
# of this license or (at your option) any later version.
# The latest version of this license is in
# http://www.latex-project.org/lppl.txt
#
# The current maintainer is Reinhard Kotucha.
my $TL_version='2006';
my $getfont_url="ftp://tug.org/tex/getnonfreefonts/getfont2006";
use File::Copy;
use Getopt::Long;
$Getopt::Long::autoabbrev=0;
$opt_lsfonts=0;
$opt_force=0;
sub usage {
print <<'EOF';
Usage:
getnonfreefonts[-sys] [-a|--all] [-f|--force] [-l|--lsfonts]
[-v|--verbose] [font1] [font2] ...
getnonfreefonts installs fonts in $TEXMFHOME.
getnonfreefonts-sys installs fonts in $TEXMFLOCAL.
Options:
-a|--all Install all fonts.
-f|--force Install fonts even if they are installed already.
-h|--help Print this message.
-l|--lsfonts List all fonts available.
-v|--verbose Be more verbose.
EOF
;
}
unless (@ARGV) {
usage;
exit 1;
}
GetOptions
"all|a",
"debug|d",
"force|f",
"help|h",
"lsfonts|l",
"verbose|v",
"sys";
$^W=1 if $opt_debug;
my $sys=($0=~/-sys$/)? 1:0;
$sys=1 if $opt_sys;
@allpackages=@ARGV;
sub message {
my $message=shift;
if ($message=~/^\[/) {
print "$message\n";
} else {
printf "%-60s", $message;
}
}
sub expand_var {
my $var=shift;
if (-d "/usr/bin") {
open KPSEWHICH, 'kpsewhich --expand-var=\$' . "$var |";
} else {
open KPSEWHICH, 'kpsewhich --expand-var=$' . "$var |";
}
while (<KPSEWHICH>) {
chop;
return $_;
}
close KPSEWHICH;
}
if ($sys) {
$INSTALLROOT=expand_var 'TEXMFLOCAL';
} else {
$INSTALLROOT=expand_var 'TEXMFHOME';
}
# get TMP|TEMP|TMPDIR environment variable
if (defined $ENV{'TMP'}) {
$systmp="$ENV{'TMP'}";
} elsif (defined $ENV{'TEMP'}) {
$systmp="$ENV{'TEMP'}";
} elsif (defined $ENV{'TMPDIR'}) {
$systmp="$ENV{'SYSTMP'}";
} else {
$systmp="/tmp";
}
# Windows usually uses backslashes though forward slashes are probably
# allowed. Perl always needs forward slashes.
# We convert backslashes to forward slashes if it looks like a Windows
# directory.
$systmp=~s/\\/\//g if ($systmp=~/^.:\\/); # c:\abc\def
$systmp=~s/\\/\//g if ($systmp=~/^\\\\/); # \\abc\def
die "! ERROR: The directory '$systmp' doesn't exist.\n"
unless (-d "$systmp");
die "! ERROR: The directory '$systmp' is not writable.\n"
unless (-w "$systmp");
$INSTALLROOT=~s/\\/\//g if ($INSTALLROOT=~/^.:\\/); # c:\abc\def
$INSTALLROOT=~s/\\/\//g if ($INSTALLROOT=~/^\\\\/); # \\abc\def
die "! ERROR: The directory '$INSTALLROOT' is not writable.\n"
unless (-w "$INSTALLROOT");
if ($opt_help) {
usage;
print <<"ENDUSAGE";
Directories:
temporary: '$systmp/getfont-<PID>'
install: '$INSTALLROOT'
ENDUSAGE
exit 0;
}
my $tmpdir="$systmp/getfont-$$";
mkdir "$tmpdir" or die "! ERROR: Can't mkdir '$tmpdir'.";
chdir "$tmpdir" or die "! ERROR: Can't cd '$tmpdir'.";
sub remove_tmpdir {
chdir "$systmp" or die "! ERROR: Can't cd '$systmp'.\n";
opendir TMPDIR, "$tmpdir"
or print "! ERROR: Can't read directory '$tmpdir'.\n";
@alltmps=readdir TMPDIR;
closedir TMPDIR;
foreach $file (@alltmps) {
next if $file=~/^\./;
unlink "$tmpdir/$file";
}
rmdir "$tmpdir" or die "! ERROR: Can't remove directory '$tmpdir'.\n";
}
# Signal handlers for UNIX, maybe ignored by Windows.
$SIG{INT} =\&remove_tmpdir;
$SIG{QUIT}=\&remove_tmpdir;
$SIG{BUS} =\&remove_tmpdir;
$SIG{PIPE}=\&remove_tmpdir;
$SIG{TERM}=\&remove_tmpdir;
$SIG{ABRT}=\&remove_tmpdir;
$SIG{SEGV}=\&remove_tmpdir;
system ('wget', "$getfont_url");
my @getfont=('perl', "./getfont$TL_version", '--getnonfreefonts');
push @getfont, "--installroot=$INSTALLROOT";
push @getfont, '--lsfonts' if $opt_lsfonts;
push @getfont, '--force' if $opt_force;
push @getfont, '--verbose' if $opt_verbose;
push @getfont, '--sys' if $sys;
push @getfont, '--all' if $opt_all;
push @getfont, @allpackages;
system @getfont;
my $exit_code=$?;
my $exit_status=int($exit_code/256);
if ($exit_status==2) {
print "\n";
system 'texhash', "$INSTALLROOT";
$updmap_command=($sys)? 'updmap-sys':'updmap';
@updmap=("$updmap_command");
push @updmap, '--quiet' unless $opt_verbose;
message "\nUpdating map files ($updmap_command)...";
system @updmap;
message $?? '[failed]':'[done]';
}
remove_tmpdir;
__END__
:endofperl
|