summaryrefslogtreecommitdiff
path: root/Master/tlpkg/bin/tl-prune-platforms
blob: 6f58d45de060c586198ec1e363e918c37bfb4009 (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
#!/usr/bin/env perl
# Copyright 2012-2020 Norbert Preining
# This file is licensed under the GNU General Public License version 2
# or any later version.
#
# Prune (remove) platforms from a tlnet distribution tree.
# Run from tl-update-images.

my $vc_id;
my $mydir;

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

use strict;
use TeXLive::TLConfig;
use TeXLive::TLPOBJ;
use TeXLive::TLPDB;
use TeXLive::TLUtils;
use Getopt::Long;
use Pod::Usage;
use File::Path;

my $opt_version = 0;
my $opt_help = 0;
my $opt_dry = 0;

TeXLive::TLUtils::process_logging_options();
GetOptions(
  "dry-run|n"	=> \$opt_dry,
  "version"	=> \$opt_version,
  "help|?"      => \$opt_help) or pod2usage(1);

pod2usage("-exitstatus" => 0, "-verbose" => 2) if $opt_help;
if ($opt_version) { print "$vc_id\n"; exit 0; } 

exit (&main());


sub main {
  # prune db in the same hierarchy from which we are being run.
  chomp(my $Master = `cd $mydir/../.. && pwd`);
  # necessary for TLUtils->platform
  $::installerdir = $Master;
  my $tlpdb = TeXLive::TLPDB->new("root" => $Master);
  die "cannot find tlpdb in $Master" unless defined($tlpdb);

  my $format = $tlpdb->config_container_format;
  my $type = "xz";
  if ($format ne $type) {
    tlwarn("$0: unknown container format $format in 00texlive.config; ",
           "ignoring and continuing with $type");
  }

  # check that all archs given on the command line are actual archs,
  # otherwise bail out for security
  my @all_archs = $tlpdb->available_architectures;
  for my $a (@ARGV) {
    if (!TeXLive::TLUtils::member($a, @all_archs)) {
      die "platform $a not installed, cannot prune, goodbye";
    }
  }

  my $containerdir = "$Master/$TeXLive::TLConfig::Archive";

  # loop over packages and remove their binary component
  for my $pkg ($tlpdb->list_packages) {
    # by definition, any 00texlive... package does not need containers.
    next if $pkg =~ /00texlive/;
    
    my $tlp = $tlpdb->get_package($pkg);
    if (!$tlp) {
      # that is a package foobar.$a that has already been removed but
      # is still in the list above, so ignore it.
      next;
    }
    foreach my $dep ($tlp->depends) {
      if ($dep =~ m/^(.*)\.ARCH$/) {
        foreach my $a (@ARGV) {
          if ($tlpdb->get_package("$pkg.$a")) {
            # remove entry in the tlpdb
            print "removing $pkg.$a from tlpdb ... ";
            $tlpdb->remove_tlpobj("$pkg.$a") unless $opt_dry;
            print "done\n";
            # remove the container
            my @arch_files = glob ("$containerdir/$pkg.$a.*tar.xz");
            if (@arch_files) {
              print "removing @arch_files ... ";
              `rm @arch_files` unless $opt_dry;
              print "done\n";
            } else {
              print "no arch files for $pkg.$a?\n";
            }
          }
        }
      }
    }
  }

  my @newarchs;
  for my $a (@all_archs) {
    push @newarchs, $a if !TeXLive::TLUtils::member($a, @ARGV);
  }

  $tlpdb->setting("available_architectures", @newarchs);
  
  if (! $opt_dry) {
    TeXLive::TLUtils::copy ("-f", $tlpdb->location,
                            $tlpdb->location . ".preprune");
    $tlpdb->save;
  }

  return 0;
}

__END__

=head1 NAME

tl-prune-platforms - remove platforms from a tlnet hierarchy

=head1 SYNOPSIS

tl-prune-platforms [I<option>] [I<platform>] ...

=head1 OPTIONS

=over 4

=item B<--help>

Display this documentation and exit.

=item B<--version>

Display version information and exit.

=back

The standard options B<-q>, B<-v>, and B<-logfile>=I<file> are also
accepted; see the C<process_logging_options> function in
L<TeXLive::TLUtils> for details.

The format of the containers and the splitting of source and
documentation files are controlled by the tlpdb options in the
pseudo-package C<00texlive.config>.  See L<TeXLive::TLPDB>.

=head1 DESCRIPTION

This program removes the binary directories of the platforms given as
arguments; that is, remove the binfiles entries in the tlpdb, and remove
the containers.  (Any xz and wget binaries for the installer remain, though.)

It is used during DVD production to exclude certain platforms, and is
run from the L<tl-update-images> script.

The pre-existing tlpdb file is saved with extension C<.preprune> before
the modified version is written.

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