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_upload.pl # # Copyright (C) 2002, 2010 Heiko Oberdiek. # # This file "hyperref_upload.pl" may be renamed to "hyperref_upload" # for installation purposes. # my $file = "hyperref_upload.pl"; my $program = uc($&) if $file =~ /^\w+/; my $version = "1.2"; my $date = "2010/02/08"; my $author = "Heiko Oberdiek"; my $copyright = "Copyright (c) 2002, 2010 by $author."; # # Reqirements: Perl5 # History: # 2002/03/15 v1.0: First release. # 2002/03/15 v1.1: Options --help, --tug, --beta, --clearbeta added. # 2010/02/08 v1.2: Adaptation to changed repository. # my $xmlfile = "files.xml"; my $tempzipfile = "/tmp/\L$program\E_$$.zip"; my $zipcmd = "zip -9"; my $sshcmd = "ssh tug"; my $tugscript = "hyperref_tug"; my $tugcmd = "~/bin/$tugscript"; my $tugfrom = $0; $tugfrom =~ s/hyperref_upload/$tugscript/; my $tugto = "tug:bin/$tugscript"; my $tuguploadcmd = "scp $tugfrom $tugto"; my $clearbetacmd = "ssh tug '$tugcmd --clearbeta'"; ### program identification my $title = "$program $version, $date - $copyright\n"; ### error strings my $Error = "!!! Error:"; # error prefix ### option variables my @bool = ("false", "true"); $::opt_help = 0; $::opt_beta = 0; $::opt_clearbeta = 0; $::opt_tug = 0; my $usage = <<"END_OF_USAGE"; ${title}Syntax: \L$program\E [options] Function: Uploads files in the current directory to the tug server. The files are selected according to "$xmlfile" in the current directory. Options: --help print usage --beta only files, marked as beta are uploaded into the beta directory at the tug server ($bool[$::opt_beta]) --clearbeta remove beta files from tug server ($bool[$::opt_clearbeta]) --tug uploads tug script "$tugscript" ($bool[$::opt_tug]) END_OF_USAGE ### process options use Getopt::Long; GetOptions( "help!", "beta!", "clearbeta!", "tug!" ) or die $usage; !$::opt_help or die $usage; @ARGV == 0 or die $usage; print $title; ### signals $SIG{__DIE__} = \&clean; $SIG{'HUP'} = \&clean; $SIG{'INT'} = \&clean; $SIG{'QUIT'} = \&clean; $SIG{'TERM'} = \&clean; ### upload tug script if ($::opt_tug) { print "*** Uploading tug server script ...\n" . " from: $tugfrom\n" . " to: $tugto\n"; system($tuguploadcmd) == 0 or die "$Error Upload of $tugscript failed!\n"; print "*** Ready.\n"; exit 0; } ## remove beta files from tug server if ($::opt_clearbeta) { print "*** Remove beta files from tug server ...\n"; system($clearbetacmd) == 0 or die "$Error Removing beta files failed!\n"; print "*** Ready.\n"; exit 0; } ### scan xml file my $destination = ""; my $destination_ok = 0; my @files = (); if ($::opt_beta) { $destination = "beta"; $destination_ok = 1; } open(XML, $xmlfile) or die "$Error Cannot open '$xmlfile'!\n"; while () { if (!$::opt_beta and //) { $destination = $1; $destination =~ s|/$||; $destination_ok = 1; } if (/ not found!\n"; ### generate temp zip file print "*** Zipping files ...\n"; unlink($tempzipfile); system("$zipcmd $tempzipfile @files") == 0 or die "$Error Generating of zip file fails!\n"; -f $tempzipfile or die "$Error Zip file is not created!\n"; my $size = (stat($tempzipfile))[7]; print " file: $tempzipfile\n" . " dest: $destination\n" . " size: $size\n"; ### uploading print "*** Uploading zip file to tug server ...\n"; system("cat $tempzipfile | " . "$sshcmd '$tugcmd --destination=\"$destination\"'") == 0 or die "$Error Uploading failed!\n"; ### cleaning sub clean { -f $tempzipfile and unlink $tempzipfile; } clean(); print "*** Ready.\n"; __END__