eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' && eval 'exec perl -S $0 $argv:q' if 0; use strict; $^W=1; # turn warning on # # hyperref_tug.pl # # Copyright (C) 2002, 2009 Heiko Oberdiek. # # This file "hyperref_tug.pl" may be renamed to "hyperref_tug" # for installation purposes. # my $file = "hyperref_tug.pl"; my $program = uc($&) if $file =~ /^\w+/; my $version = "1.2"; my $date = "2009/12/12"; my $author = "Heiko Oberdiek"; my $copyright = "Copyright (c) 2002, 2009 by $author."; # # Reqirements: Perl5 # History: # 2002/03/15 v1.0: First release. # 2002/03/15 v1.1: --clearbeta added. # 2009/12/12 v1.2: Use system's unzip. # my $homedir = "$ENV{'HOME'}/"; # my $bindir = $homedir . "bin/"; # my $unzipcmd = $bindir . "unzip"; my $prg_unzip = 'unzip'; my $hyperrefdir = "/home/httpd/html/applications/hyperref/"; # my $ctandir = "${hyperrefdir}ctan/"; my $ctandir = "/home/ftp/tex/hyperref/"; $| = 1; # autoflush STDOUT ### program identification my $title = "$program $version, $date - $copyright\n"; print $title; ### error strings my $Error = "!!! Error [tug]:"; # error prefix ### parse destination argument @ARGV == 1 or die "$Error --destination or --clearbeta missing!\n"; if ($ARGV[0] =~ /--clearbeta/) { print "*** [tug] Removing beta files ...\n"; my $betadir = "${ctandir}beta"; my @files = glob("$betadir/*"); my $zipfile = "${hyperrefdir}hyperref-beta.zip"; push @files, $zipfile if -f $zipfile; foreach (@files) { next unless -f $_; print " unlinking: $_\n"; unlink($_); } if (-d $betadir) { print " rmdir: $betadir\n"; rmdir $betadir or die "$Error Cannot remove directory!\n"; } print "*** [tug] Ready.\n"; exit 0; } $ARGV[0] =~ /--destination="?(.*)"?/ or die "$Error Syntax error!\n"; my $destination = $1; $destination =~ s|/$||; ### get zip file my $zipname = "hyperref"; $zipname .= "-$destination" unless $destination eq ""; $zipname .= ".zip"; my $zipfile = $homedir . $zipname; print "*** [tug] Receiving ...\n" . " file: $zipfile\n"; open(ZIP, ">$zipfile") or die "$Error Cannot write '$zipfile'!\n"; binmode(ZIP); binmode(STDIN); my $length = 0; while () { print ZIP $_; $length += length($_); print "\r size: $length "; } print "\n"; ### move zip file into hyperref directory my $zipdestfile = $hyperrefdir . $zipname; print "*** [tug] Moving ...\n" . " from: $zipfile\n" . " to: $zipdestfile\n"; system("mv $zipfile $zipdestfile") == 0 or die "$Error Moving zip file '$zipname' failed!\n"; ### checking ctan directory print "*** [tug] Checking ctan destination directory ...\n"; my $ctandest = $ctandir . $destination; $ctandest .= "/" unless $ctandest =~ /\/$/; -d $ctandir or mkdir($ctandir); -d $ctandest or mkdir($ctandest); ### remove ctan files print "*** [tug] Removing files ...\n" . " directory: $ctandest\n"; my @cleanlist = glob("${ctandest}*"); foreach(@cleanlist) { next unless -f $_; print " unlinking: $_\n"; unlink($_); } ### unzipping ctan files print "*** [tug] Unzipping ...\n" . " destination directory: $ctandest\n"; system("$prg_unzip $zipdestfile -d $ctandest") == 0 or die "$Error Unzipping ctan files failed!\n"; print "*** [tug] Ready.\n"; 0; __END__