summaryrefslogtreecommitdiff
path: root/Master/tlpkg/TeXLive/TLPostActions.pm
blob: 6025c2867d16b32caa9f790c282b8578410ed8e1 (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
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
# $Id$
# TeXLive::TLPostActions.pm - collection post install stuff for installation
# Copyright 2008 Norbert Preining
# This file is licensed under the GNU General Public License version 2
# or any later version.

package TeXLive::TLPostActions;

BEGIN {
  use Exporter ();
  use vars qw( @ISA @EXPORT_OK @EXPORT );
  @ISA = qw(Exporter);
  @EXPORT_OK = qw(
    %PostInstall
    %PostRemove
  );
  @EXPORT = @EXPORT_OK;
}

use TeXLive::TLUtils qw(win32 mkdirhier copy conv_to_win_path);
use TeXLive::TLWinGoo;

my $mainmenu = "TeX Live 2008";

our %PostInstall;
our %PostRemove;


#
# bin-xetex
#
sub do_install_bin_xetex {
  my ($texdir, $texdirw, $texmfsysvar) = @_;
  #
  # bin-xetex installs font-config related stuff
  #
  # new version according to Staszek
  if (!defined($texmfsysvar)) {
    texmfsysvar = `kpsewhich -var-value=TEXMFSYSVAR`;
    chomp(texmfsysvar);
  }
  if (-r "$texdir/bin/win32/conf/fonts.conf") {
    # we have installed win32, so put it into texmfsysvar
    mkdirhier("$texmfsysvar/fonts");
    my @cpycmd;
    if (win32()) {
      push @cpycmd, "xcopy", "/e", "/i";
    } else {
      push @cpycmd, "cp", "-a";
    }
    system(@cpycmd,
             (win32() ? conv_to_win_path("$texdir/bin/win32/conf") :
                       "$texdir/bin/win32/conf"),
             (win32() ? conv_to_win_path("$texmfsysvar/fonts/conf") :
                       "$texmfsysvar/fonts/conf"));
    system(@cpycmd,
             (win32() ? conv_to_win_path("$texdir/bin/win32/cache") :
                       "$texdir/bin/win32/cache"),
             (win32() ? conv_to_win_path("$texmfsysvar/fonts/cache") :
                       "$texmfsysvar/fonts/cache"));
    open(FONTSCONF, "<$texdir/bin/win32/conf/fonts.conf")
      or die("Cannot open $texdir/bin/win32/conf/fonts.conf");
    my @lines = <FONTSCONF>;
    close(FONTSCONF);
    open(FONTSCONF, ">$texmfsysvar/fonts/conf/fonts.conf")
      or die("Cannot open $texmfsysvar/fonts/conf/fonts.conf for writing");
    my $winfontdir;
    if (win32()) {
      $winfontdir = $ENV{'SystemRoot'}.'/fonts';
      $winfontdir =~ s!\\!/!g;
      mkdirhier("$texmfsysvar/fonts/cache");
    }
    foreach (@lines) {
      $_ =~ s!c:/Program Files/texlive/2008!$texdir!;
      $_ =~ s!c:/windows/fonts!$winfontdir! if win32();
      $_ =~ s!c:/etc/fccache!$texmfsysvar/fonts/cache!;
      print FONTSCONF;
    }
    close(FONTSCONF);
  }
  # call fc-cache but only when we install on win32!
  if (win32()) {
    system("fc-cache","-v", "-r");
  }
}
$PostInstall{"bin-xetex"} = \&do_install_bin_xetex;

#
# bin-texdoc
#
sub do_install_bin_texdoc {
  my ($texdir, $texdirw) = @_;
  if (win32()) {
    add_desktop_shortcut(
      $texdirw,
      'TeXdoc GUI',
      '', # $vars{'TEXDIR'}.'/tlpkg/doc/notes.ico', # the icon
      $texdir.'/bin/win32/texdoctk.bat',
      '', # no args
      'batgui', # any non-null value to hide command-prompt
    );
    add_menu_shortcut(
      $mainmenu,
      'TeXdoc GUI',
      '', # $vars{'TEXDIR'}.'/tlpkg/doc/notes.ico', # the icon
      $texdir.'/bin/win32/texdoctk.bat',
      '', # no args
      'batgui', # any non-null value to hide command-prompt
    );
  }
}
sub do_remove_bin_texdoc {
  my ($texdir) = @_;
  if (win32()) {
    remove_desktop_shortcut('TeXdoc GUI');
    remove_menu_shortcut($mainmenu, 'TeXdoc GUI');
  }
}
$PostInstall{'bin-texdoc'} = \&do_install_bin_texdoc;
$PostRemove{'bin-texdoc'} = \&do_remove_bin_texdoc;

#
# bin-tlpsv.win32
#
sub do_install_bin_tlpsv_win32 {
  my ($texdir, $texdirw) = @_;
  if (win32()) {
    add_desktop_shortcut(
      $texdirw,
      'PS_View',
      $texdir.'/tlpkg/tlpsv/psv.exe', # icon, not prog!
      $texdir.'/bin/win32/psv.bat',
      '', # no args
      'batgui', # any non-null value to hide command-prompt
    );
    add_menu_shortcut(
      $mainmenu,
      'PS_View',
      $texdir.'/tlpkg/tlpsv/psv.exe', # icon, not prog!
      $texdir.'/bin/win32/psv.bat',
      '', # no args
      'batgui', # any non-null value to hide command-prompt
    );
    register_extension(".ps", "PostScript");
    register_extension(".eps", "PostScript");
    #register_file_type("PostScript", '"'.$texdir.'/bin/win32/psv.bat"');
    register_file_type("PostScript",
      '"'.$texdir.'/tlpkg/tlpsv/gswxlua.exe" -g '.
      '"'.$texdir.'/tlpkg/tlgs/bin/gsdll32.dll" -l '.
      '"'.$texdir.'/tlpkg/tlpsv/psv.wx.lua" -p '.
      '"'.$texdir.'/tlpkg/tlpsv/psv_view.ps" -sINPUT="%1"');
    update_assocs();
  }
}
sub do_remove_bin_tlpsv_win32 {
  my ($texdir) = @_;
  if (win32()) {
    remove_desktop_shortcut('PS_View');
    remove_menu_shortcut($mainmenu, 'PS_View');
    unregister_extension(".ps");
    unregister_extension(".eps");
    unregister_file_type("PostScript");
    update_assocs();
  }
}
$PostRemove{'bin-tlpsv.win32'} = \&do_remove_bin_tlpsv_win32;
$PostInstall{'bin-tlpsv.win32'} = \&do_install_bin_tlpsv_win32;

#
# bin-texlive
#
sub do_install_bin_texlive {
  my ($texdir, $texdirw) = @_;
  if (win32()) {
    add_menu_shortcut(
      $mainmenu,
      'TeX Live Manager',
      '', # $texdir.'/tlpkg/doc/dummy.ico',
      $texdir.'/bin/win32/tlmgr.bat',
      'gui',
      'batgui',
    );
    if (uc(TeXLive::TLWinGoo::win_which_dir('tex.exe')) ne
        uc($texdir.'/bin/win32')) {
      my $texbindir = $texdir."\\bin\\win32";
      $texbindir =~ s!/!\\!g;
      add_menu_shortcut(
        $mainmenu,
        'TeX Live Prompt',
        '',
        $ENV{'COMSPEC'},
       "/k \"path $texbindir;%path%\"",
       '',
      );
      add_desktop_shortcut(
        $texdirw,
        'TeX Live Prompt',
        '',
        $ENV{'COMSPEC'},
       "/k \"path $texbindir;%path%\"",
       '',
      );
    }
  }
}
sub do_remove_bin_texlive {
  my ($texdir) = @_;
  if (win32()) {
    remove_menu_shortcut($mainmenu, 'TeX Live Manager');
    remove_menu_shortcut($mainmenu, 'TeX Live Prompt');
    remove_desktop_shortcut('TeX Live Prompt');
  }
}
$PostInstall{'bin-texlive'} = \&do_install_bin_texlive;
$PostRemove{'bin-texlive'} = \&do_remove_bin_texlive;

#
# texlive-en
#
sub do_install_texlive_en {
  my ($texdir) = @_;
  if (win32()) {
    add_menu_shortcut(
      $mainmenu,
      'TeX Live Manual (en)',
      '', # default pdf icon
      $texdir.'/texmf-doc/doc/english/texlive-en/live.pdf',
      '',
      '',
    );
  }
}
sub do_remove_texlive_en {
  my ($texdir) = @_;
  if (win32()) {
    remove_menu_shortcut($mainmenu,'TeX Live Manual (en)');
  }
}
$PostInstall{'texlive-en'} = \&do_install_texlive_en;
$PostRemove{'texlive-en'} = \&do_remove_texlive_en;

#
# texlive-cz
#
sub do_install_texlive_cz {
  my ($texdir) = @_;
  if (win32()) {
    add_menu_shortcut(
      $mainmenu,
      'TeX Live Manual (cz)',
      '', # default pdf icon
      $texdir.'/texmf-doc/doc/czechslovak/texlive-cz/live.pdf',
      '',
      '',
    );
  }
}
sub do_remove_texlive_cz {
  my ($texdir) = @_;
  if (win32()) {
    remove_menu_shortcut($mainmenu,'TeX Live Manual (cz)');
  }
}
$PostInstall{'texlive-cz'} = \&do_install_texlive_cz;
$PostRemove{'texlive-cz'} = \&do_remove_texlive_cz;

#
# texlive-fr
#
sub do_install_texlive_fr {
  my ($texdir) = @_;
  if (win32()) {
    add_menu_shortcut(
      $mainmenu,
      'TeX Live Manual (fr)',
      '', # default pdf icon
      $texdir.'/texmf-doc/doc/french/texlive-fr/live.pdf',
      '',
      '',
    );
  }
}
sub do_remove_texlive_fr {
  my ($texdir) = @_;
  if (win32()) {
    remove_menu_shortcut($mainmenu,'TeX Live Manual (fr)');
  }
}
$PostInstall{'texlive-fr'} = \&do_install_texlive_fr;
$PostRemove{'texlive-fr'} = \&do_remove_texlive_fr;

#
# texlive-ge
#
sub do_install_texlive_ge {
  my ($texdir) = @_;
  if (win32()) {
    add_menu_shortcut(
      $mainmenu,
      'TeX Live Manual (de)',
      '', # default pdf icon
      $texdir.'/texmf-doc/doc/german/texlive-ge/live.pdf',
      '',
      '',
    );
  }
}
sub do_remove_texlive_ge {
  my ($texdir) = @_;
  if (win32()) {
    remove_menu_shortcut($mainmenu,'TeX Live Manual (de)');
  }
}
$PostInstall{'texlive-ge'} = \&do_install_texlive_ge;
$PostRemove{'texlive-ge'} = \&do_remove_texlive_ge;

#
# texlive-pl
#
sub do_install_texlive_pl {
  my ($texdir) = @_;
  if (win32()) {
    add_menu_shortcut(
      $mainmenu,
      'TeX Live Manual (pl)',
      '', # default pdf icon
      $texdir.'/texmf-doc/doc/polish/texlive-pl/live.pdf',
      '',
      '',
    );
  }
}
sub do_remove_texlive_pl {
  my ($texdir) = @_;
  if (win32()) {
    remove_menu_shortcut($mainmenu,'TeX Live Manual (pl)');
  }
}
$PostInstall{'texlive-pl'} = \&do_install_texlive_pl;
$PostRemove{'texlive-pl'} = \&do_remove_texlive_pl;

#
# texlive-ru
#
sub do_install_texlive_ru {
  my ($texdir) = @_;
  if (win32()) {
    add_menu_shortcut(
      $mainmenu,
      'TeX Live Manual (ru)',
      '', # default pdf icon
      $texdir.'/texmf-doc/doc/russian/texlive-ru/live.pdf',
      '',
      '',
    );
  }
}
sub do_remove_texlive_ru {
  my ($texdir) = @_;
  if (win32()) {
    remove_menu_shortcut($mainmenu,'TeX Live Manual (ru)');
  }
}
$PostInstall{'texlive-ru'} = \&do_install_texlive_ru;
$PostRemove{'texlive-ru'} = \&do_remove_texlive_ru;

#
# texlive-zh-cn
#
sub do_install_texlive_zh_cn {
  my ($texdir) = @_;
  if (win32()) {
    add_menu_shortcut(
      $mainmenu,
      'TeX Live Manual (zh-cn)',
      '', # default pdf icon
      $texdir.'/texmf-doc/doc/chinese/texlive-zh-cn/live.pdf',
      '',
      '',
    );
  }
}
sub do_remove_texlive_zh_cn {
  my ($texdir) = @_;
  if (win32()) {
    remove_menu_shortcut($mainmenu,'TeX Live Manual (zh-cn)');
  }
}
$PostInstall{'texlive-zh-cn'} = \&do_install_texlive_zh_cn;
$PostRemove{'texlive-zh-cn'} = \&do_remove_texlive_zh_cn;


#
# FROM HERE ON ONLY DISABLED POST INSTALL AND REMOVE ACTIONS!!!!!!!
#

# disabled
sub do_bin_xdvi {
  my ($TEXDIR, $TEXMFSYSVAR) = @_;
  if (!defined($TEXMFSYSVAR)) {
    $TEXMFSYSVAR = `kpsewhich -var-value=TEXMFSYSVAR`;
    chomp($TEXMFSYSVAR);
  }
  copy ("$TEXDIR/texmf/xdvi/XDvi", "$TEXMFSYSVAR/xdvi");
}
# $PostInstall{"bin-xdvi"} = \&do_bin_xdvi;


# disabled
sub do_plain {
  my ($TEXDIR, $TEXMFSYSVAR) = @_;
  if (!defined($TEXMFSYSVAR)) {
    $TEXMFSYSVAR = `kpsewhich -var-value=TEXMFSYSVAR`;
    chomp($TEXMFSYSVAR);
  }
  # install some copies from texmf(-dist) into texmf-var
  copy ("$TEXDIR/texmf-dist/tex/plain/config/language.def",
        "$TEXMFSYSVAR/tex/plain/config");
}
# $PostInstall{"plain"} = \&do_plain;


# disabled
sub do_bin_dvipsk {
  my ($TEXDIR, $TEXMFSYSVAR) = @_;
  if (!defined($TEXMFSYSVAR)) {
    $TEXMFSYSVAR = `kpsewhich -var-value=TEXMFSYSVAR`;
    chomp($TEXMFSYSVAR);
  }
  # those files must exist
  copy ("$TEXDIR/texmf/dvips/config/config.ps",
        "$TEXMFSYSVAR/dvips/config");
}
# $PostInstall{"bin-dvipsk"} = \&do_bin_dvipsk;

# disabled
sub do_bin_dvipdfm {
  my ($TEXDIR, $TEXMFSYSVAR) = @_;
  if (!defined($TEXMFSYSVAR)) {
    $TEXMFSYSVAR = `kpsewhich -var-value=TEXMFSYSVAR`;
    chomp($TEXMFSYSVAR);
  }
  # fix up dvipdfm config file to contain the right # piping command
  mkdirhier("$TEXMFSYSVAR/dvipdfm/config");
  open(DVIPDFMCONFIGDIST, "<$TEXDIR/texmf/dvipdfm/config/config")
    or die("Cannot open $TEXDIR/texmf/dvipdfm/config/config");
  open(DVIPDFMCONFIGINST, ">$TEXMFSYSVAR/dvipdfm/config/config")
    or die("Cannot open $TEXMFSYSVAR/dvipdfm/config/config");
  while (<DVIPDFMCONFIGDIST>) {
    if (m/^D /) {
      print DVIPDFMCONFIGINST 'D "epstopdf --outfile=%o --nocompress %i"', "\n";
    } else {
      print DVIPDFMCONFIGINST;
    }
  }
  close(DVIPDFMCONFIGDIST);
  close(DVIPDFMCONFIGINST);
}
# $PostInstall{"bin-dvipdfm"} = \&do_bin_dvipdfm;

# disabled
sub do_bin_dvipdfmx {
  my ($TEXDIR, $TEXMFSYSVAR) = @_;
  if (!defined($TEXMFSYSVAR)) {
    $TEXMFSYSVAR = `kpsewhich -var-value=TEXMFSYSVAR`;
    chomp($TEXMFSYSVAR);
  }
  # dvipdfmx.cfg
  open(DVIPDFMCONFIGDIST, "<$TEXDIR/texmf/dvipdfmx/dvipdfmx.cfg")
    or die("Cannot open $TEXDIR/texmf/dvipdfmx/dvipdfmx.cfg");
  open(DVIPDFMCONFIGINST, ">$TEXMFSYSVAR/dvipdfmx/dvipdfmx.cfg")
    or die("Cannot open $TEXMFSYSVAR/dvipdfmx/dvipdfmx.cfg");
  while (<DVIPDFMCONFIGDIST>) {
    # current dvipdfmx.cfg already contains the right rungs incantation
    # so do just copy the file to texmf-var
    #if (m/^D /) {
    #  print DVIPDFMCONFIGINST "%$_";
    #  print DVIPDFMCONFIGINST "\n%% GhostScript (TeX Live (Unix and Win32)):\n";
    #  print DVIPDFMCONFIGINST 'D  "rungs -q -dNOPAUSE -dBATCH -sPAPERSIZE=a0 -sDEVICE=pdfwrite -dCompatibilityLevel=1.3 -dAutoFilterGrayImages=false -dGrayImageFilter=/FlateEncode -dAutoFilterColorImages=false -dColorImageFilter=/FlateEncode -dUseFlateCompression=true -sOutputFile=%o %i -c quit"', "\n\n";
    #} else {
      print DVIPDFMCONFIGINST;
    #}
  }
  close(DVIPDFMCONFIGDIST);
  close(DVIPDFMCONFIGINST);
}
# $PostInstall{"bin-dvipdfmx"} = \&do_bin_dvipdfmx;


# disabled
sub do_bin_kpathsea {
  my ($TEXDIR, $TEXMFSYSVAR) = @_;
  if (!defined($TEXMFSYSVAR)) {
    $TEXMFSYSVAR = `kpsewhich -var-value=TEXMFSYSVAR`;
    chomp($TEXMFSYSVAR);
  }
  copy ("$TEXDIR/texmf/web2c/mktex.cnf",
        "$TEXMFSYSVAR/web2c");
}
# $PostInstall{"bin-kpathsea"} = \&do_bin_kpathsea;

# disabled
sub do_bin_pdftex {
  my ($TEXDIR, $TEXMFSYSVAR) = @_;
  if (!defined($TEXMFSYSVAR)) {
    $TEXMFSYSVAR = `kpsewhich -var-value=TEXMFSYSVAR`;
    chomp($TEXMFSYSVAR);
  }
  # the old installer copied from CDDIR, but shouldn't this be installed
  # in ANY case since it is in bin-pdftex???
  copy ("$TEXDIR/texmf/tex/generic/config/pdftexconfig.tex",
        "$TEXMFSYSVAR/tex/generic/config");
}
# $PostInstall{"bin-pdftex"} = \&do_bin_pdftex;

# disabled
sub do_context {
  my ($TEXDIR, $TEXMFSYSVAR) = @_;
  if (!defined($TEXMFSYSVAR)) {
    $TEXMFSYSVAR = `kpsewhich -var-value=TEXMFSYSVAR`;
    chomp($TEXMFSYSVAR);
  }
  # old installer did this, should we do this, TOO????
  copy ("$TEXDIR/texmf-dist/tex/context/config/cont-usr.tex",
        "$TEXMFSYSVAR/tex/context/config");
}
# $PostInstall{"context"} = \&do_context;


1;


=head1 NAME

C<TeXLive::TLPostActions> -- TeX Live Post Installation and Removal Routines

=head1 SYNOPSIS

  use TeXLive::TLPostActions;

=head1 DESCRIPTION

The L<TeXLive::TLPostActions> module exports the C<%PostInstall> and
the C<%PostRemove> hash indexed by package names providing code references.

These code references are called with the root of the installation as
argument (C<$SELFAUTOPARENT>). Additional arguments, but not necessarily
present, are the value of C<TEXMFSYSVAR> and C<TEXMFLOCAL>.

=head1 SEE ALSO

The modules L<TeXLive::TLUtils>, L<TeXLive::TLPSRC>,
L<TeXLive::TLPDB>, L<TeXLive::TLTREE>, L<TeXLive::TeXCatalogue>.

=head1 AUTHORS AND COPYRIGHT

This script and its documentation were written for the TeX Live
distribution (L<http://tug.org/texlive>) and both are licensed under the
GNU General Public License Version 2 or later.

=cut

### Local Variables:
### perl-indent-level: 2
### tab-width: 2
### indent-tabs-mode: nil
### End:
# vim:set tabstop=2 expandtab: #