Add ARM files
[dh-make-perl] / dev / arm / libwww-perl / libwww-perl-5.813 / debian / libwww-perl / usr / bin / lwp-mirror
1 #!/usr/bin/perl -w
2
3 eval 'exec /usr/bin/perl -w -S $0 ${1+"$@"}'
4     if 0; # not running under some shell
5
6 # Simple mirror utility using LWP
7
8 =head1 NAME
9
10 lwp-mirror - Simple mirror utility
11
12 =head1 SYNOPSIS
13
14  lwp-mirror [-v] [-t timeout] <url> <local file>
15
16 =head1 DESCRIPTION
17
18 This program can be used to mirror a document from a WWW server.  The
19 document is only transfered if the remote copy is newer than the local
20 copy.  If the local copy is newer nothing happens.
21
22 Use the C<-v> option to print the version number of this program.
23
24 The timeout value specified with the C<-t> option.  The timeout value
25 is the time that the program will wait for response from the remote
26 server before it fails.  The default unit for the timeout value is
27 seconds.  You might append "m" or "h" to the timeout value to make it
28 minutes or hours, respectively.
29
30 Because this program is implemented using the LWP library, it only
31 supports the protocols that LWP supports.
32
33 =head1 SEE ALSO
34
35 L<lwp-request>, L<LWP>
36
37 =head1 AUTHOR
38
39 Gisle Aas <gisle@aas.no>
40
41 =cut
42
43
44 use LWP::Simple qw(mirror is_success status_message $ua);
45 use Getopt::Std;
46
47 $progname = $0;
48 $progname =~ s,.*/,,;  # use basename only
49 $progname =~ s/\.\w*$//; #strip extension if any
50
51 $VERSION = "5.810";
52
53 $opt_h = undef;  # print usage
54 $opt_v = undef;  # print version
55 $opt_t = undef;  # timeout
56
57 unless (getopts("hvt:")) {
58     usage();
59 }
60
61 if ($opt_v) {
62     require LWP;
63     my $DISTNAME = 'libwww-perl-' . LWP::Version();
64     die <<"EOT";
65 This is lwp-mirror version $VERSION ($DISTNAME)
66
67 Copyright 1995-1999, Gisle Aas.
68
69 This program is free software; you can redistribute it and/or
70 modify it under the same terms as Perl itself.
71 EOT
72 }
73
74 $url  = shift or usage();
75 $file = shift or usage();
76 usage() if $opt_h or @ARGV;
77
78 if (defined $opt_t) {
79     $opt_t =~ /^(\d+)([smh])?/;
80     die "$progname: Illegal timeout value!\n" unless defined $1;
81     $timeout = $1;
82     $timeout *= 60   if ($2 eq "m");
83     $timeout *= 3600 if ($2 eq "h");
84     $ua->timeout($timeout);
85 }
86
87 $rc = mirror($url, $file);
88
89 if ($rc == 304) {
90     print STDERR "$progname: $file is up to date\n"
91 }
92 elsif (!is_success($rc)) {
93     print STDERR "$progname: $rc ", status_message($rc), "   ($url)\n";
94     exit 1;
95 }
96 exit;
97
98
99 sub usage
100 {
101     die <<"EOT";
102 Usage: $progname [-options] <url> <file>
103     -v           print version number of program
104     -t <timeout> Set timeout value
105 EOT
106 }