ソースを参照

teach --fetch to honor proxy settings

Michael van Elst 22 年 前
コミット
9dc49f9751
2 ファイル変更49 行追加10 行削除
  1. 1 1
      openpkg/openpkg.spec
  2. 48 9
      openpkg/rpmx.pl

+ 1 - 1
openpkg/openpkg.spec

@@ -39,7 +39,7 @@
 #   o any cc(1)
 
 #   the package version/release
-%define       V_openpkg 20030417
+%define       V_openpkg 20030422
 
 #   the used software versions
 %define       V_rpm     4.0.2

+ 48 - 9
openpkg/rpmx.pl

@@ -77,13 +77,17 @@ foreach $var (qw(
     l_fetch_mirror_5 l_fetch_mirror_6 l_fetch_mirror_7 l_fetch_mirror_8 l_fetch_mirror_9 
     l_fetch_backup_0 l_fetch_backup_1 l_fetch_backup_2 l_fetch_backup_3 l_fetch_backup_4 
     l_fetch_backup_5 l_fetch_backup_6 l_fetch_backup_7 l_fetch_backup_8 l_fetch_backup_9 
+    _httpproxy _httpport
+    _ftpproxy _ftpport
 )) {
     $vars .= "${var}=\%{${var}};";
 }
 my @assign = split(/;/, `$CFG->{PRG}->{"rpm"} --eval '$vars'`);
 foreach $assign (@assign) {
     if ($assign =~ m|^(\S+)=(.*)$|s) {
-        $CFG->{RC}->{$1} = $2;
+	if ($2 ne '%{'.$1.'}') {
+        	$CFG->{RC}->{$1} = $2;
+	}
     }
 }
 
@@ -94,13 +98,27 @@ foreach $assign (@assign) {
 #print "\n";
 my $op = 'pass';
 my $isopt = 1;
+my $isdef = 0;
 my $optname = '';
 my $arg;
 foreach $arg (@ARGV) {
+    if ($isdef) {
+	if ($arg =~ /^(\S+)\s*(.+)/) {
+		$CFG->{RC}->{$1} = $2;
+	} else {
+        	print STDERR "rpm: invalid macro definition '$arg'\n";
+	}
+	$isdef = 0;
+	next;
+    }
     if ($arg =~ m/^--(stowaway|makeindex|update|fetch|makeproxy|repo|smart)$/) {
         $op = $1;
         next;
     }
+    if ($arg eq '--define') {
+	$isdef = 1;
+	next;
+    }
     if ($arg eq '--') {
         $isopt = 0;
         next;
@@ -226,14 +244,35 @@ sub fetch_url {
         return "invalid URL - only file, http and ftp schemes supported";
     }
 
-    #   try to fetch the URL
-    unlink("$dst.hdr");
-    $rc = system($CFG->{PRG}->{"curl"} .
-                 " --location" .
-                 " --max-time 1800" .
-                 " --connect-timeout 20" .
-                 " --dump-header $dst.hdr" .
-                 " --output '$dst' '$src'");
+    {
+	my($hpxy) = $CFG->{RC}->{"_httpproxy"};
+	my($hprt) = $CFG->{RC}->{"_httpport"};
+	my($fpxy) = $CFG->{RC}->{"_ftpproxy"};
+	my($fprt) = $CFG->{RC}->{"_ftpport"};
+
+	$hprt = 80 unless $hprt > 0;
+	$fprt = 21 unless $fprt > 0;
+
+	if (defined $hpxy && defined $hprt) {
+		$hpxy .= ":$hprt";
+	}
+	if (defined $fpxy && defined $fprt) {
+		$fpxy .= ":$fprt";
+	}
+
+	local($ENV{'http_proxy'}) = $hpxy;
+	local($ENV{'ftp_proxy'}) = $fpxy;
+
+	#   try to fetch the URL
+	unlink("$dst.hdr");
+	$rc = system($CFG->{PRG}->{"curl"} .
+	             " --location" .
+	             " --max-time 1800" .
+	             " --connect-timeout 20" .
+	             " --dump-header $dst.hdr" .
+	             " --output '$dst' '$src'");
+
+    }
 
     #   check whether command failed
     if ($rc != 0) {