[1/8] pakfire: Automatically compose $version

Message ID 20200211142853.8561-2-michael.tremer@ipfire.org
State Accepted
Commit e6f4991be209040f436d9be23b414a6dda1e7fa5
Headers
Series [1/8] pakfire: Automatically compose $version |

Commit Message

Michael Tremer Feb. 11, 2020, 2:28 p.m. UTC
  The tree in which pakfire is looking for packages and Core Updates
has been hardcoded into /opt/pakfire/etc/pakfire.conf.

This patch adds a new function which reads the system release
from /etc/system-release.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
---
 src/pakfire/lib/functions.pl | 41 ++++++++++++++++++++++++++++++++++++
 src/pakfire/pakfire.conf     |  2 --
 2 files changed, 41 insertions(+), 2 deletions(-)
  

Patch

diff --git a/src/pakfire/lib/functions.pl b/src/pakfire/lib/functions.pl
index 61787757e..cda6f00a9 100644
--- a/src/pakfire/lib/functions.pl
+++ b/src/pakfire/lib/functions.pl
@@ -70,6 +70,9 @@  my $bfile;
 my %pakfiresettings = ();
 &General::readhash("${General::swroot}/pakfire/settings", \%pakfiresettings);
 
+# Make version
+$Conf::version = &make_version();
+
 sub message {
 	my $message = shift;
 		
@@ -946,4 +949,42 @@  sub status {
 	exit 1;
 }
 
+sub get_arch() {
+	# Append architecture
+	my ($sysname, $nodename, $release, $version, $machine) = POSIX::uname();
+
+	# We only support armv5tel for all 32 bit arches
+	if ($machine =~ m/armv[567]/) {
+		return "armv5tel";
+
+	# We only support i586 for 32 bit x86
+	} elsif ($machine =~ m/i[0-9]86/) {
+		return "i586";
+	}
+
+	return $machine;
+}
+
+sub make_version() {
+	my $version = "";
+
+	# Open /etc/system-release
+	open(RELEASE, "</etc/system-release");
+	my $release = <RELEASE>;
+	close(RELEASE);
+
+	# Add the main relase
+	if ($release =~ m/IPFire ([\d\.]+)/) {
+		$version .= $1;
+	}
+
+	# Append architecture
+	my $arch = &get_arch();
+	if ($arch ne "i586") {
+		$version .= "-${arch}";
+	}
+
+	return $version;
+}
+
 1;
diff --git a/src/pakfire/pakfire.conf b/src/pakfire/pakfire.conf
index cfe48f575..9930f3771 100644
--- a/src/pakfire/pakfire.conf
+++ b/src/pakfire/pakfire.conf
@@ -21,8 +21,6 @@ 
 
 package Conf;
 
-$version = "@VERSION@";
-
 $mainserver = "pakfire.ipfire.org";
 
 $cachedir = "/opt/pakfire/cache";