summaryrefslogtreecommitdiffstats
path: root/etc/inc/pkg-utils.inc
diff options
context:
space:
mode:
authorPhil Davis <phil.davis@world.inf.org>2012-03-21 23:41:11 +0545
committerPhil Davis <phil.davis@world.inf.org>2012-03-21 23:41:11 +0545
commit8059acb56ef8d3fc39b7cadd1f0682f0795e85f1 (patch)
tree05216f92a595db961b92accfb5840c2acc116644 /etc/inc/pkg-utils.inc
parent84d50fe73c78a4034019bbd7906d0bd4b966588b (diff)
downloadpfsense-8059acb56ef8d3fc39b7cadd1f0682f0795e85f1.zip
pfsense-8059acb56ef8d3fc39b7cadd1f0682f0795e85f1.tar.gz
Handle mixed-case package names like squidGuard.
Check that conf files in PBI folders exist before unlink. Pass correct package names 1 at a time from uninstalll_package to delete_package. log_error if the PBI package name can't be found in remove_freebsd_package - this means that the PBI files will not get cleaned up. Usually this is caused because the system has been rebooted since the package was installed and the PBI db in /var/db/pbi has gone (e.g. on nanobsd /var is created from scratch at boot)
Diffstat (limited to 'etc/inc/pkg-utils.inc')
-rw-r--r--etc/inc/pkg-utils.inc49
1 files changed, 37 insertions, 12 deletions
diff --git a/etc/inc/pkg-utils.inc b/etc/inc/pkg-utils.inc
index 7734cc7..6dff286 100644
--- a/etc/inc/pkg-utils.inc
+++ b/etc/inc/pkg-utils.inc
@@ -99,21 +99,29 @@ conf_mount_ro();
*
******/
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.
exec("/usr/local/sbin/pbi_info {$packagestring} | /usr/bin/awk '/Prefix/ {print $2}'",$pbidir);
$pbidir = $pbidir[0];
- $linkdirs = array('bin','sbin');
- foreach($linkdirs as $dir) {
- if(is_dir("{$pbidir}/{$dir}")) {
- $files = scandir("{$pbidir}/{$dir}");
- foreach($files as $f) {
- if($f != '.' && $f != '..') {
- unlink("/usr/local/{$dir}/{$f}");
+ if ($pbidir == "") {
+ log_error("PBI dir for {$packagestring} was not found - cannot cleanup PBI files");
+ }
+ else {
+ $linkdirs = array('bin','sbin');
+ foreach($linkdirs as $dir) {
+ if(is_dir("{$pbidir}/{$dir}")) {
+ $files = scandir("{$pbidir}/{$dir}");
+ foreach($files as $f) {
+ if($f != '.' && $f != '..') {
+ unlink("/usr/local/{$dir}/{$f}");
+ }
}
}
}
- }
- exec("/usr/local/sbin/pbi_delete {$packagestring} 2>>/tmp/pbi_delete_errors.txt");
+ exec("/usr/local/sbin/pbi_delete {$packagestring} 2>>/tmp/pbi_delete_errors.txt");
+ }
}
/****f* pkg-utils/is_package_installed
@@ -352,7 +360,17 @@ function uninstall_package($pkg_name) {
foreach ($pkg_depends as $pkg_depend)
delete_package($pkg_depend);
} else {
- delete_package($pkg_depends);
+ // The packages (1 or more) are all in one long string.
+ // We need to pass them 1 at a time to delete_package.
+ // Compress any multiple whitespace (sp, tab, cr, lf...) into a single space char.
+ $pkg_dep_str = preg_replace("'\s+'", ' ', $pkg_depends);
+ // Get rid of any leading or trailing space.
+ $pkg_dep_str = trim($pkg_dep_str);
+ // Now we have a space-separated string. Make it into an array and process it.
+ $pkg_dep_array = explode(" ", $pkg_dep_str);
+ foreach ($pkg_dep_array as $pkg_depend) {
+ delete_package($pkg_depend);
+ }
}
}
delete_package_xml($pkg_name);
@@ -794,12 +812,18 @@ function install_package_xml($pkg) {
* change packages to store configs at /usr/pbi/pkg/etc and remove this
*/
eval_once($pkg_config['custom_php_install_command']);
- exec("/usr/local/sbin/pbi_info | grep {$pkg}- | xargs /usr/local/sbin/pbi_info | awk '/Prefix/ {print $2}'",$pbidirarray);
+ // Note: pkg may be mixed-case, e.g. "squidGuard" but the PBI names are lowercase.
+ // e.g. "squidguard-1.4_4-i386" so feed lowercase to pbi_info below.
+ // Also add the "-" so that examples like "squid-" do not match "squidguard-".
+ $pkg_name_for_pbi_match = strtolower($pkg) . "-";
+ exec("/usr/local/sbin/pbi_info | grep {$pkg_name_for_pbi_match}- | xargs /usr/local/sbin/pbi_info | awk '/Prefix/ {print $2}'",$pbidirarray);
$pbidir0 = $pbidirarray[0];
exec("find /usr/local/etc/ -name *.conf | grep {$pkg}",$files);
foreach($files as $f) {
$pbiconf = str_replace('/usr/local',$pbidir0,$f);
- unlink($pbiconf);
+ if (is_file($pbiconf) || is_link($pbiconf)) {
+ unlink($pbiconf);
+ }
symlink($f,$pbiconf);
}
eval_once($pkg_config['custom_php_install_command']);
@@ -906,6 +930,7 @@ function delete_package($pkg) {
if(!$pkg)
return;
+ // Note: $pkg has the full PBI package name followed by ".pbi". Strip off ".pbi".
$pkg = substr(reverse_strrchr($pkg, "."), 0, -1);
if($pkg)
OpenPOWER on IntegriCloud