blob: 1b2944e93851fa489a1a8cb385c398562da998da (
plain)
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
|
#!/usr/bin/env perl
# For testing, edit $ro_dir and $luaprog as needed;
# $ro_dir should be a read-only directory and
# $luaprog should be a working lua executable but not texlua.
# Under Unix/Linux, just test whether loading of win32 modules is skipped.
#!/usr/bin/env perl
use strict;
BEGIN {
$^W = 1;
my $me=$0;
$me=~s!\\!/!g if $^O=~/^MSWin(32|64)$/i;
if ($me=~m!/!) {
# wingoo-demo now in a subsubdirectory:
($::installerdir=$me)=~s!(.*)/[^/]+/[^/]+/[^/]*$!$1!;
} else {
# This shouldn't occur if called from batchfile
$::installerdir='./../..';
}
@INC = ("$::installerdir/tlpkg/installer/perllib") if ($^O=~/^MSWin(32|64)$/i);
unshift (@INC, "$::installerdir/tlpkg");
}
use TeXLive::TLUtils qw( get_system_tmpdir );
use TeXLive::TLWinGoo qw(
&admin
&non_admin
&admin_again
&dir_writable
®_country
&get_system_path
&get_user_path
&get_system_env
&get_user_env
&expand_string
&win_which_dir
&global_tmpdir
&add_texbindir_to_path
&remove_texbindirs_from_path
®ister_script_type
&unregister_script_type
&broadcast_env
&update_assocs
&wg_error
); # safe under Unix/Linux!
my $ro_dir = "z:/aps";
my $luaprog = "x:/utils0/lua.exe";
$::LOGLEVELTERMINAL=$::LOG_DDDEBUG;
$::LOGLEVELFILE=$::LOG_ZERO;
sub maybenot {
my $bool = shift;
return $bool ? " is " : " is not ";
}
# two uses:
# - is the parent directory writable?
# - is the script interpreted by lua or by texlua?
sub create_file {
my $name = shift;
return if -e $name;
eval {
open DUMMY, ">".$name;
print DUMMY 's = tostring(0.0000001)'; # lua: 1e-7; texlua: 0
print DUMMY ('print("0.0000001 becomes " .. s)');
close DUMMY;
} ;
}
sub print_search_paths {
print "System path: ".get_system_path()."\n";
print "User path: ".get_user_path()."\n";
}
sub print_lua_out {
my $luatest = expand_string( $ENV{'TEMP'} ) . "/testlua";
my $luatestlua = $luatest . ".texlua";
unlink $luatestlua if -e $luatestlua;
create_file( $luatestlua );
my $cmd = 'set PATHEXT=%PATHEXT%;.TEXLUA & "'.$luatest.'"';
$cmd =~ s/\//\\/g;
print "Lua[tex] result: ".`$cmd`."\n";
unlink $luatestlua;
}
sub print_assoc_cmd {
my $ext = shift;
my $cmdout = `assoc $ext`;
chomp $cmdout if $cmdout;
if (!$cmdout) { print "Extension unknown says assoc\n"; return; }
my $ftype = $cmdout;
$ftype =~ s/.*=//;
if (!$ftype) { print "Extension unknown says assoc\n"; return; }
$cmdout = `ftype $ftype`;
if (!$cmdout) { print "Filetype unknown says ftype\n"; return; }
$cmdout =~ s/.*=//;
print( $ext.' command is: '.$cmdout."\n" );
}
sub pause {
my $mess = shift;
print( $mess."\nType any key..." );
read STDIN,my $dummy, 1;
}
### end of subs ###
my $real_admin = admin();
print( "\nGENERAL; ALSO UNIX\n" );
print ( "\nINC\n" . (join "\n", @INC) . "\n\n");
# admin
if (admin()) {
print "Admin or not_on_Windows\n";
} else {
print "Not admin\n";
}
# global_tmpdir
print "\nGlobal tempdir: " . global_tmpdir()."\n";
if ($^O !~ /^MSWin(32|64)$/i) {
print "Not Windows; bailing out...\n";
exit;
}
### end of non-windows
my @winversion = Win32::GetOSVersion();
print "Windows version: " . $winversion[1] . "\n";
# country
print "Country: " . reg_country() . "\n";
# dir_writable
my $wr_dir = $ENV{'USERPROFILE'};
$wr_dir =~ s/\\/\//g;
mkdir $wr_dir unless -e $wr_dir;
print $wr_dir . maybenot(dir_writable($wr_dir)) . "writable\n";
print $ro_dir . maybenot(dir_writable($ro_dir)) . "writable\n";
# expand_string
print( "\nExpansion\n" );
print expand_string("pre\\%systemROOT%\\post")."\n";
# win_which_dir
print( "\nFinding an executable\n" );
print "cmd.exe found in " . win_which_dir("cmd.exe") . "\n";
my $system_tmpdir=get_system_tmpdir();
print( "\n\nHKCU and HKLM\n\n" );
my ($wr_dir1, $wr_dir2);
while (1) { # running this first as admin (if possible) and then as non-admin
print ((admin() ? "Is" : "Not") . " an admin\n");
# adding and removing texbindir
print( "\ntexbindir on searchpath:\n" );
$wr_dir1 = $wr_dir . "/tex1";
mkdir $wr_dir1 unless -e $wr_dir1;
create_file( $wr_dir1."/tex.exe" );
add_texbindir_to_path($wr_dir1);
print( "Take 1\n" );
print_search_paths();
print "tex.exe found in " . win_which_dir("tex.exe") . "\n";
$wr_dir2 = $wr_dir . "/tex2";
mkdir $wr_dir2 unless -e $wr_dir2;
create_file( $wr_dir2."/tex.exe" );
add_texbindir_to_path($wr_dir2);
print( "Take 2\n" );
print_search_paths();
print "tex.exe found in " . win_which_dir("tex.exe") . "\n";
print( "Mopping up...\n" );
remove_texbindirs_from_path();
print_search_paths();
# adding a filetype
print( "\nRegistering and unregistering filetypes\n" );
my $testlua = admin() ? $::installerdir."/bin/win32/texlua.exe" : $luaprog;
update_assocs(); # just to be sure
print_assoc_cmd( '.texlua' );
print_lua_out();
register_script_type(".texlua", $testlua );
update_assocs();
print_assoc_cmd( '.texlua' );
print_lua_out();
print( "Now unregister\n" );
unregister_script_type(".texlua");
update_assocs();
print_assoc_cmd( '.texlua' );
print_lua_out();
print( "Now re-register (not shown)\n" );
register_script_type(".texlua", $testlua );
update_assocs();
# broadcast environment changes
broadcast_env();
pause( maybenot(admin())." admin; check environment in new dosbox\n\n" );
if (admin()) {
non_admin();
next;
} elsif ($winversion[1]>=6) { last; }
#vista: don't try this
# the problem case: no admin, but TeX on system path
print( "\nNon-admin path problem\n" );
my $fn = expand_string("%windir%")."/TEX.EXE";
$fn =~ s/\\/\//g;
create_file($fn); # a tex.exe on the system path!
add_texbindir_to_path(expand_string($wr_dir2));
my @wge = wg_error();
if (@wge) {
print $wge[1]."\n";
}
print( "Cannot remove tex from system searchpath\n" );
print_search_paths();
print "Wrong tex.exe found in " . win_which_dir("tex.exe") . "\n";
unlink $fn;
remove_texbindirs_from_path();
# broadcast environment changes
broadcast_env();
pause( "Non-admin: check environment in new dosbox" );
if (!admin()) { last; }
}
rmdir $wr_dir1 if unlink $wr_dir1.'/tex.exe';
rmdir $wr_dir2 if unlink $wr_dir2.'/tex.exe';
print( "Dummy texs removed from path\n");
admin_again() if $real_admin;
unregister_script_type(".texlua");
update_assocs();
broadcast_env();
print_assoc_cmd( '.texlua' );
|