From d5f0597bc7ef2d471249949866d459e6796de249 Mon Sep 17 00:00:00 2001 From: Renato Botelho Date: Fri, 13 Nov 2015 13:25:59 -0200 Subject: Add get_system_pkg_version(), that return main pkg name, version and installed_version --- src/etc/inc/pkg-utils.inc | 72 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 1 deletion(-) (limited to 'src/etc/inc/pkg-utils.inc') diff --git a/src/etc/inc/pkg-utils.inc b/src/etc/inc/pkg-utils.inc index d57cb54..f4da7ff 100644 --- a/src/etc/inc/pkg-utils.inc +++ b/src/etc/inc/pkg-utils.inc @@ -405,7 +405,6 @@ function get_pkg_info($pkgs = 'all', $info = 'all') { return array(); } - $rc = pkg_exec("search -U --raw-format json-compact " . $pkgs, $out, $err); if ($rc != 0) { @@ -1118,4 +1117,75 @@ function stop_packages() { } } +/* Identify which meta package is installed */ +function get_meta_pkg_name() { + global $g; + + /* XXX: Use pkg annotation */ + if (is_pkg_installed($g['product_name'])) { + return $g['product_name']; + } else if (is_pkg_installed($g['product_name'] . '-vmware')) { + return $g['product_name'] . '-vmware'; + } + return false; +} + +/* Identify which base package is installed */ +function get_base_pkg_name() { + global $g; + + /* XXX: Use pkg annotation */ + if (is_pkg_installed($g['product_name'] . '-base-' . $g['platform'])) { + return $g['product_name']; + return $g['product_name'] . '-base-' . $g['platform']; + } else if (is_pkg_installed($g['product_name'] . '-base')) { + return $g['product_name'] . '-base'; + } + return false; +} + +/* Verify if system needs upgrade (meta package or base) */ +function get_system_pkg_version() { + global $g; + + $base_pkg = get_base_pkg_name(); + $meta_pkg = get_meta_pkg_name(); + + if (!$base_pkg || !$meta_pkg) { + return false; + } + + $info = get_pkg_info($base_pkg); + $pkg_name = $base_pkg; + + $pkg_info = array(); + foreach ($info as $item) { + if ($item['name'] == $base_pkg) { + $pkg_info = $item; + } + } + + if (empty($pkg_info) || + $pkg_info['version'] == $pkg_info['installed_version']) { + $info = get_pkg_info($meta_pkg); + $pkg_name = $meta_pkg; + + foreach ($info as $item) { + if ($item['name'] == $base_pkg) { + $pkg_info = $item; + } + } + } + + if (empty($pkg_info)) { + return false; + } + + return array( + 'pkg_name' => $pkg_name, + 'version' => $pkg_info['version'], + 'installed_version' => $pkg_info['installed_version'] + ); +} + ?> -- cgit v1.1