summaryrefslogtreecommitdiff
path: root/Master/tlpkg/dev/mktextex.pl
blob: 1dd107ada9c489faf04b7f684567ff82d46fcb4c (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
#!/usr/bin/env perl
# $Id: mktextex.pl 12269 2009-03-01 16:55:53Z trzeciak $
#
# Copyright 2009 Norbert Preining
# This file is licensed under the GNU General Public License version 2
# or any later version.
#
#

my $svnrev = '$Revision: 12269 $';
my $datrev = '$Date: 2009-03-01 17:55:53 +0100 (Sun, 01 Mar 2009) $';

our $Master;

BEGIN {
  $^W = 1;
  # make subprograms (including kpsewhich) have the right path:
  $mydir = $0;
  $mydir =~ s,/[^/]*$,,;
  if (!$^O=~/^MSWin(32|64)$/i) {
    $ENV{"PATH"} = "$mydir:$ENV{PATH}";
  }
  #
  chomp($Master = `kpsewhich -var-value=SELFAUTOPARENT`);
  #
  # make Perl find our packages first:
  unshift (@INC, "$Master/tlpkg");
  unshift (@INC, "$Master/texmf/scripts/texlive");
}

use Cwd qw/abs_path/;
use strict;

use TeXLive::TLConfig;
use TeXLive::TLPDB;

my $localtlpdb = TeXLive::TLPDB->new ("root" => $Master);
die("cannot find tlpdb in $Master") unless (defined($localtlpdb));
my $instloc = $localtlpdb->option_location;
my $mediatlpdb = TeXLive::TLPDB->new ("root" => $instloc);
die("cannot find tlpdb in $instloc.") unless defined($mediatlpdb);


my $fn = shift @ARGV;

printf STDERR "searching tlpdb fof $fn\n";

my @found = $mediatlpdb->find_file($fn);

if ($#found == 0) {
  # we found only one package, so install it
  my ($pkg,$file) = split ":", $found[0];
  printf STDERR "installing $pkg for $file\n";
  system("tlmgr install $pkg >&2");
  print "$Master/$file\n";
} elsif ($#found >= 0) {
  # too many packages found:
  printf STDERR "too many packages provide $fn:\n";
  for my $f (@found) {
    printf STDERR "$f\n";
  }
} else {
  printf STDERR "$fn not found in tlpdb\n";
}

exit 1;

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