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