summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xMaster/texmf/scripts/texlive/tlmgr.pl152
-rw-r--r--Master/tlpkg/installer/w32_updater.cmd115
-rw-r--r--Master/tlpkg/tlpsrc/bin-texlive.tlpsrc1
3 files changed, 175 insertions, 93 deletions
diff --git a/Master/texmf/scripts/texlive/tlmgr.pl b/Master/texmf/scripts/texlive/tlmgr.pl
index e4416a65418..f7b3b70ccbc 100755
--- a/Master/texmf/scripts/texlive/tlmgr.pl
+++ b/Master/texmf/scripts/texlive/tlmgr.pl
@@ -1123,110 +1123,72 @@ sub action_backup {
}
#
-sub grow_w32_updater {
- my ($pkg, $opt_dry) = @_;
- my $updater_string = '';
- # these packages cannot be upgrade on w32
- # so we have to create a update program
+sub write_w32_updater {
+ my ($opt_dry, @w32_updates) = @_;
my $media = $tlmediasrc->media;
my $mediatlpdb = $tlmediasrc->tlpdb;
- my $mediatlp = $mediatlpdb->get_package($pkg);
# we have to download/copy also the src/doc files if necessary!
my $container_src_split = $mediatlpdb->config_src_container;
my $container_doc_split = $mediatlpdb->config_doc_container;
# get options about src/doc splitting from $totlpdb
+ # TT: should we local options to decide about install of doc & src?
my $opt_src = $localtlpdb->option_install_srcfiles;
- # we do install documenation files for category Documentation even if option_install_docfiles is false
- my $opt_doc = ($mediatlp->category =~ m/documentation/i) ? 1 : $localtlpdb->option_install_docfiles;
- my $do_src = ($container_src_split && $opt_src && $mediatlp->srcfiles) ? 1 : 0;
- my $do_doc = ($container_doc_split && $opt_doc && $mediatlp->docfiles) ? 1 : 0;
- my $temp = $localtlpdb->root . "/temp";
+ my $opt_doc = $localtlpdb->option_install_docfiles;
+ my $root = $localtlpdb->root;
+ my $temp = "$root/temp";
+ my $repo = $mediatlpdb->root . "/$Archive";
TeXLive::TLUtils::mkdirhier($temp);
if ($media eq 'DVD') {
tlwarn ("Creating updater from DVD currently not implemented!\n");
tlwarn ("But it should not be necessary!\n");
- } else {
- my $oldrev = $localtlpdb->get_package($pkg)->revision;
- my $newrev = $mediatlp->revision;
- my $repo = $mediatlpdb->root . '/'. $Archive;
- my @do_one_args = ($oldrev, $newrev, $repo, $temp, $opt_dry);
- $updater_string .= do_one_pkg($pkg, @do_one_args);
- $updater_string .= do_one_pkg("$pkg.src", @do_one_args) if ($do_src);
- $updater_string .= do_one_pkg("$pkg.doc", @do_one_args) if ($do_doc);
- }
- return $updater_string;
- sub do_one_pkg {
- my ($pkg, $oldrev, $newrev, $repo, $temp, $opt_dry) = @_;
- my $updater_string = '';
- my $update_info = "update: $pkg ($oldrev -^> $newrev)";
+ return 1; # abort
+ }
+ my ($mediatlp, $localtlp, $opt_real_doc, $sysret, $size, $md5, $fullname,
+ $oldrev, $newrev, $pkg_part, @pkg_parts, @updater_args);
+ foreach my $pkg (@w32_updates) {
+ $mediatlp = $mediatlpdb->get_package($pkg);
+ $localtlp = $localtlpdb->get_package($pkg);
+ $oldrev = $localtlp->revision;
+ $newrev = $mediatlp->revision;
+ # we do install documenation files for category Documentation even if option_install_docfiles is false
+ $opt_real_doc = ($mediatlp->category =~ m/documentation/i) ? 1 : $opt_doc;
+ @pkg_parts = ($pkg);
+ push(@pkg_parts, "$pkg.src") if ($container_src_split && $opt_src && $mediatlp->srcfiles);
+ push(@pkg_parts, "$pkg.doc") if ($container_doc_split && $opt_real_doc && $mediatlp->docfiles);
if ($opt_dry) {
- $update_info =~ s/\^//; # get rid of the batch escape char
- info("$update_info\n");
- } elsif ($tlmediasrc->media eq 'CD') {
- copy("$repo/$pkg.tar.lzma", "$temp");
- } else { # net
- TeXLive::TLUtils::download_file("$repo/$pkg.tar.lzma", "$temp/$pkg.tar.lzma");
- }
- # now we should have the file present
- if (!$opt_dry && ! -r "$temp/$pkg.tar.lzma") {
- tlwarn ("Couldn't get $pkg.tar.lzma, that is bad\n");
- } else {
- # add lines to the updater script string
- $updater_string = "
-tlpkg\\installer\\lzma\\lzmadec.win32.exe < temp\\$pkg.tar.lzma > temp\\$pkg.tar
-tlpkg\\installer\\tarsave.exe -x -f temp\\$pkg.tar
-tlpkg\\tlperl\\bin\\perl.exe texmf\\scripts\\texlive\\tlmgr.pl _include_tlpobj tlpkg\\tlpobj\\$pkg.tlpobj
-echo $update_info
->>%logdir%tlmgr.log echo [%date% %time%] $update_info
-del temp\\$pkg.tar.lzma temp\\$pkg.tar
-";
+ info("update: $pkg ($oldrev -> $newrev)\n");
+ next;
}
- return $updater_string;
- }
-}
-
-sub write_w32_updater {
- #TODO: think of some way to validate the update
- my $updater_string = shift;
- # assemble the updater script string
- $updater_string = <<'EOF'
-@echo off
-rem Update script for TeX Live infrastructure
-rem called automatically after creation by tlmgr.bat wrapper
-rem left only for inspection, can be safely removed
-
-setlocal
-cd /d %~dp0
-rem now we are in .../tlpkg/installer
-rem create tar.exe backup
->nul copy tar.exe tarsave.exe
-cd ..\..
-rem now we are in the root
-rem get location of the log file
-for /f "delims=" %%D in ('kpsewhich -var-value=TEXMFSYSVAR') do set "logdir=%%~fD\web2c\"
-rem set up perl environment
-set PERL5LIB=%cd%\tlpkg\tlperl\lib
-
-echo Do not close this window! TeX Live infrastructure update in progress...
-echo In case of a disaster download and run:
-echo http://mirror.ctan.org/systems/texlive/tlnet/2008/update-tlmgr-latest.exe
-EOF
-
-. $updater_string . <<'EOF'
-
-del tlpkg\installer\tarsave.exe
-rem Before we can enable self-delete, we need to validate the update somehow.
-rem start /b cmd /c del "%%~f0"
-EOF
-;
- # write the updater script to file
- open UPDATER, ">" . $localtlpdb->root . "/tlpkg/installer/updater"
- or die "Cannot create updater: $!";
- print UPDATER $updater_string;
+ foreach $pkg_part (@pkg_parts) {
+ if ($media eq 'CD') {
+ copy("$repo/$pkg_part.tar.lzma", "$temp");
+ } else { # net
+ TeXLive::TLUtils::download_file("$repo/$pkg_part.tar.lzma", "$temp/$pkg_part.tar.lzma");
+ }
+ # now we should have the file present
+ if (!-r "$temp/$pkg_part.tar.lzma") {
+ tlwarn ("Couldn't get $pkg_part.tar.lzma, that is bad\n");
+ return 1; # abort
+ }
+ # unpack lzma archive
+ $sysret = system("$root/tlpkg/installer/lzma/lzmadec.win32.exe < \"$temp/$pkg_part.tar.lzma\" > \"$temp/$pkg_part.tar\"");
+ return 1 if $sysret; # unpack failed? abort
+ unlink("$temp/$pkg_part.tar.lzma"); # we don't need that archive anymore
+ push @updater_args, $pkg_part, $oldrev, $newrev;
+ }
+ # create backup
+ ($size, $md5, $fullname) = $localtlp->make_container("tar", $root, $temp, "__BACKUP_$pkg.r$oldrev");
+ if ($size <= 0) {
+ tlwarn("Creation of backup container of $pkg failed.\n");
+ return 1; # backup failed? abort
+ }
+ }
+ return 0 if ($opt_dry); # nothing else to do
+ # write the updater script file
+ open UPDATER, ">$root/tlpkg/installer/updater" or die "Cannot create updater: $!";
+ print UPDATER 'call %~dp0w32_updater ' . join(' ',@updater_args);
close UPDATER;
- # tlwarn("UPDATER script has been created:\n");
- # tlwarn(" " . $localtlpdb->root . "\\tlpkg\\installer\\updater.bat\n");
- # print STDOUT $updater_string;
+ return 0;
}
@@ -1605,7 +1567,7 @@ sub action_update {
}
#
- my $w32_updater = '' if win32();
+ my @w32_updates if win32();
foreach my $pkg (sort @updated) {
next if ($pkg =~ m/^00texlive/);
my $tlp = $localtlpdb->get_package($pkg);
@@ -1640,7 +1602,8 @@ sub action_update {
}
if (win32() && ($pkg =~ m/$WinSpecialUpdatePackagesRegexp/)) {
- $w32_updater .= grow_w32_updater($pkg, $opts{"dry-run"});
+ # collect all infrastructure packages for later processing
+ push @w32_updates, $pkg;
} else {
if ($::machinereadable) {
machine_line($pkg, $FLAG_UPDATE, $rev, $mediarev, $sizes{$pkg});
@@ -1725,7 +1688,10 @@ sub action_update {
}
# that already checks whether we actually have to do something
- write_w32_updater($w32_updater) if (win32() && $w32_updater && !$opts{"dry-run"});
+ if (win32()) {
+ my $ret = write_w32_updater($opts{"dry-run"} || $opts{"list"}, @w32_updates);
+ tlwarn ("Aborting infrastructure update.\n") if ($ret);
+ }
if (($nrupdated == 0) && ($tlmediasrc->media ne "NET") && $opts{"all"}) {
# for all but net updates we warn if nothing is updated
tlwarn("\nNothing to update.\n");
diff --git a/Master/tlpkg/installer/w32_updater.cmd b/Master/tlpkg/installer/w32_updater.cmd
new file mode 100644
index 00000000000..781f035b50a
--- /dev/null
+++ b/Master/tlpkg/installer/w32_updater.cmd
@@ -0,0 +1,115 @@
+@echo off
+rem Update script for TeX Live infrastructure
+rem called automatically if detected by tlmgr launcher
+rem
+rem Copyright 2009 by Tomasz M. Trzeciak <t.m.trzeciak@googlemail.com>
+rem Public Domain
+rem
+
+rem make environment changes local & enable cmd extensions
+2>nul verify nonzero_errorlevel
+setlocal enableextensions
+if not errorlevel 1 goto :begin
+>&2 echo CMD.EXE extensions not available. Aborting...
+exit /b 1
+
+:begin
+rem let's make sure that we can use dynamic variables
+set "errorlevel="
+set "date="
+set "time="
+rem get root location
+for /f "delims=" %%D in ('kpsewhich -var-value=SELFAUTOPARENT') do set "TLROOT=%%~fD"
+rem get location of the log file
+for /f "delims=" %%D in ('kpsewhich -var-value=TEXMFSYSVAR') do set "logdir=%%~fD\web2c\"
+rem cd to root
+cd /d "%TLROOT%"
+rem create tar.exe backup
+>nul copy /y "%~dp0tar.exe" "%~dp0tarsave.exe"
+rem set up perl environment
+set "PERL5LIB=%TLROOT%\tlpkg\tlperl\lib"
+rem get package list from arguments
+set pkglist=%*
+if not defined pkglist goto :finish
+
+echo DO NOT CLOSE THIS WINDOW!
+echo TeX Live infrastructure update in progress...
+call :foreachpkg :untar "temp\" %pkglist% || goto :rollback
+call :foreachpkg :tlobj "tlpkg\tlpobj\" %pkglist% || goto :rollback
+set pkglist=& call :foreachpkg :filter_src_doc "" %pkglist%
+call :foreachpkg :update_info "" %pkglist%
+echo Update complete.
+set exitcode=0
+goto :finish
+
+:rollback
+set pkglist=& call :foreachpkg :filter_src_doc "" %pkglist%
+call :foreachpkg :update_info ">&2" %pkglist%
+>&2 echo Update failed! Rolling back to previous version...
+call :foreachpkg :untar "temp\__BACKUP_" %pkglist% || goto :panic
+call :foreachpkg :tlobj "tlpkg\tlpobj\" %pkglist% || goto :panic
+call :foreachpkg :restore_info "" %pkglist%
+echo Recovery from backup successful.
+ >temp\popup.vbs echo MsgBox "TeX Live infrastructure update failed." ^& Chr(10) ^& _
+>>temp\popup.vbs echo "Recovery from backup succeeded.", _
+>>temp\popup.vbs echo 48, "TeX Live update"
+start /wait wscript temp\popup.vbs
+del temp\popup.vbs
+set exitcode=1
+goto :finish
+
+:finish
+del tlpkg\installer\tarsave.exe temp\__BACKUP_*
+rem start /b cmd /c del "%~f0" & exit /b 0
+exit /b %exitcode%
+
+:panic
+call :foreachpkg :restore_info ">&2" %pkglist%
+>&2 echo FATAL ERROR: recovery from backup failed!
+echo To repair your TeX Live installation download and run:
+echo http://mirror.ctan.org/systems/texlive/tlnet/2008/update-tlmgr-latest.exe
+ >temp\popup.vbs echo MsgBox "TeX Live infrastructure update failed and so did recovery from backup." ^& Chr(10) ^& _
+>>temp\popup.vbs echo "To repair your TeX Live installation download and run:" ^& Chr(10) ^& _
+>>temp\popup.vbs echo "http://mirror.ctan.org/systems/texlive/tlnet/2008/update-tlmgr-latest.exe", _
+>>temp\popup.vbs echo 16, "FATAL ERROR: TeX Live update"
+start /wait wscript temp\popup.vbs
+del temp\popup.vbs
+rem Evil has taken over - emit adequate exit code
+exit /b 666
+
+REM SUBROUTINES
+
+:foreachpkg cmd prefix [pkg_name oldrev newrev [...]]
+if [%3]==[] exit /b 0
+call %~1 %2 %3 %4 %5
+if errorlevel 1 exit /b %errorlevel%
+shift /3 & shift /3 & shift /3
+goto :foreachpkg
+
+:untar temp\[__BACKUP_] pkg_name
+set "ext=tar"
+if %~n1_==__BACKUP__ set "ext=r%~3.tar"
+tlpkg\installer\tarsave.exe -x -f "%~1%~2.%ext%" && del "%~1%~2.%ext%"
+exit /b %errorlevel%
+
+:tlobj tlpkg\tlpobj\ pkg_name
+tlpkg\tlperl\bin\perl.exe texmf\scripts\texlive\tlmgr.pl _include_tlpobj "%~1%~2.tlpobj"
+exit /b %errorlevel%
+
+:filter_src_doc
+if /i %~x2.==.src. exit /b 0
+if /i %~x2.==.doc. exit /b 0
+set pkglist=%pkglist% %2 %3 %4
+exit /b 0
+
+:update_info redir pkg_name oldrev newrev
+set "infomsg=update: %~2 (%~3 -^> %~4)"
+goto :continue_info
+:restore_info redir pkg_name oldrev newrev
+set "infomsg=restore: %~2 (%~3)"
+:continue_info
+rem exit /b 0
+if "%~1"==">&2" set "infomsg=failed %infomsg%
+rem >>%logdir%tlmgr.log echo [%date% %time%] %infomsg%
+%~1 echo %infomsg%
+exit /b 0
diff --git a/Master/tlpkg/tlpsrc/bin-texlive.tlpsrc b/Master/tlpkg/tlpsrc/bin-texlive.tlpsrc
index 6d7ab2034a8..3358cf8e562 100644
--- a/Master/tlpkg/tlpsrc/bin-texlive.tlpsrc
+++ b/Master/tlpkg/tlpsrc/bin-texlive.tlpsrc
@@ -24,3 +24,4 @@ binpattern f bin/${ARCH}/tlmgr
binpattern f bin/${ARCH}/rungs
binpattern f bin/win32/tl-w32-wrapper.texlua
binpattern f bin/win32/symlinks4cygwin.sh
+binpattern f/win32 tlpkg/installer/w32_updater.cmd