#!/usr/bin/env perl # $Id$ # # Copyright 2008 Reinhard Kotucha, Norbert Preining # This file is licensed under the GNU General Public License version 2 # or any later version. # This script creates the zip (everything) and tgz (omits windows) # archives to do a network install. Invoked from tl-update-tlnet. 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 info); use TeXLive::TLPDB; use TeXLive::TLPOBJ; use Getopt::Long; use Cwd 'abs_path'; $Getopt::Long::autoabbrev=0; $opt_help=0; $opt_verbose=0; $opt_texlivedocs = 0; sub usage { print <<'EOF'; Usage: tl-make-install-pkg [-h|--help] [-v|--verbose] -o|--outputdir=DIR Generate 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. An existing directory must be specified as the output location. Options: -h, --help Print this message and exit. -t, --texlivedocs Include the pdf and html versions of the texlive guide -o, --outputdir Target directory. Must exist and be writable. -v, --verbose Extra messages. EOF ; exit 0; } usage if (@ARGV<1); TeXLive::TLUtils::process_logging_options(); GetOptions( "outputdir|o=s", "texlivedocs|t", "verbose|v", "help|h") or usage; usage if $opt_help; die "$0: extra argument(s) @ARGV; try --help if you need it.\n" if @ARGV; # 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"; die "$0: the output directory must be specified; try --help if you need it.\n" if ! $opt_outputdir; my $outputdir = $opt_outputdir; 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" 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) { info("thisdir: \"$thisdir\"\n"); info("installerdir: \"$installerdir\"\n"); info("sys_tmp: \"$sys_tmp\"\n"); info("tmpdir: \"$tmpdir\"\n"); info("inst_tmp: \"$inst_tmp\"\n"); info("outputdir: \"$outputdir\"\n"); } die "$0: Output directory does not exist: $outputdir.\n" unless -e $outputdir; die "$0: $outputdir not a directory.\n" unless -d $outputdir; die "$0: Output directory not writable: $outputdir.\n" unless -w $outputdir; # read TLPDB and extract files my $tlpdb = TeXLive::TLPDB->new ("root" => $installerdir); die "$0: Cannot find tlpdb in $installerdir.\n" unless defined $tlpdb; my $tlp = $tlpdb->get_package("00texlive.installer"); die "$0: no 00texlive.installer in ${installerdir}'s texlive.tlpdb" unless defined $tlp; my $tlpinfra = $tlpdb->get_package("texlive.infra"); die "$0: no texlive.infra in ${installerdir}'s texlive.tlpdb" unless defined $tlpinfra; my @unix = (); push @unix, $tlp->runfiles; push @unix, grep(!/^texmf\//, $tlpinfra->runfiles); push @unix, $tlp->docfiles; # add the texlive-XX docs in pdf and html format if the option is given. # if ($opt_texlivedocs) { foreach my $p (qw(texlive-en texlive-de texlive-fr texlive-cz texlive-pl texlive-ru texlive-zh-cn)) { my $tlpdocs = $tlpdb->get_package($p); if (!defined $tlpdocs) { warn "Cannot find package $p in tlpdb"; next; } push (@unix, $tlpdocs->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"}}); } # main. copy_files (@unix); make_zip ('tgz'); copy_files (@win32); make_zip ('zip'); install_files (); cleanup (); # 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 files. # sub make_zip { my ($type) = @_; info ("$0: 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_files { $outputdir = abs_path ($outputdir); info ("$0: 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"); # create unpacked installer that can run in that directory, # for the sake of people mirroring. # We'd like to specify exactly what we want to unpack, # but unzip doesn't support recursively unpacking a directory, # and it's too painful to specify all the (many dozens of) files. # So unpack directly in the real dir. Scary. xchdir ($outputdir); # save what we've got now. my $savedir = "/tmp/tluip.$$.save"; xsystem ("rm -rf $savedir"); mkdir ($savedir); xsystem ("mv install-tl install-tl.bat* tlpkg/TeXLive tlpkg/installer $savedir/"); # unpack in a temp directory. my $junkdir = "/tmp/tluip.$$.temp"; xsystem ("rm -rf $junkdir"); mkdir ($junkdir); xsystem ("cd $junkdir && unzip -q $outputdir/install-tl.zip"); # move what we want (corresponds to the mv into savedir) and erase the rest. xsystem ("mv $junkdir/install-tl* ."); xsystem ("mv $junkdir/tlpkg/* tlpkg/"); xsystem ("rm -rf $junkdir"); # if we made this far, we don't need to preserve the previous version. xsystem ("rm -rf $savedir"); } # chdir or die. # sub xchdir { my ($dir) = @_; chdir ($dir) || die "chdir($dir) failed: $!"; #chomp (my $pwd = `pwd`); #print "\t CHDIR $dir (now $pwd)\n"; } # system or die. # sub xsystem { my (@args) = @_; my $retval = system (@args); if ($retval != 0) { $retval /= 256; chomp (my $pwd = `pwd`); die "system(@args) failed in $pwd, status $retval"; } } ### Local Variables: ### perl-indent-level: 2 ### tab-width: 2 ### indent-tabs-mode: nil ### End: # vim:set tabstop=2 expandtab: #