#!/usr/bin/perl
use
LWP::Simple
qw(mirror is_success status_message $ua)
;
my
$progname
= $0;
$progname
=~ s,.*/,,;
$progname
=~ s/\.\w*$//;
my
%opts
;
unless
(GetOptions(\
%opts
,
'h'
,
'v'
,
't=i'
)) {
usage();
}
if
(
$opts
{v}) {
my
$DISTNAME
=
'libwww-perl-'
.
$LWP::VERSION
;
die
<<"EOT";
This is lwp-mirror version $LWP::Simple::VERSION ($DISTNAME)
Copyright 1995-1999, Gisle Aas.
This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
EOT
}
my
$url
= decode(
locale
=>
shift
) or usage();
my
$file
= encode(
locale_fs
=> decode(
locale
=>
shift
)) or usage();
usage()
if
$opts
{h} or
@ARGV
;
if
(
$opts
{t}) {
if
(
$opts
{t} =~ /^(\d+)([smh])?/) {
my
$timeout
= $1;
$timeout
*= 60
if
($2 eq
"m"
);
$timeout
*= 3600
if
($2 eq
"h"
);
$ua
->timeout(
$timeout
);
}
else
{
die
"$progname: Illegal timeout value!\n"
;
}
}
my
$rc
= mirror(
$url
,
$file
);
if
(
$rc
== 304) {
print
STDERR
"$progname: $file is up to date\n"
;
}
elsif
(!is_success(
$rc
)) {
print
STDERR
"$progname: $rc "
, status_message(
$rc
),
" ($url)\n"
;
exit
1;
}
exit
;
sub
usage {
die
<<"EOT";
Usage: $progname [-options] <url> <file>
-v print version number of program
-t <timeout> Set timeout value
EOT
}