-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathurpm-downloader.pl
124 lines (114 loc) · 3.05 KB
/
urpm-downloader.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/perl -w
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Copyright: 2012 by Matteo Pasotti <[email protected]>
use strict;
use warnings;
use diagnostics;
use Term::ANSIColor qw(:constants);
use Getopt::Long qw(:config permute);
use urpmex::Urpmex;
my $PKG_QUERYMAKER = "urpmq";
my $QUERY_LISTMEDIA_PARM = "--list-media";
my $QUERY_LISTURL_PARM = "--list-url";
my $QUERY_LOOKFORSRPM_PARM = "--sourcerpm";
my $DLDER = "--wget";
my $use_wget = 0; # false
my $use_axel = 0; # false
my $dl_srpm = 0; # false
my $use_major = 0; # false
my @pacchetti;
sub process_args {
my $pkg = shift;
#print "$pkg\n";
push @pacchetti, $pkg;
}
my $result = GetOptions ("wget" => \$use_wget,
"axel" => \$use_axel,
"source" => \$dl_srpm,
'<>' => \&process_args,
"major" => \$use_major);
sub main {
my $pkg = "";
my @media_urls=retrieve_active_media_urls($dl_srpm);
if(scalar(@pacchetti) gt 0){
for $pkg(@pacchetti){
my @lista_srpms;
if($dl_srpm){
@lista_srpms = retrieve_srpm_pkgname($pkg);
}else{
@lista_srpms = retrieve_brpm_pkgname($pkg);
}
#print "@lista_srpms\n";
if($use_major){
#print "Using only major version\n";
for(my $i=0;$i<scalar(@lista_srpms)-1;$i++){
shift @lista_srpms;
#print "@lista_srpms\n";
}
}
for my $srpm(@lista_srpms){
$srpm =~s/^\s+//g;
chomp $srpm;
$srpm = $srpm.".rpm" if(!$dl_srpm);
print "Processing $srpm\n";
for my $url(@media_urls){
chomp $url;
my @protocol = split(':',$url);
if($protocol[0] eq "http"){
#print "Protocol: HTTP\n";
#print "Trying $url/$srpm\n";
my $check = `curl -s --head "$url/$srpm" | head -n 1 | grep "200 OK" > /dev/null ; echo \$?`;
chomp $check;
#print "Result: $check\n";
if($check eq "0"){
download($url,$srpm);
last;
}
}elsif($protocol[0] eq "ftp"){
#print "Protocol: FTP\n";
my $check = `curl -s --head "$url/$srpm"`;
$check =~s/\n/ /g;
$check =~s/^\s+//g;
$check =~s/\s+$//g;
if($check ne ""){
download($url,$srpm);
last;
}
}elsif($protocol[0] eq "rsync"){
print "Protocol: RSYNC\n";
}
}
}
}
return 0;
}else{
print "No packages passed as argument\n";
exit(2);
}
}
sub download {
my $url = shift();
my $rpm = shift();
if($use_wget){
`wget "$url/$rpm" -O $rpm`;
}elsif($use_axel){
`axel -a "$url/$rpm" -o $rpm`;
}else{
`curl -s "$url/$rpm" -o $rpm`;
}
}
while(main() eq 1){
}
exit(0);