/
tlmgr.pl
executable file
·10244 lines (9031 loc) · 339 KB
/
tlmgr.pl
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
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env perl
# $Id$
#
# Copyright 2008-2021 Norbert Preining
# This file is licensed under the GNU General Public License version 2
# or any later version.
my $svnrev = '$Revision$';
my $datrev = '$Date$';
my $tlmgrrevision;
my $tlmgrversion;
my $prg;
my $bindir;
if ($svnrev =~ m/: ([0-9]+) /) {
$tlmgrrevision = $1;
} else {
$tlmgrrevision = "unknown";
}
$datrev =~ s/^.*Date: //;
$datrev =~ s/ \(.*$//;
$tlmgrversion = "$tlmgrrevision ($datrev)";
our $Master;
our $loadmediasrcerror;
our $packagelogfile;
our $packagelogged;
our $commandslogged;
our $commandlogfile;
our $tlmgr_config_file;
our $pinfile;
our $action; # for the pod2usage -sections call
our %opts;
our $allowed_verify_args_regex = qr/^(none|main|all)$/i;
END {
if ($opts{"pause"}) {
print "Press Enter to exit the program.\n";
<STDIN>;
}
}
BEGIN {
$^W = 1;
# make subprograms (including kpsewhich) have the right path:
my $kpsewhichname;
if ($^O =~ /^MSWin/i) {
# on w32 $0 and __FILE__ point directly to tlmgr.pl; they can be relative
$Master = __FILE__;
$Master =~ s!\\!/!g;
$Master =~ s![^/]*$!../../..!
unless ($Master =~ s!/texmf-dist/scripts/texlive/tlmgr\.pl$!!i);
$bindir = "$Master/bin/win32";
$kpsewhichname = "kpsewhich.exe";
# path already set by wrapper batchfile
} else {
$Master = __FILE__;
$Master =~ s,/*[^/]*$,,;
$bindir = $Master;
$Master = "$Master/../..";
# make subprograms (including kpsewhich) have the right path:
$ENV{"PATH"} = "$bindir:$ENV{PATH}";
$kpsewhichname = "kpsewhich";
}
if (-r "$bindir/$kpsewhichname") {
# if not in bootstrapping mode => kpsewhich exists, so use it to get $Master
chomp($Master = `kpsewhich -var-value=SELFAUTOPARENT`);
}
# if we have no directory in which to find our modules,
# no point in going on.
if (! $Master) {
die ("Could not determine directory of tlmgr executable, "
. "maybe shared library woes?\nCheck for error messages above");
}
$::installerdir = $Master; # for config.guess et al., see TLUtils.pm
# make Perl find our packages first:
unshift (@INC, "$Master/tlpkg");
unshift (@INC, "$Master/texmf-dist/scripts/texlive");
}
use Cwd qw/abs_path/;
use File::Find;
use File::Spec;
use Pod::Usage;
use Getopt::Long qw(:config no_autoabbrev permute);
use strict;
use TeXLive::TLConfig;
use TeXLive::TLPDB;
use TeXLive::TLPOBJ;
use TeXLive::TLUtils;
use TeXLive::TLWinGoo;
use TeXLive::TLDownload;
use TeXLive::TLConfFile;
use TeXLive::TLCrypto;
TeXLive::TLUtils->import(qw(member info give_ctan_mirror win32 dirname
mkdirhier copy debug tlcmp repository_to_array));
use TeXLive::TLPaper;
#
# set up $prg for warning messages
$prg = TeXLive::TLUtils::basename($0);
# for usage in various Perl modules
$::prg = $prg;
binmode(STDOUT, ":utf8");
binmode(STDERR, ":utf8");
our %config; # hash of config settings from config file
our $remotetlpdb;
our $location; # location from which the new packages come
our $localtlpdb; # local installation which we are munging
# flags for machine-readable form
our $FLAG_REMOVE = "d";
our $FLAG_FORCIBLE_REMOVED = "f";
our $FLAG_UPDATE = "u";
our $FLAG_REVERSED_UPDATE = "r";
our $FLAG_AUTOINSTALL = "a";
our $FLAG_INSTALL = "i";
our $FLAG_REINSTALL = "I";
# keep in sync with install-tl.
our $common_fmtutil_args =
"--no-error-if-no-engine=$TeXLive::TLConfig::PartialEngineSupport";
# option variables
$::gui_mode = 0;
$::machinereadable = 0;
my %action_specification = (
'_include_tlpobj' => {
"run-post" => 0,
"function" => \&action_include_tlpobj
},
"backup" => {
"options" => {
"all" => 1,
"backupdir" => "=s",
"clean" => ":-99",
"dry-run|n" => 1
},
"run-post" => 1,
"function" => \&action_backup
},
"candidates" => {
"run-post" => 0,
"function" => \&action_candidates
},
"check" => {
"options" => { "use-svn" => 1 },
"run-post" => 1,
"function" => \&action_check
},
"conf" => {
"options" => {
"conffile" => "=s",
"delete" => 1,
},
"run-post" => 0,
"function" => \&action_conf
},
"dump-tlpdb" => {
"options" => { local => 1, remote => 1 },
"run-post" => 0,
"function" => \&action_dumptlpdb
},
"generate" => {
"options" => {
"dest" => "=s",
"localcfg" => "=s",
"rebuild-sys" => 1
},
"run-post" => 1,
"function" => \&action_generate
},
"get-mirror" => {
"run-post" => 0,
"function" => \&action_get_mirror
},
"gui" => {
"options" => {
"load" => 1,
# Tk::CmdLine options
"background" => "=s",
"class" => "=s",
"display" => "=s",
"font" => "=s",
"foreground" => "=s",
"geometry" => "=s",
"iconic" => 1,
"motif" => 1,
"name" => "=s",
"screen" => "=s",
"synchronous" => 1,
"title" => "=s",
"xrm" => "=s",
},
"run-post" => 1,
"function" => \&action_gui
},
"info" => {
"options" => {
"data" => "=s",
"all" => 1,
"list" => 1,
"only-installed" => 1,
"only-remote" => 1
},
"run-post" => 0,
"function" => \&action_info
},
"init-usertree" => {
"run-post" => 0,
"function" => \&action_init_usertree
},
"install" => {
"options" => {
"dry-run|n" => 1,
"file" => 1,
"force" => 1,
"no-depends" => 1,
"no-depends-at-all" => 1,
"reinstall" => 1,
"with-doc" => 1,
"with-src" => 1,
},
"run-post" => 1,
"function" => \&action_install
},
"key" => {
"run-post" => 0,
"function" => \&action_key
},
"option" => {
"run-post" => 1,
"function" => \&action_option
},
"paper" => {
"options" => { "list" => 1 },
"run-post" => 1,
"function" => \&action_paper
},
"path" => {
"options" => { "w32mode" => "=s" },
"run-post" => 0,
"function" => \&action_path
},
"pinning" => {
"options" => { "all" => 1 },
"run-post" => 1,
"function" => \&action_pinning
},
"platform" => {
"options" => { "dry-run|n" => 1 },
"run-post" => 1,
"function" => \&action_platform
},
"postaction" => {
"options" => {
"all" => 1,
"fileassocmode" => "=i",
"w32mode" => "=s",
},
"run-post" => 0,
"function" => \&action_postaction
},
"recreate-tlpdb" => {
"options" => { "platform|arch" => "=s" },
"run-post" => 0,
"function" => \&action_recreate_tlpdb
},
"remove" => {
"options" => {
"all" => 1,
"backup" => 1,
"backupdir" => "=s",
"dry-run|n" => 1,
"force" => 1,
"no-depends" => 1,
"no-depends-at-all" => 1,
},
"run-post" => 1,
"function" => \&action_remove
},
repository => {
"options" => { "with-platforms" => 1 },
"run-post" => 1,
"function" => \&action_repository
},
"restore" => {
"options" => {
"all" => 1,
"backupdir" => "=s",
"dry-run|n" => 1,
"force" => 1
},
"run-post" => 1,
"function" => \&action_restore
},
"search" => {
"options" => {
"all" => 1,
"file" => 1,
"global" => 1,
"word" => 1,
},
"run-post" => 1,
"function" => \&action_search
},
"shell" => {
"function" => \&action_shell
},
"update" => {
"options" => {
"all" => 1,
"backup" => 1,
"backupdir" => "=s",
"dry-run|n" => 1,
"exclude" => "=s@",
"force" => 1,
"list" => 1,
"no-auto-install" => 1,
"no-auto-remove" => 1,
"no-depends" => 1,
"no-depends-at-all" => 1,
"no-restart" => 1,
"reinstall-forcibly-removed" => 1,
"self" => 1,
},
"run-post" => 1,
"function" => \&action_update
},
"version" => { }, # handled separately
);
my %globaloptions = (
"gui" => 1,
"gui-lang" => "=s",
"debug-json-timing" => 1,
"debug-translation" => 1,
"h|?" => 1,
"help" => 1,
"json" => 1,
"location|repository|repo" => "=s",
"machine-readable" => 1,
"no-execute-actions" => 1,
"package-logfile" => "=s",
"command-logfile" => "=s",
"persistent-downloads" => "!",
"pause" => 1,
"pin-file" => "=s",
"print-platform|print-arch" => 1,
"print-platform-info" => 1,
"usermode|user-mode" => 1,
"usertree|user-tree" => "=s",
"verify-repo" => "=s",
"verify-downloads" => "!",
"require-verification" => "!",
"version" => 1,
);
main();
### main ##################################################################
sub main {
my %options; # TL options from local tlpdb
my %optarg;
for my $k (keys %globaloptions) {
if ($globaloptions{$k} eq "1") {
$optarg{$k} = 1;
} else {
$optarg{"$k" . $globaloptions{$k}} = 1;
}
}
for my $v (values %action_specification) {
if (defined($v->{'options'})) {
my %opts = %{$v->{'options'}};
for my $k (keys %opts) {
if ($opts{$k} eq "1") {
$optarg{$k} = 1;
} else {
$optarg{"$k" . $opts{$k}} = 1;
}
}
}
}
# save command line options for later restart, if necessary
@::SAVEDARGV = @ARGV;
TeXLive::TLUtils::process_logging_options();
GetOptions(\%opts, keys(%optarg)) or pod2usage(2);
# load the config file and set the config options
# load it BEFORE starting downloads as we set persistent-downloads there!
load_config_file();
$::debug_translation = 0;
$::debug_translation = 1 if $opts{"debug-translation"};
$::machinereadable = $opts{"machine-readable"}
if (defined($opts{"machine-readable"}));
$action = shift @ARGV;
if (!defined($action)) {
if ($opts{"gui"}) { # -gui = gui
$action = "gui";
} elsif ($opts{"print-platform"}) {
$action = "print-platform";
} elsif ($opts{"print-platform-info"}) {
$action = "print-platform-info";
} else {
$action = "";
}
}
$action = lc($action);
$action = "platform" if ($action eq "arch");
ddebug("action = $action\n");
for my $k (keys %opts) {
ddebug("$k => " . (defined($opts{$k}) ? $opts{$k} : "(undefined)") . "\n");
}
ddebug("arguments: @ARGV\n") if @ARGV;
# prepare for loading of lang.pl which expects $::lang and $::opt_lang
$::opt_lang = $config{"gui-lang"} if (defined($config{"gui-lang"}));
$::opt_lang = $opts{"gui-lang"} if (defined($opts{"gui-lang"}));
require("TeXLive/trans.pl");
load_translations();
if ($opts{"version"} || (defined $action && $action eq "version")) {
if ($::machinereadable) {
# give_version already is machinereadable aware
print give_version();
} else {
info(give_version());
}
exit(0);
}
if (defined($action) && $action eq "help") {
$opts{"help"} = 1;
$action = undef; # an option not an action
}
if (defined($action) && $action eq "print-platform") {
print TeXLive::TLUtils::platform(), "\n";
exit 0;
}
if (defined($action) && $action eq "print-platform-info") {
print "config.guess ", `$::installerdir/tlpkg/installer/config.guess`;
my $plat = TeXLive::TLUtils::platform();
print "platform ", $plat, "\n";
print "platform_desc ", TeXLive::TLUtils::platform_desc($plat), "\n";
exit 0;
}
# ACTION massaging
# for backward compatibility and usability
# unify arguments so that the $action contains paper in all cases
# and push the first arg back to @ARGV for action_paper processing
if (defined $action
&& $action =~ /^(paper|xdvi|psutils|pdftex|dvips|dvipdfmx?|context)$/) {
unshift(@ARGV, $action);
$action = "paper";
}
# backward compatibility with action "show" and "list" from before
if (defined $action && $action =~ /^(show|list)$/) {
$action = "info";
}
# merge actions remove and uninstall
if (defined $action && $action eq "uninstall") {
$action = "remove";
}
#
# check for correctness of verify-repo argument
if (defined($opts{"verify-repo"}) &&
($opts{"verify-repo"} !~ m/$allowed_verify_args_regex/)) {
tldie("$prg: unknown value for --verify-repo: $opts{'verify-repo'}\n");
}
# convert command line crypto options
$opts{"verify-repo"}
= convert_crypto_options($opts{"verify-downloads"},
$opts{"require-verification"},
$opts{"verify-repo"});
if (defined($opts{"verify-downloads"})
|| defined($opts{"require-verification"})) {
tlwarn("$prg: please use -verify-repo options instead of verify-downloads/require-verification\n" .
"$prg: adjusting to --verify-repo=$opts{'verify-repo'}\n");
}
delete $opts{"require-verification"};
delete $opts{"verify-downloads"};
# now $action should be part of %actionoptions, otherwise this is
# an error
if (defined($action) && $action && !exists $action_specification{$action}) {
die "$prg: unknown action: $action; try --help if you need it.\n";
}
if ((!defined($action) || !$action) && !$opts{"help"} && !$opts{"h"}) {
die "$prg: no action given; try --help if you need it.\n";
}
if ($opts{"help"} || $opts{"h"}) {
# perldoc does ASCII emphasis on the output, and runs it through
# $PAGER, so people want it. But not all Unix platforms have it,
# and on Windows our Config.pm can apparently interfere, so always
# skip it there. Or if users have NOPERLDOC set in the environment.
my @noperldoc = ();
if (win32() || $ENV{"NOPERLDOC"}) {
@noperldoc = ("-noperldoc", "1");
} else {
if (!TeXLive::TLUtils::which("perldoc")) {
@noperldoc = ("-noperldoc", "1");
} else {
# checking only for the existence of perldoc is not enough
# because Debian/Ubuntu unfortunately ship a stub that does nothing;
# try to check for that, too.
my $ret = system("perldoc -V >/dev/null 2>&1");
if ($ret == 0) {
debug("working perldoc found, using it\n");
} else {
tlwarn("$prg: perldoc seems to be non-functional, not using it.\n");
@noperldoc = ("-noperldoc", "1");
}
}
}
# less can break control characters and thus the output of pod2usage
# is broken. We add/set LESS=-R in the environment and unset
# LESSPIPE and LESSOPEN to try to help.
#
if (defined($ENV{'LESS'})) {
$ENV{'LESS'} .= " -R";
} else {
$ENV{'LESS'} = "-R";
}
delete $ENV{'LESSPIPE'};
delete $ENV{'LESSOPEN'};
if ($action && ($action ne "help")) {
# 1) Must use [...] form for -sections arg because otherwise the
# /$action subsection selector applies to all sections.
# https://rt.cpan.org/Public/Bug/Display.html?id=102116
# 2) Must use "..." for that so the $action value is interpolated.
pod2usage(-exitstatus => 0, -verbose => 99,
-sections => [ 'NAME', 'SYNOPSIS', "ACTIONS/$::action.*" ],
@noperldoc);
} else {
if ($opts{"help"}) {
pod2usage(-exitstatus => 0, -verbose => 2, @noperldoc);
} else {
# give a short message about usage
print "
tlmgr revision $tlmgrversion
usage: tlmgr OPTION... ACTION ARGUMENT...
where ACTION is one of:\n";
for my $k (sort keys %action_specification) {
# don't print internal options
next if ($k =~ m/^_/);
print " $k\n";
}
print "\nUse\n tlmgr ACTION --help
for more details on a specific option, and
tlmgr --help
for the full story.\n";
exit 0;
}
}
}
# --machine-readable is only supported by update.
if ($::machinereadable &&
$action ne "update" && $action ne "install" && $action ne "option" && $action ne "shell" && $action ne "remove") {
tlwarn("$prg: --machine-readable output not supported for $action\n");
}
#
# bail out of it is unknown action
if (!defined($action_specification{$action})) {
tlwarn("$prg: action unknown: $action\n");
exit ($F_ERROR);
}
# check on supported arguments
#
my %suppargs;
%suppargs = %{$action_specification{$action}{'options'}}
if defined($action_specification{$action}{'options'});
my @notvalidargs;
for my $k (keys %opts) {
my @allargs = keys %suppargs;
push @allargs, keys %globaloptions;
my $found = 0;
for my $ok (@allargs) {
my @variants = split '\|', $ok;
if (TeXLive::TLUtils::member($k, @variants)) {
$found = 1;
last;
}
}
push @notvalidargs, $k if !$found;
}
if (@notvalidargs) {
my $msg = "The action $action does not support the following option(s):\n";
for my $c (@notvalidargs) {
$msg .= " $c";
}
tlwarn("$prg: $msg\n");
tldie("$prg: Try --help if you need it.\n");
}
#
# the main tree we will be working on
$::maintree = $Master;
if ($opts{"usermode"}) {
# we could also try to detect that we don't have write permissions
# and switch to user mode automatically
if (defined($opts{"usertree"})) {
$::maintree = $opts{"usertree"};
} else {
chomp($::maintree = `kpsewhich -var-value TEXMFHOME`);
}
}
# besides doing normal logging if -logfile is specified, we try to log
# package related actions (install, remove, update) to
# the package-log file TEXMFSYSVAR/web2c/tlmgr.log
$packagelogged = 0; # how many msgs we logged
$commandslogged = 0;
chomp (my $texmfsysvar = `kpsewhich -var-value=TEXMFSYSVAR`);
$packagelogfile = $opts{"package-logfile"};
if ($opts{"usermode"}) {
$packagelogfile ||= "$::maintree/web2c/tlmgr.log";
} else {
$packagelogfile ||= "$texmfsysvar/web2c/tlmgr.log";
}
#
# Try to open the packagelog file, but do NOT die when that does not work
if (!open(PACKAGELOG, ">>$packagelogfile")) {
debug("Cannot open package log file for appending: $packagelogfile\n");
debug("Will not log package installation/removal/update for this run\n");
$packagelogfile = "";
} else {
debug("appending to package log file: $packagelogfile\n");
}
# output of executed commands are put into -command-logfile
$commandlogfile = $opts{"command-logfile"};
if ($opts{"usermode"}) {
$commandlogfile ||= "$::maintree/web2c/tlmgr-commands.log";
} else {
$commandlogfile ||= "$texmfsysvar/web2c/tlmgr-commands.log";
}
# Try to open the packagelog file, but do NOT die when that does not work
if (!open(COMMANDLOG, ">>$commandlogfile")) {
debug("Cannot open command log file for appending: $commandlogfile\n");
debug("Will not log output of executed commands for this run\n");
$commandlogfile = "";
} else {
debug("appending to command log file: $commandlogfile\n");
}
$loadmediasrcerror = "Cannot load TeX Live database from ";
# in system mode verify that the selected action is allowed
if (!$opts{"usermode"} && $config{'allowed-actions'}) {
if (!TeXLive::TLUtils::member($action, @{$config{'allowed-actions'}})) {
tlwarn("$prg: action not allowed in system mode: $action\n");
exit ($F_ERROR);
}
}
# set global variable if execute actions should be suppressed
$::no_execute_actions = 1 if (defined($opts{'no-execute-actions'}));
# if we are asked to use persistent connections try to start it here
ddebug("tlmgr:main: do persistent downloads = $opts{'persistent-downloads'}\n");
if ($opts{'persistent-downloads'}) {
TeXLive::TLUtils::setup_persistent_downloads() ;
}
if (!defined($::tldownload_server)) {
debug("tlmgr:main: ::tldownload_server not defined\n");
} else {
if ($::opt_verbosity >= 1) {
debug(debug_hash_str("$prg:main: ::tldownload_server hash:",
$::tldownload_server));
}
}
my $ret = execute_action($action, @ARGV);
# close the special log file
if (!$::gui_mode) {
if ($packagelogfile) {
info("$prg: package log updated: $packagelogfile\n") if $packagelogged;
close(PACKAGELOG);
}
if ($commandlogfile) {
info("$prg: command log updated: $commandlogfile\n") if $commandslogged;
close(COMMANDLOG);
}
}
# F_ERROR stops processing immediately, and prevents postactions from
# being run (e.g., untar fails). F_WARNING continues on, including
# postactions (e.g., user tries to install 10 packages and the
# checksum fails for one, but the others are ok), but still ends the
# program by exiting unsuccessfully. So call them both "errors"
# as far as the user is concerned.
if ($ret & ($F_ERROR | $F_WARNING)) {
tlwarn("$prg: An error has occurred. See above messages. Exiting.\n");
}
# end of main program, returns also error codes
exit ($ret);
} # end main
sub give_version {
if (!defined($::version_string)) {
$::version_string = "";
$::mrversion = "";
$::version_string .= "tlmgr revision $tlmgrversion\n";
$::mrversion .= "revision $tlmgrrevision\n";
$::version_string .= "tlmgr using installation: $Master\n";
$::mrversion .= "installation $Master\n";
if (open (REL_TL, "$Master/release-texlive.txt")) {
# print first, which has the TL version info.
my $rel_tl = <REL_TL>;
$::version_string .= $rel_tl;
# for machine readable we only want the last word which is the version
my @foo = split(' ', $rel_tl);
$::mrversion .= "tlversion $foo[$#foo]\n";
close (REL_TL);
}
#
# add the list of revisions
if ($::opt_verbosity > 0) {
$::version_string .= "Revisions of TeXLive:: modules:";
$::version_string .= "\nTLConfig: " . TeXLive::TLConfig->module_revision();
$::version_string .= "\nTLUtils: " . TeXLive::TLUtils->module_revision();
$::version_string .= "\nTLPOBJ: " . TeXLive::TLPOBJ->module_revision();
$::version_string .= "\nTLPDB: " . TeXLive::TLPDB->module_revision();
$::version_string .= "\nTLPaper: " . TeXLive::TLPaper->module_revision();
$::version_string .= "\nTLWinGoo: " . TeXLive::TLWinGoo->module_revision();
$::version_string .= "\n";
}
$::mrversion .= "TLConfig " . TeXLive::TLConfig->module_revision();
$::mrversion .= "\nTLUtils " . TeXLive::TLUtils->module_revision();
$::mrversion .= "\nTLPOBJ " . TeXLive::TLPOBJ->module_revision();
$::mrversion .= "\nTLPDB " . TeXLive::TLPDB->module_revision();
$::mrversion .= "\nTLPaper " . TeXLive::TLPaper->module_revision();
$::mrversion .= "\nTLWinGoo " . TeXLive::TLWinGoo->module_revision();
$::mrversion .= "\n";
}
if ($::machinereadable) {
return $::mrversion;
} else {
return $::version_string;
}
}
sub execute_action {
my ($action, @argv) = @_;
# we have to set @ARGV to the @argv since many of the action_* subs
# use GetOption
@ARGV = @argv;
# actions which shouldn't have any lasting effects, such as search or
# list, end by calling finish(0), which skips postinstall actions.
if (!defined($action_specification{$action})) {
tlwarn ("$prg: unknown action: $action; try --help if you need it.\n");
return ($F_ERROR);
}
if (!defined($action_specification{$action}{"function"})) {
tlwarn ("$prg: action $action defined, but no way to execute it.\n");
return $F_ERROR;
}
my $ret = $F_OK;
my $foo = &{$action_specification{$action}{"function"}}();
if (defined($foo)) {
if ($foo & $F_ERROR) {
# report of bad messages are given at the top level.
return $foo;
}
if ($foo & $F_WARNING) {
tlwarn("$prg: action $action returned an error; continuing.\n");
$ret = $foo;
}
} else {
$ret = $F_OK;
tlwarn("$prg: no value returned from action $action, assuming ok.\n");
}
my $run_post = 1;
if ($ret & $F_NOPOSTACTION) {
# clear the postaction bit
$ret ^= $F_NOPOSTACTION;
$run_post = 0;
}
if (!$action_specification{$action}{"run-post"}) {
$run_post = 0;
}
return ($ret) if (!$run_post);
# run external programs.
$ret |= &handle_execute_actions();
return $ret;
}
# run CMD with notice to the user and if exit status is nonzero, complain.
# return exit status.
#
sub do_cmd_and_check {
my $cmd = shift;
# we output the pre-running notice on a separate line so that
# tlmgr front ends (MacOSX's TeX Live Utility) can read it
# and show it to the user before the possibly long delay.
info("running $cmd ...\n");
logcommand("running $cmd");
logpackage("command: $cmd");
my ($out, $ret);
if ($opts{"dry-run"}) {
$ret = $F_OK;
$out = "";
} elsif (win32() && (! -r "$Master/bin/win32/luatex.dll")) {
# deal with the case where only scheme-infrastructure is installed
# on Windows, thus no luatex.dll is available and the wrapper cannot be started
tlwarn("Cannot run wrapper due to missing luatex.dll\n");
$ret = $F_OK;
$out = "";
} else {
($out, $ret) = TeXLive::TLUtils::run_cmd("$cmd 2>&1");
}
$out =~ s/\n+$//; # trailing newlines don't seem interesting
my $outmsg = "output:\n$out\n--end of output of $cmd.\n";
if ($ret == $F_OK) {
info("done running $cmd.\n") unless $cmd =~ /^fmtutil/;
logcommand("success, $outmsg");
ddebug("$cmd $outmsg");
return ($F_OK);
} else {
info("\n");
tlwarn("$prg: $cmd failed (status $ret), output:\n$out\n");
logcommand("error, status: $ret, $outmsg");
return ($F_ERROR);
}
}
# run external programs (mktexlsr, updmap-sys, etc.) as specified by the
# keys in the RET hash. We return the number of unsuccessful runs, zero
# if all ok.
#
# If the "map" key is specified, the value may be a reference to a list
# of map command strings to pass to updmap, e.g., "enable Map=ascii.map".
#
sub handle_execute_actions {
my $errors = 0;
my $sysmode = ($opts{"usermode"} ? "-user" : "-sys");
my $fmtutil_cmd = "fmtutil$sysmode";
my $status_file = TeXLive::TLUtils::tl_tmpfile();
my $fmtutil_args = "$common_fmtutil_args --status-file=$status_file";
# if create_formats is false (NOT the default) we add --refresh so that
# only existing formats are recreated
if (!$localtlpdb->option("create_formats")) {
$fmtutil_args .= " --refresh";
debug("refreshing only existing formats per user option (create_formats=0)\n");
}
if ($::files_changed) {
$errors += do_cmd_and_check("mktexlsr");
if (defined($localtlpdb->get_package('context'))
&& (-x "$bindir/texlua" || -x "$bindir/texlua.exe")) {
$errors += do_cmd_and_check("mtxrun --generate");
}
$::files_changed = 0;
}
chomp(my $TEXMFSYSVAR = `kpsewhich -var-value=TEXMFSYSVAR`);
chomp(my $TEXMFSYSCONFIG = `kpsewhich -var-value=TEXMFSYSCONFIG`);
chomp(my $TEXMFLOCAL = `kpsewhich -var-value=TEXMFLOCAL`);
chomp(my $TEXMFDIST = `kpsewhich -var-value=TEXMFDIST`);
# maps handling
{
my $updmap_run_needed = 0;
for my $m (keys %{$::execute_actions{'enable'}{'maps'}}) {
$updmap_run_needed = 1;
}
for my $m (keys %{$::execute_actions{'disable'}{'maps'}}) {
$updmap_run_needed = 1;
}
my $dest = $opts{"usermode"} ? "$::maintree/web2c/updmap.cfg"
: "$TEXMFDIST/web2c/updmap.cfg";
if ($updmap_run_needed) {
TeXLive::TLUtils::create_updmap($localtlpdb, $dest);
}
$errors += do_cmd_and_check("updmap$sysmode") if $updmap_run_needed;
}
# format relevant things
# we first have to check if the config files, that is fmtutil.cnf
# or one of the language* files have changed, regenerate them
# if necessary, and then run the necessary fmtutil calls.
{
# first check for language* files
my $regenerate_language = 0;
for my $m (keys %{$::execute_actions{'enable'}{'hyphens'}}) {
$regenerate_language = 1;
last;
}
for my $m (keys %{$::execute_actions{'disable'}{'hyphens'}}) {
$regenerate_language = 1;
last;
}
if ($regenerate_language) {
for my $ext ("dat", "def", "dat.lua") {
my $lang = "language.$ext";
info("regenerating $lang\n");
my $arg1 = "$TEXMFSYSVAR/tex/generic/config/language.$ext";
my $arg2 = "$TEXMFLOCAL/tex/generic/config/language-local.$ext";
if ($ext eq "dat") {
TeXLive::TLUtils::create_language_dat($localtlpdb, $arg1, $arg2);
} elsif ($ext eq "def") {
TeXLive::TLUtils::create_language_def($localtlpdb, $arg1, $arg2);
} else {
TeXLive::TLUtils::create_language_lua($localtlpdb, $arg1, $arg2);
}
}
}
# format-regenerate is used when the paper size changes.
# In that case we simply want to generate all formats
#
my %done_formats;
my %updated_engines;
my %format_to_engine;
my %do_enable;
my $do_full = 0;
for my $m (keys %{$::execute_actions{'enable'}{'formats'}}) {
$do_full = 1;
$do_enable{$m} = 1;
# here we check whether an engine is updated
my %foo = %{$::execute_actions{'enable'}{'formats'}{$m}};
if (!defined($foo{'name'}) || !defined($foo{'engine'})) {
tlwarn("$prg: Very strange error, please report ", %foo);
} else {
$format_to_engine{$m} = $foo{'engine'};
if ($foo{'name'} eq $foo{'engine'}) {
$updated_engines{$m} = 1;
}
}
}
for my $m (keys %{$::execute_actions{'disable'}{'formats'}}) {
$do_full = 1;
}
if ($do_full) {
info("regenerating fmtutil.cnf in $TEXMFDIST\n");
TeXLive::TLUtils::create_fmtutil($localtlpdb,
"$TEXMFDIST/web2c/fmtutil.cnf");
}
if (!$::regenerate_all_formats) {
# first regenerate all formats --byengine
for my $e (keys %updated_engines) {
debug ("updating formats based on $e\n");
$errors += do_cmd_and_check
("$fmtutil_cmd --byengine $e --no-error-if-no-format $fmtutil_args");
read_and_report_fmtutil_status_file($status_file);
unlink($status_file);
}
# now rebuild all other formats
for my $f (keys %do_enable) {
next if defined($updated_engines{$format_to_engine{$f}});
# ignore disabled formats
next if !$::execute_actions{'enable'}{'formats'}{$f}{'mode'};
debug ("(re)creating format dump $f\n");
$errors += do_cmd_and_check ("$fmtutil_cmd --byfmt $f $fmtutil_args");
read_and_report_fmtutil_status_file($status_file);
unlink($status_file);