diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2015-04-16 13:29:17 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2015-04-16 13:29:17 +0000 |
commit | d450dcd06c086187394ee3bcd4ba8fa73b5d37e1 (patch) | |
tree | c453ebcdfadb2eb319ab212ee333d5150739e23a /usr.sbin/pkg_add | |
parent | 840b2f4ba7a4034058cb98b6bf6be0881f32c070 (diff) |
reorg code, the arch/osversion code should live in a single place,
short and sweet
Diffstat (limited to 'usr.sbin/pkg_add')
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/FwUpdate.pm | 14 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/PackageRepository/Installed.pm | 33 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/PackingElement.pm | 21 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Paths.pm | 56 |
4 files changed, 69 insertions, 55 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/FwUpdate.pm b/usr.sbin/pkg_add/OpenBSD/FwUpdate.pm index efb023aff01..8403c858719 100644 --- a/usr.sbin/pkg_add/OpenBSD/FwUpdate.pm +++ b/usr.sbin/pkg_add/OpenBSD/FwUpdate.pm @@ -1,7 +1,7 @@ #! /usr/bin/perl # ex:ts=8 sw=4: -# $OpenBSD: FwUpdate.pm,v 1.17 2015/02/15 09:54:21 espie Exp $ +# $OpenBSD: FwUpdate.pm,v 1.18 2015/04/16 13:29:16 espie Exp $ # # Copyright (c) 2014 Marc Espie <espie@openbsd.org> # @@ -28,15 +28,9 @@ our @ISA = qw(OpenBSD::PkgAdd::State); sub find_path { my $state = shift; - open my $cmd, '-|', OpenBSD::Paths->sysctl, '-n', 'kern.version'; - my $line = <$cmd>; - close($cmd); - if ($line =~ m/^OpenBSD (\d\.\d)(\S*)\s/) { - my ($version, $tag) = ($1, $2); - if ($tag eq '-current') { - $version = 'snapshots'; - } - $state->{path} = "http://firmware.openbsd.org/firmware/$version/"; + my $dir = OpenBSD::Paths->os_directory; + if (defined $dir) { + $state->{path} = "http://firmware.openbsd.org/firmware/$dir/"; } else { $state->fatal("Couldn't find/parse OS version"); } diff --git a/usr.sbin/pkg_add/OpenBSD/PackageRepository/Installed.pm b/usr.sbin/pkg_add/OpenBSD/PackageRepository/Installed.pm index 87e87e9681e..de0dff231c3 100644 --- a/usr.sbin/pkg_add/OpenBSD/PackageRepository/Installed.pm +++ b/usr.sbin/pkg_add/OpenBSD/PackageRepository/Installed.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: Installed.pm,v 1.30 2015/04/16 09:32:23 espie Exp $ +# $OpenBSD: Installed.pm,v 1.31 2015/04/16 13:29:16 espie Exp $ # # Copyright (c) 2007-2014 Marc Espie <espie@openbsd.org> # @@ -31,32 +31,13 @@ my ($version, $current); sub expand_locations { my ($class, $string, $state) = @_; + require OpenBSD::Paths; if ($string eq '%a') { - require OpenBSD::PackingElement; - return OpenBSD::PackingElement::Arch::arch(); - } else { - if (!defined $version) { - require OpenBSD::Paths; - open my $cmd, '-|', - OpenBSD::Paths->sysctl, '-n', 'kern.version'; - my $line = <$cmd>; - close($cmd); - if ($line =~ m/^OpenBSD (\d\.\d)(\S*)\s/) { - $version = $1; - if ($2 eq '-current') { - $current = 'snapshots'; - } else { - $current = $version; - } - } else { - $state->fatal("Can't figure out version"); - } - } - if ($string eq '%c') { - return $current; - } else { - return $version; - } + return OpenBSD::Paths->architecture; + } elsif ($string eq '%v') { + return OpenBSD::Paths->os_version; + } elsif ($string eq '%c') { + return OpenBSD::Paths->os_directory; } } diff --git a/usr.sbin/pkg_add/OpenBSD/PackingElement.pm b/usr.sbin/pkg_add/OpenBSD/PackingElement.pm index 7e8155307b7..37008e14b20 100644 --- a/usr.sbin/pkg_add/OpenBSD/PackingElement.pm +++ b/usr.sbin/pkg_add/OpenBSD/PackingElement.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: PackingElement.pm,v 1.240 2015/04/16 09:32:23 espie Exp $ +# $OpenBSD: PackingElement.pm,v 1.241 2015/04/16 13:29:16 espie Exp $ # # Copyright (c) 2003-2014 Marc Espie <espie@openbsd.org> # @@ -1748,17 +1748,6 @@ sub stringize($) return join(',', @{$self->{arches}}); } -my ($machine_arch, $arch); - -sub arch -{ - if (!defined $arch) { - my $cmd = OpenBSD::Paths->uname." -m"; - chomp($arch = `$cmd`); - } - return $arch; -} - sub check { my ($self, $forced_arch) = @_; @@ -1772,12 +1761,8 @@ sub check next; } } - if (!defined $machine_arch) { - my $cmd = OpenBSD::Paths->arch." -s"; - chomp($machine_arch = `$cmd`); - } - return 1 if $ok eq $machine_arch; - return 1 if $ok eq arch(); + return 1 if $ok eq OpenBSD::Paths->machine_architecture; + return 1 if $ok eq OpenBSD::Paths->architecture; } return; } diff --git a/usr.sbin/pkg_add/OpenBSD/Paths.pm b/usr.sbin/pkg_add/OpenBSD/Paths.pm index 1530f8edc0c..b49be5ef17e 100644 --- a/usr.sbin/pkg_add/OpenBSD/Paths.pm +++ b/usr.sbin/pkg_add/OpenBSD/Paths.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: Paths.pm,v 1.30 2014/08/26 17:47:24 jsing Exp $ +# $OpenBSD: Paths.pm,v 1.31 2015/04/16 13:29:16 espie Exp $ # # Copyright (c) 2007-2014 Marc Espie <espie@openbsd.org> # @@ -74,4 +74,58 @@ sub font_cruft() { ("fonts.alias", "fonts.dir", "fonts.cache-1", "fonts.scale") sub man_cruft() { ("whatis.db", "mandoc.db", "mandoc.index") } sub info_cruft() { ("dir") } +# a bit of code, OS-dependent stuff that's run-time detected and has no +# home yet. + +my ($machine_arch, $arch, $osversion, $osdirectory); + +sub architecture +{ + if (!defined $arch) { + my $cmd = uname()." -m"; + chomp($arch = `$cmd`); + } + return $arch; +} + +sub machine_architecture +{ + if (!defined $machine_arch) { + my $cmd = arch()." -s"; + chomp($machine_arch = `$cmd`); + } + return $machine_arch; +} + +sub compute_osversion +{ + open my $cmd, '-|', OpenBSD::Paths->sysctl, '-n', 'kern.version'; + my $line = <$cmd>; + close($cmd); + if ($line =~ m/^OpenBSD (\d\.\d)(\S*)\s/) { + $osversion = $1; + if ($2 eq '-current') { + $osdirectory = 'snapshots'; + } else { + $osdirectory = $osversion; + } + } +} + +sub os_version +{ + if (!defined $osversion) { + compute_osversion(); + } + return $osversion; +} + +sub os_directory +{ + if (!defined $osversion) { + compute_osversion(); + } + return $osdirectory; +} + 1; |