summaryrefslogtreecommitdiffstats
path: root/etc
diff options
context:
space:
mode:
authorRenato Botelho <garga@FreeBSD.org>2015-05-07 10:53:35 -0300
committerRenato Botelho <garga@FreeBSD.org>2015-05-07 10:53:35 -0300
commitc2eb250805df20598929f70bbc96f00998df6d22 (patch)
treecd70ae17e7b035748d05ba5c1cbda043b5b2dc60 /etc
parentd2caff9bf7e5f6daac68b48d81311346592a1136 (diff)
downloadpfsense-c2eb250805df20598929f70bbc96f00998df6d22.zip
pfsense-c2eb250805df20598929f70bbc96f00998df6d22.tar.gz
Rename remove_freebsd_package() to pkg_delete() and introduce pkg_remove_prefix() pkg_call() and is_pkg_installed()
Diffstat (limited to 'etc')
-rw-r--r--etc/inc/pkg-utils.inc62
1 files changed, 41 insertions, 21 deletions
diff --git a/etc/inc/pkg-utils.inc b/etc/inc/pkg-utils.inc
index b3539b4..371c8ec 100644
--- a/etc/inc/pkg-utils.inc
+++ b/etc/inc/pkg-utils.inc
@@ -83,27 +83,47 @@ if (!isset($g['platform'])) {
$g['platform'] = trim(file_get_contents("/etc/platform"));
}
-/****f* pkg-utils/remove_package
- * NAME
- * remove_package - Removes package from FreeBSD if it exists
- * INPUTS
- * $packagestring - name/string to check for
- * RESULT
- * none
- * NOTES
- *
- ******/
-function remove_freebsd_package($packagestring) {
- // The packagestring passed in must be the full PBI package name,
- // as displayed by the pbi_info utility. e.g. "package-1.2.3_4-i386"
- // It must NOT have ".pbi" on the end.
- $links = get_pbi_binaries(escapeshellarg($packagestring));
- foreach ($links as $link) {
- if (is_link("/usr/local/{$link['link_name']}")) {
- @unlink("/usr/local/{$link['link_name']}");
- }
+/* Remove pkg_prefix from package name if it's present */
+function pkg_remove_prefix(&$pkg_name) {
+ global $g;
+
+ if (substr($pkg_name, 0, strlen($g['pkg_prefix'])) == $g['pkg_prefix']) {
+ $pkg_name = substr($pkg_name, strlen($g['pkg_prefix']));
+ }
+}
+
+/* Execute a pkg call */
+function pkg_call($params) {
+ if (empty($params)) {
+ return false;
+ }
+
+ // XXX: Use proper call with fifo to collect statistics
+ $_gc = exec("env ASSUME_ALWAYS_YES=1 /usr/sbin/pkg " . escapeshellarg($params), $output, $rc);
+
+ return ($rc == 0);
+}
+
+/* Check if package is installed */
+function is_pkg_installed($pkg_name) {
+ global $g;
+
+ pkg_remove_prefix($pkg_name);
+
+ return pkg_call("info -e " . $g['pkg_prefix'] . $pkg_name);
+}
+
+/* Delete package from FreeBSD, $pkg_name should not contain prefix */
+function pkg_delete($pkg_name) {
+ global $g;
+
+ pkg_remove_prefix($pkg_name);
+
+ if (is_pkg_installed($pkg_name)) {
+ pkg_call("delete -q -y " . $g['pkg_prefix'] . $pkg_name);
+ /* Cleanup unecessary dependencies */
+ pkg_call("autoremove -y -q");
}
- exec("/usr/local/sbin/pbi_delete " . escapeshellarg($packagestring) . " 2>>/tmp/pbi_delete_errors.txt");
}
/****f* pkg-utils/is_package_installed
@@ -971,7 +991,7 @@ function delete_package($pkg) {
}
update_output_window($static_output);
- remove_freebsd_package($pkg);
+ pkg_delete($pkg);
$static_output .= "done.\n";
update_output_window($static_output);
OpenPOWER on IntegriCloud