diff options
Diffstat (limited to 'src/etc/inc/pkg-utils.inc')
-rw-r--r-- | src/etc/inc/pkg-utils.inc | 94 |
1 files changed, 37 insertions, 57 deletions
diff --git a/src/etc/inc/pkg-utils.inc b/src/etc/inc/pkg-utils.inc index 1509206..daceefb 100644 --- a/src/etc/inc/pkg-utils.inc +++ b/src/etc/inc/pkg-utils.inc @@ -96,30 +96,26 @@ function pkg_remove_prefix(&$pkg_name) { function pkg_update($force = false) { global $g; - $now = strftime('%s'); - $last_update_file="{$g['varrun_path']}/{$g['product_name']}-upgrade-last-update"; - if (!$force) { - if (file_exists($last_update_file)) { - $last_update = rtrim(file_get_contents($last_update_file), "\n"); - if (!is_numericint($last_update)) { - $last_update = 0; - } - } + return pkg_call("update" . ($force ? " -f" : "")); +} - if ($last_update > 0) { - if ($now > $last_update && ($now - $last_update) <= (60 * 60)) { - return true; - } - } - } +/* return an array with necessary environment vars for pkg */ +function pkg_env() { + global $config, $g; - $rc = pkg_call("update"); + $pkg_env_vars = array( + "LANG" => "C", + "HTTP_USER_AGENT" => $user_agent, + "ASSUME_ALWAYS_YES" => "true" + ); - if ($rc) { - file_put_contents($last_update_file, $now . "\n"); + if ($g['platform'] == "nanobsd" || + isset($config['system']['use_mfs_tmpvar'])) { + $pkg_env_vars['PKG_DBDIR'] = '/root/var/db/pkg'; + $pkg_env_vars['PKG_CACHEDIR'] = '/root/var/cache/pkg'; } - return $rc; + return $pkg_env_vars; } /* Execute a pkg call */ @@ -135,21 +131,19 @@ function pkg_call($params, $mute = false) { $user_agent .= ' : ' . get_single_sysctl('kern.hostuuid'); } - $env = array( - "HTTP_USER_AGENT" => $user_agent, - "ASSUME_ALWAYS_YES" => "true", - "REPO_AUTOUPDATE" => "false" - ); - $descriptorspec = array( 1 => array("pipe", "w"), /* stdout */ 2 => array("pipe", "w") /* stderr */ ); + conf_mount_rw(); + pkg_debug("pkg_call(): {$params}\n"); - $process = proc_open("/usr/sbin/pkg {$params}", $descriptorspec, $pipes, '/', $env); + $process = proc_open("/usr/sbin/pkg {$params}", $descriptorspec, $pipes, + '/', pkg_env()); if (!is_resource($process)) { + conf_mount_ro(); return false; } @@ -201,6 +195,8 @@ function pkg_call($params, $mute = false) { fclose($pipes[2]); proc_close($process); + conf_mount_ro(); + if (!isset($rc)) { $rc = $status['exitcode']; } @@ -233,21 +229,19 @@ function pkg_exec($params, &$stdout, &$stderr) { $user_agent .= ' : ' . get_single_sysctl('kern.hostuuid'); } - $env = array( - "HTTP_USER_AGENT" => $user_agent, - "ASSUME_ALWAYS_YES" => "true", - "REPO_AUTOUPDATE" => "false" - ); - $descriptorspec = array( 1 => array("pipe", "w"), /* stdout */ 2 => array("pipe", "w") /* stderr */ ); + conf_mount_rw(); + pkg_debug("pkg_exec(): {$params}\n"); - $process = proc_open("/usr/sbin/pkg {$params}", $descriptorspec, $pipes, '/', $env); + $process = proc_open("/usr/sbin/pkg {$params}", $descriptorspec, $pipes, + '/', pkg_env()); if (!is_resource($process)) { + conf_mount_ro(); return -1; } @@ -263,6 +257,8 @@ function pkg_exec($params, &$stdout, &$stderr) { } fclose($pipes[2]); + conf_mount_ro(); + return proc_close($process); } @@ -390,21 +386,7 @@ function get_pkg_info($pkgs = 'all', $info = 'all') { $pkgs = $g['pkg_prefix']; } - /* Make sure repo metadata is up2date */ - update_status("\n" . - gettext("Updating package repository metadada...") . "\n"); - - if (!pkg_update()) { - $input_errors[] = gettext( - "ERROR: An error occurred when updating packages repository. Aborting...") - . "\n"; - update_status("\n" . gettext( - "ERROR: An error occurred when updating packages repository. Aborting...") - . "\n"); - return array(); - } - - $rc = pkg_exec("search -U --raw-format json-compact " . $pkgs, $out, $err); + $rc = pkg_exec("search --raw-format json-compact " . $pkgs, $out, $err); if ($rc != 0) { update_status("\n" . gettext( @@ -932,11 +914,13 @@ function delete_package_xml($package_name, $when = "post-deinstall") { $need_syslog_restart = true; } - /* remove config.xml entries */ - update_status(gettext("Configuration... ")); - unset($config['installedpackages']['package'][$pkgid]); - update_status(gettext("done.") . "\n"); - write_config("Removed {$package_name} package.\n"); + if ($when == "post-deinstall") { + /* remove config.xml entries */ + update_status(gettext("Configuration... ")); + unset($config['installedpackages']['package'][$pkgid]); + update_status(gettext("done.") . "\n"); + write_config("Removed {$package_name} package.\n"); + } /* remove package entry from /etc/syslog.conf if needed */ /* this must be done after removing the entries from config.xml */ @@ -972,10 +956,6 @@ function package_reinstall_all() { sleep(1); } update_status("\n"); - } else { - if (!pkg_update()) { - return false; - } } $pkg_info = get_pkg_info(); |