| 1 |
#!/usr/local/bin/perl56 -I/home/systems/syb/work/publisher |
| 2 |
# (C) Copyright 1996-2016 ECMWF. |
| 3 |
# |
| 4 |
# This software is licensed under the terms of the Apache Licence Version 2.0 |
| 5 |
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. |
| 6 |
# In applying this licence, ECMWF does not waive the privileges and immunities |
| 7 |
# granted to it by virtue of its status as an intergovernmental organisation nor |
| 8 |
# does it submit to any jurisdiction. |
| 9 |
|
| 10 |
###!/usr/local/share/perl -I/home/systems/syb/work/publisher |
| 11 |
|
| 12 |
################################################################################### |
| 13 |
# Script modified from davtest.pl, probably originally by Daniel Varela Santoalla. |
| 14 |
# Modifications by Iain Russell, |
| 15 |
# December 2002 |
| 16 |
# |
| 17 |
# Takes one command-line parameter: the name/path of a file to be uploaded. |
| 18 |
# Strange behaviour: it actually requires a dummy command-line parameter |
| 19 |
# to be included after the real one. |
| 20 |
################################################################################### |
| 21 |
|
| 22 |
use strict; |
| 23 |
use HTTP::DAV; |
| 24 |
|
| 25 |
|
| 26 |
# defined these if not intending to supply them through the GUI. |
| 27 |
# If the GUI does supply them (ie if they are specified on the command |
| 28 |
# line), then the hardcoded values will be overridden. |
| 29 |
|
| 30 |
my $username = ""; |
| 31 |
my $password = ""; |
| 32 |
my $bUsernameSupplied = 0; |
| 33 |
my $site = "w3ec2"; |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
################################ |
| 38 |
# Check command-line arguments # |
| 39 |
################################ |
| 40 |
|
| 41 |
# print "Args: $#ARGV\n"; |
| 42 |
|
| 43 |
my $numArgs = $#ARGV + 1; |
| 44 |
|
| 45 |
|
| 46 |
if ($numArgs < 1) |
| 47 |
{ |
| 48 |
print "\nDAV updater.\n"; |
| 49 |
print "Usage: dav.pl [path]<file> [username] [password] [site]\n"; |
| 50 |
exit -1; |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
# has a username & password been supplied? |
| 55 |
|
| 56 |
if ($numArgs >= 3) |
| 57 |
{ |
| 58 |
$username = @ARGV[1]; |
| 59 |
$password = @ARGV[2]; |
| 60 |
$bUsernameSupplied = 1; |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
# how about a site? |
| 65 |
|
| 66 |
if ($numArgs == 4) |
| 67 |
{ |
| 68 |
$site = @ARGV[3]; |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
# filename is the first on the command line |
| 73 |
|
| 74 |
my ($file) = @ARGV[0]; |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
################################## |
| 79 |
# Set up the paths to be updated # |
| 80 |
################################## |
| 81 |
|
| 82 |
my $url; |
| 83 |
my $to; |
| 84 |
|
| 85 |
if ($site eq "w3ec2") |
| 86 |
{ |
| 87 |
$url = "http://w3ec2.ecmwf.int:81/"; |
| 88 |
$to = $url . "/magics/magplus/" . $file; |
| 89 |
} |
| 90 |
|
| 91 |
elsif ($site eq "wedit") |
| 92 |
{ |
| 93 |
$url = "http://wedit.ecmwf.int:81/"; |
| 94 |
$to = $url . "publications/manuals/magics/magplus/" .$file; |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
my $d = HTTP::DAV->new(); |
| 99 |
my $from = $ENV{'PWD'} . "/" . $file; |
| 100 |
|
| 101 |
print ("From: $from\n"); |
| 102 |
print ("To: $to\n"); |
| 103 |
|
| 104 |
################### |
| 105 |
# Upload the file # |
| 106 |
################### |
| 107 |
|
| 108 |
$d->DebugLevel(1); |
| 109 |
|
| 110 |
$d->credentials( -user=>$username,-pass =>$password,-url =>$url); |
| 111 |
$d->open( -url=>"$url" ); |
| 112 |
|
| 113 |
$d->lock( -url=>"$to", -timeout=>"10m" ) |
| 114 |
or die "Won't put unless I can lock\n"; |
| 115 |
|
| 116 |
if ( $d->put( -local=>"$from", -url=>"$to") ) { |
| 117 |
print "$from successfully uploaded to $to\n"; |
| 118 |
} else { |
| 119 |
print "put failed: " . $d->message . "\n"; |
| 120 |
} |
| 121 |
|
| 122 |
$d->unlock( -url=>"$to"); |