summaryrefslogtreecommitdiff
path: root/Master/tlpkg/bin/tl-update-nsis
blob: 3490924190e45ca9913cc9e8bc758d36710b9ce2 (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
194
#!/usr/bin/env perl
# $Id$
# Copyright 2008-2019 Norbert Preining
# This file is licensed under the GNU General Public License version 2
# or any later version.
# 
# Create a .nsi file for the Windows updates.

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 $opt_help = 0;

TeXLive::TLUtils::process_logging_options();

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

exit (&main ());

sub main {
  chomp(my $Master = `cd $mydir/../.. && pwd`);
  my $tlpdb = TeXLive::TLPDB->new("root" => $Master);
  die("Cannot find tlpdb in $Master\n") unless defined($tlpdb);
  
  my $texliveinfra = $tlpdb->get_package("texlive.infra");
  my $texliveinfraw32 = $tlpdb->get_package("texlive.infra.win32");
  my $texliveinfraw64 = $tlpdb->get_package("texlive.infra.win64");
  my @allfiles = ();
  push(@allfiles, $texliveinfra->all_files);
  push(@allfiles, $texliveinfraw32->all_files) if defined $texliveinfraw32;
  push(@allfiles, $texliveinfraw64->all_files) if defined $texliveinfraw64;
  
  # create the tlpobj files, and directory if necessary.
  my $tlpobjdir = "$InfraLocation/tlpobj";
  my $abs_tlpobjdir = "$Master/$tlpobjdir";
  if (! -d $abs_tlpobjdir) {
    &TeXLive::TLUtils::mkdirhier($abs_tlpobjdir);
  }
  my $rev = 0; # get the highest rev of all our packages
  for my $p ($texliveinfra, $texliveinfraw32, $texliveinfraw64) {
    if (defined $p) {
      if ($p->revision > $rev) {
        $rev = $p->revision;
      }
      open(TMP,">$abs_tlpobjdir/$p->{'name'}.tlpobj")
      || die "open($abs_tlpobjdir/$p->{'name'}.tlpobj) failed: $!";
      $p->writeout(\*TMP);
      close(TMP);
      push(@allfiles, "$tlpobjdir/$p->{'name'}.tlpobj");
    }
  }

  my %dirtofiles;
  for my $f (@allfiles) {
    if ($f !~ m!/!) {
      $f = "./$f";
    }
    my ($dn,$fn) = TeXLive::TLUtils::dirname_and_basename($f);
    if (!defined($dirtofiles{$dn})) {
      @{$dirtofiles{$dn}} = ();
    }
    push @{$dirtofiles{$dn}}, $fn;
  }
  print <<'EOF';
!include "FileFunc.nsh"
!insertmacro GetParent

EOF
  print "!define REV \"r$rev\"\n";

print <<'EOF';

Page directory
Page instfiles

Name "TeX Live Manager Update ${REV}"
OutFile "update-tlmgr-${REV}.exe"
EOF
print "InstallDir \"\$PROGRAMFILES\\texlive\\$TeXLive::TLConfig::ReleaseYear\"\n";

print <<'EOF';

RequestExecutionLevel "user"

DirText "Setup will update the TeX Live Manager of your TeX Live installation in the following folder. \
 To install in a different folder, click Browse and select another folder. \
 Click Install to start the update."

Function .onInit
  SearchPath $0 tlmgr.bat
  ${GetParent} $0 $1
  ${GetParent} $1 $0
  ${GetParent} $0 $1
  ;MessageBox MB_OK "tlmgr=$1"
  StrCpy $INSTDIR $1
  ;SetOutPath $1
FunctionEnd

Function .onVerifyInstDir
  IfFileExists $INSTDIR\tlpkg\texlive.tlpdb PathGood
    Abort
  PathGood:
FunctionEnd

Section "MainGroup"
  #SetOutPath "$INSTDIR"
  #File /r tlupdates\*.*
EOF
  my $mm = $Master;
  $mm =~ s!/!\\!g;
  for my $d (keys %dirtofiles) {
    my $dd = $d;
    $dd =~ s!/!\\!g;
    print "  SetOutPath \"\$INSTDIR\\$dd\"\n";
    for my $f (@{$dirtofiles{$d}}) {
      $f =~ s!/!\\!g;
      print "  File $mm\\$dd\\$f\n";
    }
  }
  # TODO win64 SUPPORT
  print "  ExecWait \'\"\$INSTDIR\\bin\\win32\\tlmgr.bat\" _include_tlpobj";
  for my $p ($texliveinfra, $texliveinfraw32) {
    if (defined $p) {
      print " \"\$INSTDIR\\tlpkg\\tlpobj\\", $p->name, ".tlpobj\"";
    }
  }
  print "'\nSectionEnd\n";
  
  return 0;
}


__END__

=head1 NAME

tl-update-nsis - creates a .nsi file for tlmgr packages

=head1 SYNOPSIS

tl-update-nsis [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.

=head1 DESCRIPTION

Writes, to standard output, a C<.nsi> file that can be used with NSIS to
create an update executable for Windows, to work around Windows'
inability to overwrite open files, and for disaster recovery. It
contains the tlmgr-related infrastructure files.
L<http://tug.org/texlive/tlmgr.html> explains more.

If necessary, this creates a C<.../tlpkg/tlpobj/> subdirectory in the
current hierarchy for C<makensis> to read (so it is not removed).

This is invoked by the C<tl-update-tlcritical> script, along with the
sibling C<tl-makeself-from-tlnet> which creates a similar disaster
recovery executable for Unix.

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