summaryrefslogtreecommitdiff
path: root/Master/tlpkg/bin/update-containers
blob: 20c66d40a4b111c0b243cd5313e1fa126a15d05b (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
#!/usr/bin/env perl
# $Id: update-containers 5188 2007-10-14 20:32:44Z karl $
# Copyright 2008 Norbert Preining
# This file is licensed under the GNU General Public License version 2
# or any later version.
# 
# Generate a zip file for the packages specified on the cmdline, or
# for -all

BEGIN {
  $^W = 1;
  ($mydir = $0) =~ s,/[^/]*$,,;
  unshift (@INC, "$mydir/..");
}

use strict;

use TeXLive::TLConfig;
use TeXLive::TLPOBJ;
use TeXLive::TLPDB;
use TeXLive::TLUtils qw/debug/;
use Getopt::Long;
use Pod::Usage;
use File::Path;

my $opt_all = 0;
our $mydir;
our $opt_debug = 0;
my $opt_containerdir = "./archive";
my $opt_relative = 0;
my $help = 0;

GetOptions("containerdir=s"	=> \$opt_containerdir, 
           "debug!"       => \$opt_debug,
           "help|?"       => \$help) or pod2usage(1);

pod2usage(-exitstatus => 0, -verbose => 2) if $help;

my $srcsplit = 0;
my $docsplit = 0;
my $type = "lzma";

exit (&main ());

sub main
{
  # get the db.
  chomp (my $Master = `cd $mydir/../.. && pwd`);  # xx TLPDB should default
  my $tlpdb = TeXLive::TLPDB->new ("root" => "$Master");
  die("Cannot find tlpdb in $Master!\n") unless defined($tlpdb);
  my @packs;
  @packs = $tlpdb->list_packages;
  # get configuration of package splitting
  $srcsplit = $tlpdb->config_src_container;
  $docsplit = $tlpdb->config_doc_container;
  my $format = $tlpdb->config_container_format;
  if (($format eq "lzma") || ($format eq "zip")) {
    $type = $format;
  } else {
    warn "unknown container format specified in 00texlive.config: $format\nIgnoring and continuing with $type!\n";
  }
  # read in the old texlive.pkgver and save the revisions
  my %archiverevs;
  if (-r "$opt_containerdir/texlive.pkgver") {
    open(TMP,"<$opt_containerdir/texlive.pkgver") or
      die "Cannot open $opt_containerdir/texlive.pkgver for reading: $!\nPlease use tlpdb2container first!\n";
    while (<TMP>) {
      my ($pkg,$rev) = split;
      $archiverevs{$pkg} = $rev;
    }
    close(TMP);
  } else {
    die "No $opt_containerdir/texlive.pkgver, please use tlpdb2container first!\n";
  }
  # collect packages to be updated:
  my @todopacks;
  for my $pkg (@packs) {
    my $oldrev = 0;
    if (defined($archiverevs{$pkg})) {
      $oldrev = $archiverevs{$pkg};
    } else {
      debug("found a new package without container: $pkg\n");
    }
    my $tlp = $tlpdb->get_package($pkg);
    my $newrev = 0;
    if (defined($tlp)) {
      $newrev = $tlp->revision;
    } else {
      warn "It looks like $pkg has disappeared, you should remove its containers!\n";
    }
    if ($oldrev == $newrev) {
      debug("$pkg up to date\n");
    } elsif ($oldrev < $newrev) {
      push @todopacks, $pkg;
    } else {
      # huhh, the new rev is SMALLER then the oldrev?!?!
      die "This shouldn't happen, the revision of $pkg in texlive.tlpdb is OLDER than the one in $opt_containerdir/texlive.pkgver.\nAre you sure???\n";
    }
  }
  # get list of packages.
  for my $pkg (sort @todopacks) {
    next if ($pkg eq "00texlive.config");
    next if ($pkg eq "00texlive.installer");
    my $obj = $tlpdb->get_package ($pkg);
    die "$0: no TeX Live package named $pkg in $Master.\n" if ! $obj;
    printf STDERR "updating $pkg containers ...\n";
    if ($srcsplit) {
      my $objsrc = $obj->split_src_package;
      if ($objsrc) {
        $objsrc->make_container($type,$Master,$opt_containerdir,"$pkg.source",$opt_relative);
      }
    }
    if ($docsplit) {
      my $objdoc = $obj->split_doc_package;
      if ($objdoc) {
        $objdoc->make_container($type,$Master,$opt_containerdir,"$pkg.doc",$opt_relative);
      }
    }
    $obj->make_container($type,$Master,$opt_containerdir,$pkg,$opt_relative);
  }
  if (@todopacks) {
    # we did update something
    printf STDERR "updating $opt_containerdir/texlive.pkgver ...\n";
    open(TMP,">$opt_containerdir/texlive.pkgver") or die "Cannot create $opt_containerdir/texlive.pkgver";
    $tlpdb->generate_packagelist(\*TMP);
    close(TMP);
    print "all done.\n";
  } else {
    printf STDERR "Nothing to be done.\n";
  }
}



__END__

=head1 NAME

update-containers - update already generated containers

=head1 SYNOPSIS

update-containers [OPTION]... 

=head1 OPTIONS

=over 8

=item B<-containerdir> I<containerdir>
The location where the previously generated containers are to be found,
defaults to ./zip.

=back

The standard options C<-help> and C<-debug> are also accepted.
See the tlpfiles documentation for details.

Note that the format of the containers and the splitting off of source
and documentation files are controlled by the TLPDB options saved in the
pseudo package C<00texlive.config>. Please see the documentation for TLPDB
for details.


=head1 DESCRIPTION

The B<update-containers> program compares the revisions of all packages
as found in the C<containerdir> with the revisions of the packages in
the C<texlive.tlpdb>. In case the latter is more recent (i.e., a higher
number) the containers are updated.

=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: #