ACC SHELL
/**
* File:
* pkg_finish.ycp
*
* Module:
* Step of base installation finish
*
* Authors:
* Jiri Srain <jsrain@suse.cz>
*
* $Id: pkg_finish.ycp 59737 2009-11-24 14:34:51Z locilka $
*
*/
{
textdomain "packager";
import "Installation";
import "Mode";
import "Stage";
import "String";
import "FileUtils";
import "Packages";
any ret = nil;
string func = "";
map param = $[];
// During upgrade, old sources are reinitialized
// either as enabled or disabled.
// The old sources from targed should go away.
void BackUpAllTargetSources () {
import "Directory";
string repos_dir = "/etc/zypp/repos.d";
if (! FileUtils::Exists (repos_dir)) {
y2error ("Directory %1 doesn't exist!", repos_dir);
return;
}
list <string> current_repos = (list<string>) SCR::Read (.target.dir, repos_dir);
if (current_repos == nil || size (current_repos) == 0) {
y2warning ("There are currently no repos in %1 conf dir", repos_dir);
return;
} else {
y2milestone ("These repos currently exist on a target: %1", current_repos);
}
map cmd = (map) WFM::Execute (.local.bash_output, "date +%Y%m%d-%H%M%S");
list <string> a_name_list = splitstring(cmd["stdout"]:"the_latest", "\n");
string archive_name = "repos_" + a_name_list[0]:"" + ".tgz";
string shellcommand = sformat (
"mkdir -p '%1' && cd '%1' && /bin/tar -czf '%2' '%3'",
String::Quote (Directory::vardir + "/repos.d_backup/"),
String::Quote (archive_name),
String::Quote (repos_dir)
);
cmd = (map) SCR::Execute (.target.bash_output, shellcommand);
if (cmd["exit"]:-1 != 0) {
y2error ("Unable to backup current repos; Command >%1< returned: %2",
shellcommand, cmd
);
}
boolean success = nil;
foreach (string one_repo, current_repos, {
one_repo = repos_dir + "/" + one_repo;
y2milestone ("Removing target repository %1", one_repo);
success = (boolean) SCR::Execute (.target.remove, one_repo);
if (success != true) {
y2error ("Cannot remove %1 file", one_repo);
}
});
y2milestone ("All old repositories were removed from the target");
}
/* Check arguments */
if(size(WFM::Args()) > 0 && is(WFM::Args(0), string)) {
func = (string)WFM::Args(0);
if(size(WFM::Args()) > 1 && is(WFM::Args(1), map))
param = (map)WFM::Args(1);
}
y2milestone ("starting pkg_finish");
y2debug("func=%1", func);
y2debug("param=%1", param);
if (func == "Info")
{
return (any)$[
"steps" : 1,
// progress step title
"title" : _("Saving the package manager configuration..."),
"when" : [ `installation, `update, `autoinst ],
];
}
else if (func == "Write")
{
/*
File "/openSUSE-release.prod" is no more on the media
but directly in the RPM. Don't create the directory
and don't copy the file manually anymore.
(since evrsion 2.17.5)
// Copy information about product (bnc#385868)
// FIXME: this is a temporary hack containing a hardcoded file name
string media_prod = Pkg::SourceProvideOptionalFile (
Packages::theSources[0]:0, 1,
"/openSUSE-release.prod");
if (media_prod != nil)
{
WFM::Execute (.local.bash, sformat ("test -d %1%2 || mkdir %1%2",
Installation::destdir, "/etc/zypp/products.d"));
WFM::Execute (.local.bash, sformat ("test -d %3%2 && /bin/cp %1 %3%2",
media_prod, "/etc/zypp/products.d", Installation::destdir));
}
*/
// Remove (backup) all sources not used during the update
// BNC #556469: Backup and remove all the old repositories before any Pkg::SourceSaveAll call
if (Stage::initial() && Mode::update()) {
BackUpAllTargetSources();
}
// See bnc #384827, #381360
if (Mode::update()) {
y2milestone ("Adding default repositories");
WFM::call ("inst_extrasources");
}
Pkg::SourceCacheCopyTo (Installation::destdir);
// save all repositories and finish target
Pkg::SourceSaveAll ();
Pkg::TargetFinish();
// copy list of failed packages to installed system
WFM::Execute (.local.bash, sformat (
"test -f %1 && /bin/cp -a %1 '%2%1'",
"/var/lib/YaST2/failed_packages",
String::Quote (Installation::destdir)));
}
else
{
y2error ("unknown function: %1", func);
ret = nil;
}
y2debug("ret=%1", ret);
y2milestone("pkg_finish finished");
return ret;
} /* EOF */
ACC SHELL 2018