summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjim-p <jimp@pfsense.org>2014-08-19 14:32:46 -0400
committerjim-p <jimp@pfsense.org>2014-08-19 14:32:46 -0400
commitbfe9c9e7a3a103ff1b278e5af5f8a7c39051810d (patch)
treed705f7ea9bc73f2159267fcd5e1ed52dd1e60a74
parente0f10116ef8b4264a0804ee552f99f2bebd7edfe (diff)
downloadpfsense-bfe9c9e7a3a103ff1b278e5af5f8a7c39051810d.zip
pfsense-bfe9c9e7a3a103ff1b278e5af5f8a7c39051810d.tar.gz
Move the fetching of a package's config file and additional files to separate functions, and then have the "xml" package button perform these so that it is not only a redundant copy of the "pkg" reinstall button. This can help ensure a package files are in a known-good state before other actions are performed, in case the deinstall would fail or behave erratically due to other files being missing.
-rw-r--r--etc/inc/pkg-utils.inc179
-rw-r--r--usr/local/www/pkg_mgr_install.php2
2 files changed, 118 insertions, 63 deletions
diff --git a/etc/inc/pkg-utils.inc b/etc/inc/pkg-utils.inc
index 4a19c7b..417d6b3 100644
--- a/etc/inc/pkg-utils.inc
+++ b/etc/inc/pkg-utils.inc
@@ -598,6 +598,7 @@ function get_pbi_binaries($pbi) {
return $result;
}
+
function install_package($package, $pkg_info = "", $force_install = false) {
global $g, $config, $static_output, $pkg_interface;
@@ -637,28 +638,10 @@ function install_package($package, $pkg_info = "", $force_install = false) {
log_error(sprintf(gettext('Beginning package installation for %s .'), $pkg_info['name']));
$static_output .= sprintf(gettext("Beginning package installation for %s ."), $pkg_info['name']);
update_status($static_output);
+
/* fetch the package's configuration file */
- if($pkg_info['config_file'] != "") {
- $static_output .= "\n" . gettext("Downloading package configuration file... ");
- update_output_window($static_output);
- pkg_debug(gettext("Downloading package configuration file...") . "\n");
- $fetchto = substr(strrchr($pkg_info['config_file'], '/'), 1);
- download_file_with_progress_bar($pkg_info['config_file'], '/usr/local/pkg/' . $fetchto);
- if(!file_exists('/usr/local/pkg/' . $fetchto)) {
- pkg_debug(gettext("ERROR! Unable to fetch package configuration file. Aborting installation.") . "\n");
- if($pkg_interface == "console")
- print "\n" . gettext("ERROR! Unable to fetch package configuration file. Aborting package installation.") . "\n";
- else {
- $static_output .= gettext("failed!\n\nInstallation aborted.\n");
- update_output_window($static_output);
- echo "<br />Show <a href=\"pkg_mgr_install.php?showlog=true\">install log</a></center>";
- }
- conf_mount_ro();
- return -1;
- }
- $static_output .= gettext("done.") . "\n";
- update_output_window($static_output);
- }
+ pkg_fetch_config_file($package, $pkg_info);
+
/* add package information to config.xml */
$pkgid = get_pkg_id($pkg_info['name']);
$static_output .= gettext("Saving updated package information...") . " ";
@@ -761,6 +744,7 @@ function install_package_xml($pkg) {
}
}
}
+
$configfile = substr(strrchr($pkg_info['config_file'], '/'), 1);
if(file_exists("/usr/local/pkg/" . $configfile)) {
$static_output .= gettext("Loading package configuration... ");
@@ -784,50 +768,9 @@ function install_package_xml($pkg) {
$static_output .= gettext("done.") . "\n";
update_output_window($static_output);
}
- /* download additional files */
- if(is_array($pkg_config['additional_files_needed'])) {
- $static_output .= gettext("Additional files... ");
- $static_orig = $static_output;
- update_output_window($static_output);
- foreach($pkg_config['additional_files_needed'] as $afn) {
- $filename = get_filename_from_url($afn['item'][0]);
- if($afn['chmod'] <> "")
- $pkg_chmod = $afn['chmod'];
- else
- $pkg_chmod = "";
- if($afn['prefix'] <> "")
- $prefix = $afn['prefix'];
- else
- $prefix = "/usr/local/pkg/";
+ pkg_fetch_additional_files($pkg, $pkg_info);
- if(!is_dir($prefix))
- safe_mkdir($prefix);
- $static_output .= $filename . " ";
- update_output_window($static_output);
- if (download_file_with_progress_bar($afn['item'][0], $prefix . $filename) !== true) {
- $static_output .= "failed.\n";
- @unlink($prefix . $filename);
- update_output_window($static_output);
- return false;
- }
- if(stristr($filename, ".tgz") <> "") {
- pkg_debug(gettext("Extracting tarball to -C for ") . $filename . "...\n");
- $tarout = "";
- exec("/usr/bin/tar xvzf " . escapeshellarg($prefix . $filename) . " -C / 2>&1", $tarout);
- pkg_debug(print_r($tarout, true) . "\n");
- }
- if($pkg_chmod <> "") {
- pkg_debug(sprintf(gettext('Changing file mode to %1$s for %2$s%3$s%4$s'), $pkg_chmod, $prefix, $filename, "\n"));
- @chmod($prefix . $filename, $pkg_chmod);
- system("/bin/chmod {$pkg_chmod} {$prefix}{$filename}");
- }
- $static_output = $static_orig;
- update_output_window($static_output);
- }
- $static_output .= gettext("done.") . "\n";
- update_output_window($static_output);
- }
/* if a require exists, include it. this will
* show us where an error exists in a package
* instead of making us blindly guess
@@ -1488,4 +1431,114 @@ function package_server_mismatch_message() {
. '<a href="/pkg_mgr_settings.php">' . gettext("Package Manager Settings") . '</a>';
}
+
+function pkg_fetch_config_file($package, $pkg_info = "") {
+ global $g, $config, $static_output, $pkg_interface;
+ conf_mount_rw();
+
+ if(empty($pkg_info) or !is_array($pkg_info[$package])) {
+ $pkg_info = get_pkg_info(array($package));
+ $pkg_info = $pkg_info[$package]; // We're only dealing with one package, so we can strip away the extra array.
+ if (empty($pkg_info)) {
+ conf_mount_ro();
+ return -1;
+ }
+ }
+
+ /* fetch the package's configuration file */
+ if($pkg_info['config_file'] != "") {
+ $static_output .= "\n" . gettext("Downloading package configuration file... ");
+ update_output_window($static_output);
+ pkg_debug(gettext("Downloading package configuration file...") . "\n");
+ $fetchto = substr(strrchr($pkg_info['config_file'], '/'), 1);
+ download_file_with_progress_bar($pkg_info['config_file'], '/usr/local/pkg/' . $fetchto);
+ if(!file_exists('/usr/local/pkg/' . $fetchto)) {
+ pkg_debug(gettext("ERROR! Unable to fetch package configuration file. Aborting installation.") . "\n");
+ if($pkg_interface == "console")
+ print "\n" . gettext("ERROR! Unable to fetch package configuration file. Aborting package installation.") . "\n";
+ else {
+ $static_output .= gettext("failed!\n\nInstallation aborted.\n");
+ update_output_window($static_output);
+ echo "<br />Show <a href=\"pkg_mgr_install.php?showlog=true\">install log</a></center>";
+ }
+ conf_mount_ro();
+ return -1;
+ }
+ $static_output .= gettext("done.") . "\n";
+ update_output_window($static_output);
+ }
+ conf_mount_ro();
+ return true;
+}
+
+
+function pkg_fetch_additional_files($package, $pkg_info = "") {
+ global $g, $config, $static_output, $pkg_interface;
+ conf_mount_rw();
+
+ if(empty($pkg_info) or !is_array($pkg_info[$package])) {
+ $pkg_info = get_pkg_info(array($package));
+ $pkg_info = $pkg_info[$package]; // We're only dealing with one package, so we can strip away the extra array.
+ if (empty($pkg_info)) {
+ conf_mount_ro();
+ return -1;
+ }
+ }
+
+ $configfile = substr(strrchr($pkg_info['config_file'], '/'), 1);
+ if(file_exists("/usr/local/pkg/" . $configfile)) {
+ $static_output .= gettext("Loading package configuration... ");
+ update_output_window($static_output);
+ $pkg_config = parse_xml_config_pkg("/usr/local/pkg/" . $configfile, "packagegui");
+ $static_output .= gettext("done.") . "\n";
+ update_output_window($static_output);
+ /* download additional files */
+ if(is_array($pkg_config['additional_files_needed'])) {
+ $static_output .= gettext("Additional files... ");
+ $static_orig = $static_output;
+ update_output_window($static_output);
+ foreach($pkg_config['additional_files_needed'] as $afn) {
+ $filename = get_filename_from_url($afn['item'][0]);
+ if($afn['chmod'] <> "")
+ $pkg_chmod = $afn['chmod'];
+ else
+ $pkg_chmod = "";
+
+ if($afn['prefix'] <> "")
+ $prefix = $afn['prefix'];
+ else
+ $prefix = "/usr/local/pkg/";
+
+ if(!is_dir($prefix))
+ safe_mkdir($prefix);
+ $static_output .= $filename . " ";
+ update_output_window($static_output);
+ if (download_file_with_progress_bar($afn['item'][0], $prefix . $filename) !== true) {
+ $static_output .= "failed.\n";
+ @unlink($prefix . $filename);
+ update_output_window($static_output);
+ return false;
+ }
+ if(stristr($filename, ".tgz") <> "") {
+ pkg_debug(gettext("Extracting tarball to -C for ") . $filename . "...\n");
+ $tarout = "";
+ exec("/usr/bin/tar xvzf " . escapeshellarg($prefix . $filename) . " -C / 2>&1", $tarout);
+ pkg_debug(print_r($tarout, true) . "\n");
+ }
+ if($pkg_chmod <> "") {
+ pkg_debug(sprintf(gettext('Changing file mode to %1$s for %2$s%3$s%4$s'), $pkg_chmod, $prefix, $filename, "\n"));
+ @chmod($prefix . $filename, $pkg_chmod);
+ system("/bin/chmod {$pkg_chmod} {$prefix}{$filename}");
+ }
+ $static_output = $static_orig;
+ update_output_window($static_output);
+ }
+ $static_output .= gettext("done.") . "\n";
+ update_output_window($static_output);
+ }
+ conf_mount_ro();
+ return true;
+ }
+}
+
?>
diff --git a/usr/local/www/pkg_mgr_install.php b/usr/local/www/pkg_mgr_install.php
index 2f5d04c..945aa2d 100644
--- a/usr/local/www/pkg_mgr_install.php
+++ b/usr/local/www/pkg_mgr_install.php
@@ -226,6 +226,8 @@ if ($_GET) {
filter_configure();
break;
case 'reinstallxml':
+ pkg_fetch_config_file($pkgid);
+ pkg_fetch_additional_files($pkgid);
case 'reinstallpkg':
delete_package_xml($pkgid);
if (install_package($pkgid) < 0) {
OpenPOWER on IntegriCloud