summaryrefslogtreecommitdiff
path: root/Master/tlpkg/bin/tl-update-makeself
blob: b170afcf6fd614e42bfb4ef8249c4dbef6f86a80 (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
#!/usr/bin/env perl
# $Id$
# Copyright 2008 Norbert Preining
# This file is licensed under the GNU General Public License version 2
# or any later version.
# 
# Creates a .run file for updating the texlive.infra and bin-texlive packages
# comparable to the windows .exe updater

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

our $mydir;

use strict;

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

my $help = 0;

TeXLive::TLUtils::process_logging_options();

GetOptions("help|?"       => \$help) or pod2usage(1);
pod2usage(-exitstatus => 0, -verbose => 2) if $help;

exit (&main ());


sub main
{
  # get the db.
  chomp (my $Master = `cd $mydir/../.. && pwd`);
  my $tlpdb = TeXLive::TLPDB->new ("root" => $Master);
  die("Cannot find tlpdb in $Master\n") unless defined($tlpdb);
  my @packs = ();
  my $bintexlive = $tlpdb->get_package("bin-texlive");
  my $texliveinfra = $tlpdb->get_package("texlive.infra");
  push @packs, $bintexlive;
  push @packs, $texliveinfra;

  for my $a ($tlpdb->available_architectures) {
    next if ($a eq "win32");
    my $foo = $tlpdb->get_package("bin-texlive.$a");
    push @packs, $foo if defined($foo);
    my $bar = $tlpdb->get_package("texlive.infra.$a");
    push @packs, $bar if defined($bar);
  }

  my @allfiles = ();
  for my $p (@packs) {
    push @allfiles, $p->all_files;
  }
  
  my $tmpdir = `mktemp -d`;
  chomp($tmpdir);
  for my $f (@allfiles) {
    if ($f !~ m!/!) {
      $f = "./$f";
    }
    my ($dn, $fn) = TeXLive::TLUtils::dirname_and_basename($f);
    `mkdir -p \"$tmpdir/master/$dn\"`;
    `cp -a \"$Master/$f\" \"$tmpdir/master/$f\"`;
  }

  # get highest rev of all these packages.
  my $rev = 0;
  for my $p (@packs) {
    $rev = $p->revision if $rev > $p->revision;
  }

  # we have to create the tlpobj files, too
  my $tlpobjdir = "$InfraLocation/tlpobj";
  if (! -d "$tmpdir/master/$tlpobjdir") {
    &TeXLive::TLUtils::mkdirhier("$tmpdir/master/$tlpobjdir");
  }
  for my $p (@packs) {
    open(TMP,">$tmpdir/master/$tlpobjdir/$p->{'name'}.tlpobj") or die "Cannot create $tmpdir/master/$tlpobjdir/$p->{'name'}.tlpobj";
    $p->writeout(\*TMP);
    close(TMP);
  }

  open (RUN, ">$tmpdir/runme.sh") or die "Cannot create $tmpdir/runme.sh: $!";
  print RUN <<'EOF';
#!/bin/sh
#
# updater for tlmgr and infrastructure on unix
#

ROOT=`kpsewhich --var-value=SELFAUTOPARENT`
if [ -r "$ROOT/tlpkg/texlive.tlpdb" ] ; then
  my ./master/bin .
  cp -a ./master/* "$ROOT/"
  # now try to get the list of installed architectures by listing the
  # directories in $ROOT/bin
  tlpobjs="\"$ROOT/tlpkg/tlpobj/bin-texlive.tlpobj\" \"$ROOT/tlpkg/tlpobj/texlive.infra\""
  for a in "$ROOT/bin/*" ; do
    b=`basename $a`
    cp -a bin/$b "$ROOT/bin/"
    tlpobjs="$tlpobjs \"$ROOT/tlpkg/tlpobj/bin-texlive.$b\" \"$ROOT/tlpkg/tlpobj/texlive.infra.$b\""
  done
else
  # could be made more intelligent
  echo "Cannot find root, please call the .run script with --noexec --keep and"
  echo "then call the runme.sh script in the unpacked directory with the"
  echo "root as the first argument, i.e., someting like"
  echo "    sh runme.sh /your/path/to/the/texlive/installaton/2008"
  exit 1
fi

echo tlmgr _include_tlpobj $tlpobjs

EOF

  close(RUN);
  `chmod ugo+x "$tmpdir/runme.sh"`;

  `makeself "$tmpdir" update-texlive-${rev}.run \"TeX Live Manager Updater ${rev}\" ./runme.sh`;

  return(0);
}


__END__

=head1 NAME

tl-create-makeself - creates a .run file for bin-texlive and texlive.infra

=head1 SYNOPSIS

tl-create-makeself [OPTION]...

=head1 OPTIONS

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

There should be an option for the destination of the .run file.

=head1 DESCRIPTION

Creates an updater for Unix systems for the central TeX Live packages 
using makeself.

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