summaryrefslogtreecommitdiff
path: root/Master/tlpkg/bin/tl-make-install-pkg
blob: 28a0baa8cbea639bf116fe7918e8675a8653005a (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
#!/usr/bin/env perl
$^W=1;

# $Id$
# tl-make-install-pkg
#
# Copyright 2008 Reinhard Kotucha, Norbert Preining
# This file is licensed under the GNU General Public License version 2
# or any later version.

# tl-make-install-pkg.pl is supposed to create the file "install-tl.zip"
# is needed for network downloads.

BEGIN {
  $^W = 1;
  my $me=$0;
  $thisdir=`pwd`;
  chomp ($thisdir);
  if ($me=~m!/!) {
    ($::installerdir=$me)=~s!(.*)/.*$!$1/../..!;
  } else {
    $::installerdir='../..';
  }
  chdir $installerdir or die "can't chdir \"$installerdir\".\n";
  $installerdir=`pwd`;
  chomp ($installerdir);
  unshift (@INC, "$::installerdir/tlpkg");
}

use TeXLive::TLUtils qw(mkdirhier copy get_system_tmpdir tllog);
use TeXLive::TLPDB;
use TeXLive::TLPOBJ;
use Getopt::Long;
$Getopt::Long::autoabbrev=0;

$opt_help=0;
$opt_verbose=0;
$opt_outputdir=0;

sub usage {
  print <<'EOF';
Usage:
    tl-make-install-pkg [-h|--help] [-v|--verbose] -o|--outputdir=dir

    tl-make-install-pkg generates a .tar.gz file for Unix and a .zip file
    for all systems containing all the files needed to install TeX Live
    from the network.

    Options:
        -h|--help        Print this message.
        -o|--outputdir   Target directory. Must exist and be writable.
        -v|--verbose     Extra messages.
EOF
;
  exit 0;
}

usage if (@ARGV<1);

GetOptions 
    "verbose|v",
    "outputdir|o=s",
    "help|h";

usage if ($opt_help);

### determine directories.

my $sys_tmp=get_system_tmpdir or die "No system TMPDIR found."; 
my $tmpdir="$sys_tmp/install-tl-$$";
my $inst_tmp="$sys_tmp/install-tl-$$/install-tl";
my $outputdir="$opt_outputdir";
$outputdir="$thisdir/$outputdir" unless ($outputdir=~m!^/!); 

### cleanup.

my @signals=qw(HUP INT ILL FPE SEGV TERM ABRT QUIT BUS PIPE);

sub cleanup {
  if (-d "$tmpdir") {
    system('rm', '-rf', "$tmpdir");
  }
}

foreach my $signal (@signals) {
  $SIG{"$signal"}=\&cleanup;
}

### create directories.

die "$tmpdir already exists.\n" if (-d "$tmpdir");

mkdir "$tmpdir" or die "Can't mkdir \"$tmpdir\".\n";
mkdir "$inst_tmp" or die "Can't mkdir \"$inst_tmp\".\n";

if ($opt_verbose) {
  tllog ($::LOG_NORMAL, "thisdir:      \"$thisdir\"\n");
  tllog ($::LOG_NORMAL, "installerdir: \"$installerdir\"\n");
  tllog ($::LOG_NORMAL, "sys_tmp:      \"$sys_tmp\"\n");
  tllog ($::LOG_NORMAL, "tmpdir:       \"$tmpdir\"\n");
  tllog ($::LOG_NORMAL, "inst_tmp:     \"$inst_tmp\"\n");
  tllog ($::LOG_NORMAL, "outputdir:    \"$outputdir\"\n");
}

die "outputdir \"$outputdir\" dosn't exist.\n" unless (-d "$outputdir");
die "outputdir \"$outputdir\" is not writable.\n" unless (-w "$outputdir");

### read TLPDB and extract files

my $tlpdb = TeXLive::TLPDB->new ("root" => "$installerdir");
die("Cannot find tlpdb in $installerdir!\n") unless defined($tlpdb);
my $tlp = $tlpdb->get_package("00texlive.installer");
die("Cannot find package 00texlive.installer in ${installerdir}'s texlive.tlpdb\n") unless defined($tlp);

my $tlpinfra = $tlpdb->get_package("texlive-infra");
die("Cannot find package texlive-infra in ${installerdir}'s texlive.tlpdb\n") unless defined($tlp);


my @unix;
push @unix, $tlp->runfiles;
push @unix, $tlpinfra->runfiles;
push @unix, $tlp->docfiles;
my %tlpbin = %{$tlp->binfiles};
foreach my $a (keys %tlpbin) {
  next if ($a =~ m/win32/);
  push @unix, @{$tlpbin{$a}};
}
my @win32;
push @win32, @unix;
if (defined($tlpbin{"win32"})) {
  push @win32, @{$tlpbin{"win32"}};
}

### copy files from the repository to tmpdir

sub copy_files {
  my ($dir, $file);
  for (@_) {
    if ($_ !~ m!/!) {
      # file in the root, missing ./
      $_ = "./$_";
    }
    ($dir, $file) = /^(.*)\/(.*)/;
    mkdirhier "$inst_tmp/$dir";
    copy "$_", "$inst_tmp/$dir";
  }
}

### create the .tar.gz and the .zip file

sub make_zip
{
  my ($type) = @_;
  tllog ($::LOG_NORMAL, "making $type\n");

  chdir ($tmpdir) || die "chdir($tmpdir) failed: $!";
  if ($type eq 'zip') {
    system('zip', '-rq', 'install-tl.zip', 'install-tl'); 
  } else {
    system('tar', '-czf', 'install-tl-unx.tar.gz', 'install-tl'); 
  }
  chdir ($installerdir) || die "chdir($installerdir) failed: $!";
}

### copy generated files to outputdir

sub install_zip
{
  tllog ($::LOG_NORMAL, "installing to $outputdir\n");
  copy "$tmpdir/install-tl-unx.tar.gz", $outputdir;
  system ('ls', '-l', "$outputdir/install-tl-unx.tar.gz");

  copy "$tmpdir/install-tl.zip", $outputdir;
  system ('ls', '-l', "$outputdir/install-tl.zip");
}

### main
copy_files (@unix);
make_zip 'tgz';

copy_files (@win32);
make_zip 'zip';

install_zip;

cleanup;

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