summaryrefslogtreecommitdiffstats
path: root/src/etc/inc/pkg-utils.inc
diff options
context:
space:
mode:
authorRenato Botelho <renato@netgate.com>2015-11-13 13:25:59 -0200
committerRenato Botelho <renato@netgate.com>2015-11-13 13:25:59 -0200
commitd5f0597bc7ef2d471249949866d459e6796de249 (patch)
tree92d7ed31799df175fd67a54fd0c1e3b84a7a1fbf /src/etc/inc/pkg-utils.inc
parentf5b1c660715053e8f88a190324e1d5a24b23ff66 (diff)
downloadpfsense-d5f0597bc7ef2d471249949866d459e6796de249.zip
pfsense-d5f0597bc7ef2d471249949866d459e6796de249.tar.gz
Add get_system_pkg_version(), that return main pkg name, version and installed_version
Diffstat (limited to 'src/etc/inc/pkg-utils.inc')
-rw-r--r--src/etc/inc/pkg-utils.inc72
1 files changed, 71 insertions, 1 deletions
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']
+ );
+}
+
?>
OpenPOWER on IntegriCloud