source: trunk/gsdl/bin/script/urlcopy.pl@ 1173

Last change on this file since 1173 was 1173, checked in by sjboddie, 24 years ago

added files needed by end-user collection building stuff

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 3.9 KB
Line 
1#!/usr/bin/perl -w
2
3###########################################################################
4#
5# urlcopy.pl --
6# A component of the Greenstone digital library software
7# from the New Zealand Digital Library Project at the
8# University of Waikato, New Zealand.
9#
10# Copyright (C) 1999 New Zealand Digital Library Project
11#
12# This program is free software; you can redistribute it and/or modify
13# it under the terms of the GNU General Public License as published by
14# the Free Software Foundation; either version 2 of the License, or
15# (at your option) any later version.
16#
17# This program is distributed in the hope that it will be useful,
18# but WITHOUT ANY WARRANTY; without even the implied warranty of
19# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20# GNU General Public License for more details.
21#
22# You should have received a copy of the GNU General Public License
23# along with this program; if not, write to the Free Software
24# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25#
26###########################################################################
27
28
29# This program will download the specified urls (http:, ftp: and file:)
30
31BEGIN {
32 die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
33 unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
34
35 unshift (@INC, "$ENV{'GSDLHOME'}/perllib/cpan/lib");
36 $ENV{'PATH'} = "$ENV{'GSDLHOME'}/perllib/cpan/bin:$ENV{'PATH'}";
37}
38
39use util;
40use File::Basename;
41
42sub print_usage
43{
44 print STDERR "\n usage: $0 [urls] collection-name\n\n";
45}
46
47sub main
48{
49 if (scalar(@ARGV)<2)
50 {
51 print_usage();
52 exit(1);
53 }
54
55 my $dirname = pop(@ARGV);
56 my $full_importname
57 = &util::filename_cat($ENV{'GSDLHOME'},"collect",$dirname,"import");
58
59 mkdir ($full_importname, 0777) unless -e $full_importname;
60
61 # split argv into 3 lists: http, ftp and file
62 my (@http,@ftp,@file) = ((),(),());
63 my $a;
64 foreach $a (@ARGV)
65 {
66 $a =~ s/^\"//;
67 $a =~ s/\"$//;
68
69 if ($a =~ m/^http:/i)
70 {
71 push(@http,$a);
72 }
73 elsif ($a =~ m/^ftp:/i)
74 {
75 push(@ftp,$a);
76 }
77 elsif ($a =~ m/^file:/i)
78 {
79 push(@file,$a);
80 }
81 else
82 {
83 print STDERR "URL argument not supported: $a\n";
84 print STDERR "Ingoring argument.\n";
85 }
86 }
87
88 if (scalar(@http)>0)
89 {
90 my $w3mircfg_filename
91 = &util::filename_cat($ENV{'GSDLHOME'},"tmp","$dirname.w3mir");
92
93 # create cfg file
94 open(CFGOUT,">$w3mircfg_filename")
95 || die "Unable to open $w3mircfg_filename: $!";
96 print CFGOUT "Options: recurse\n\n";
97
98 my $first = 1;
99 my $a;
100 foreach $a (@http)
101 {
102 my $src_url = $a;
103 my $dst_dir = $a;
104 $dst_dir =~ s/^http://i;
105 $dst_dir = &util::filename_cat($full_importname,$dst_dir);
106
107 if ($src_url !~ m/\/$/)
108 {
109 # last name is a file => strip off filename
110 $dst_dir = &File::Basename::dirname($dst_dir);
111 }
112 if ($first)
113 {
114 print CFGOUT "URL: $src_url $dst_dir\n";
115 $first = 0;
116 }
117 else
118 {
119 print CFGOUT "Also-queue: $src_url $dst_dir\n";
120 }
121 }
122 print CFGOUT "\nFixup: run\n";
123 close(CFGOUT);
124
125 my $cmd = "cd $full_importname; ";
126 $cmd .= "w3mir.pl -cfgfile $w3mircfg_filename";
127
128 my $status = system($cmd);
129 $status /= 256;
130 if ($status != 0)
131 {
132 print STDERR "An error was encountered executing: $cmd\n";
133 exit($status);
134 }
135 }
136
137 if (scalar(@ftp)>0)
138 {
139 my $cmd = "cd $full_importname; ";
140 $cmd .= "ncftp ";
141 my $a;
142 foreach $a (@ftp)
143 {
144 $a = "$a/" if ($a !~ m/\/$/);
145 $cmd .= " \"$a/*\"";
146 }
147 my $status = system($cmd);
148 $status /= 256;
149 if ($status != 0)
150 {
151 print STDERR "An error was encountered executing: $cmd\n";
152 exit($status);
153 }
154
155 }
156
157 if (scalar(@file)>0)
158 {
159 my $cmd = "filedownload.pl";
160 my $a;
161 foreach $a (@file)
162 {
163 $cmd .= " \"$a\"";
164 }
165 $cmd .= " $dirname";
166
167 my $status = system($cmd);
168 $status /= 256;
169 if ($status != 0)
170 {
171 print STDERR "An error was encountered executing: $cmd\n";
172 exit($status);
173 }
174 }
175
176 return 0;
177}
178
179&main();
180
181
182
183
Note: See TracBrowser for help on using the repository browser.