pakfire: Allow pinning Pakfire to one mirror server

Message ID 20211014190149.20704-1-michael.tremer@ipfire.org
State Accepted
Commit ec18a1ecae60c6c3b6418e300aebd6a823844c8d
Headers
Series pakfire: Allow pinning Pakfire to one mirror server |

Commit Message

Michael Tremer Oct. 14, 2021, 7:01 p.m. UTC
  This patch adds a new $mirror option to the configuration file which
will cause Pakfire to only use this one to download any files.

This feature is disabled by default but useful for development.

Fixes: #12706
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
---
 src/pakfire/lib/functions.pl | 12 ++++++++++++
 src/pakfire/pakfire.conf     |  3 +++
 2 files changed, 15 insertions(+)
  

Patch

diff --git a/src/pakfire/lib/functions.pl b/src/pakfire/lib/functions.pl
index f46c9acc1..4d9854a6f 100644
--- a/src/pakfire/lib/functions.pl
+++ b/src/pakfire/lib/functions.pl
@@ -30,6 +30,7 @@  use HTTP::Headers;
 use HTTP::Message;
 use HTTP::Request;
 use Net::Ping;
+use URI;
 
 use Switch;
 
@@ -297,6 +298,17 @@  sub valid_signature($) {
 }
 
 sub selectmirror {
+	if (defined ${Conf::mirror}) {
+		my $uri = URI->new("${Conf::mirror}");
+
+		# Only accept HTTPS mirrors
+		if ($uri->scheme eq "https") {
+			return ("HTTPS", $uri->host, $uri->path . "/" . ${Conf::version});
+		} else {
+			message("MIRROR ERROR: Unsupported mirror: " . ${Conf::mirror});
+		}
+	}
+
 	### Check if there is a current server list and read it.
 	#   If there is no list try to get one.
 	my $count = 0;
diff --git a/src/pakfire/pakfire.conf b/src/pakfire/pakfire.conf
index 9930f3771..bc54dcff4 100644
--- a/src/pakfire/pakfire.conf
+++ b/src/pakfire/pakfire.conf
@@ -23,6 +23,9 @@  package Conf;
 
 $mainserver = "pakfire.ipfire.org";
 
+# Only use this mirror
+#$mirror = "https://mirror1.ipfire.org/pakfire2";
+
 $cachedir = "/opt/pakfire/cache";
 $dbdir = "/opt/pakfire/db";
 $coredir = "/opt/pakfire/db/core";