summaryrefslogtreecommitdiffstats
path: root/etc/inc/pkg-utils.inc
diff options
context:
space:
mode:
Diffstat (limited to 'etc/inc/pkg-utils.inc')
-rw-r--r--etc/inc/pkg-utils.inc179
1 files changed, 116 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;
+ }
+}
+
?>
OpenPOWER on IntegriCloud