summaryrefslogtreecommitdiffstats
path: root/etc
diff options
context:
space:
mode:
authorRenato Botelho <renato@netgate.com>2015-07-01 10:17:55 -0300
committerRenato Botelho <renato@netgate.com>2015-07-01 10:17:55 -0300
commit65c94077e4a9889ac6ba9035fed54c7b2d16fd5b (patch)
treef53006efe729315a2f5c561589bae33c3e1d015c /etc
parente1382589556b500e36197d3b7c02a10f4b3b8261 (diff)
downloadpfsense-65c94077e4a9889ac6ba9035fed54c7b2d16fd5b.zip
pfsense-65c94077e4a9889ac6ba9035fed54c7b2d16fd5b.tar.gz
Implement get_pkg_info()
Diffstat (limited to 'etc')
-rw-r--r--etc/inc/pkg-utils.inc52
1 files changed, 40 insertions, 12 deletions
diff --git a/etc/inc/pkg-utils.inc b/etc/inc/pkg-utils.inc
index e42f9d3..b6ec8d0 100644
--- a/etc/inc/pkg-utils.inc
+++ b/etc/inc/pkg-utils.inc
@@ -291,20 +291,48 @@ function get_package_internal_name($package_data) {
}
}
-/****f* pkg-utils/get_pkg_info
- * NAME
- * get_pkg_info - Retrieve package information from package server.
- * INPUTS
- * $pkgs - 'all' to retrieve all packages, an array containing package names otherwise
- * $info - 'all' to retrieve all information, an array containing keys otherwise
- * RESULT
- * $raw_versions - Array containing retrieved information, indexed by package name.
- ******/
+/* Get information about packages */
function get_pkg_info($pkgs = 'all', $info = 'all') {
- global $g;
+ global $g, $static_output;
- // XXX: implement
- return array();
+ $out = '';
+ $err = '';
+
+ if ($pkgs == 'all') {
+ $pkgs = $g['pkg_prefix'];
+ }
+
+ /* Make sure repo metadata is up2date */
+ $static_output .= "\n" . gettext("Updating package repository metadada...") . "\n";
+ update_status($static_output);
+ if (!pkg_call("update")) {
+ $static_output .= "\n" . gettext("ERROR: An error occurred when updating packages repository. Aborting...") . "\n";
+ update_status($static_output);
+ return array();
+ }
+
+ $rc = pkg_exec("search -U --raw-format json-compact " . $pkgs, $out, $err);
+
+ if ($rc != 0) {
+ $static_output .= "\n" . gettext("ERROR: Error trying to get packages list. Aborting...") . "\n";
+ $static_output .= $err;
+ update_status($static_output);
+ return array();
+ }
+
+ $result = array();
+ $pkgs_info = explode("\n", $out);
+ foreach ($pkgs_info as $pkg_info_json) {
+ $pkg_info = json_decode($pkg_info_json, true);
+ if (!isset($pkg_info['name'])) {
+ continue;
+ }
+
+ $result[] = $pkg_info;
+ unset($pkg_info);
+ }
+
+ return $result;
}
/*
OpenPOWER on IntegriCloud