ACC SHELL
/**
* File:
* switch_scr_finish.ycp
*
* Module:
* Step of base installation finish
*
* Authors:
* Jiri Srain <jsrain@suse.cz>
*
* $Id: switch_scr_finish.ycp 55088 2009-01-27 16:17:17Z locilka $
*
*/
{
textdomain "installation";
import "Directory";
import "Installation";
include "installation/scr_switch_debugger.ycp";
any ret = nil;
string func = "";
map param = $[];
/**
* SCR Switch failed. Reporting error, collecting data.
* We don't ask whether to run the debugger, just run it.
*
* bnc #201058, #411832
*/
void ErrorDuringSCRSwitch (string chroot_dir) {
y2error("Cannot switch to SCR '%1', running debugger", chroot_dir);
RunSCRSwitchDebugger(chroot_dir);
}
/**
* Check the new SCR, bnc #433057
*
* @return boolean whether successful
*/
boolean TestTheNewSCR () {
y2milestone ("Running some tests on the new SCR");
map ret_exec = (map) SCR::Execute (.target.bash_output, "TEST=OK; echo ${TEST}");
if (ret_exec["exit"]:-1 != 0) {
y2milestone ("SCR::Execute: %1", ret_exec);
y2error ("SCR Error");
return false;
}
list ret_dir = (list) SCR::Read(.target.dir, "/");
if (ret_dir == nil || ret_dir == []) {
y2milestone ("SCR::Read/dir: %1", ret_dir);
y2error ("SCR Error");
return false;
}
list scr_dir = (list) SCR::Dir(.sysconfig);
if (scr_dir == nil || scr_dir == []) {
y2milestone ("SCR::Dir: %1", scr_dir);
y2error ("SCR Error");
return false;
}
y2milestone ("SCR seems to be OK");
return true;
}
void CheckFreeSpaceNow () {
map ret_exec = (map) SCR::Execute (.target.bash_output, "/bin/df -h");
if (ret_exec["exit"]:-1 != 0) {
y2error ("Cannot find out free space: %1", ret_exec);
} else {
y2milestone ("Free space: \n%1", mergestring (splitstring (ret_exec["stdout"]:"", "\\n"), "\n"));
}
}
boolean TestTheNewSCRHandler () {
integer SCR_PID = FindSCRPID();
if (SCR_PID > 0) SwitchY2Debug (SCR_PID);
boolean ret = TestTheNewSCR();
if (SCR_PID > 0) SwitchY2Debug (SCR_PID);
// BNC #460477
CheckFreeSpaceNow();
return ret;
}
/* 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 switch_scr_finish");
y2debug("func=%1", func);
y2debug("param=%1", param);
if (func == "Info")
{
return (any)$[
"steps" : 1,
// progress step title
"title" : _("Moving to installed system..."),
"when" : [ `installation, `live_installation, `update, `autoinst ],
];
}
else if (func == "Write")
{
// --------------------------------------------------------------
// stop SCR
// restart on destination
y2milestone ("Stopping SCR");
WFM::SCRClose (Installation::scr_handle);
// --------------------------------------------------------------
y2milestone ("Re-starting SCR on %1", Installation::destdir);
Installation::scr_handle = WFM::SCROpen ("chroot="+Installation::destdir+":scr", false);
y2milestone ("new scr_handle: %1", Installation::scr_handle);
// bugzilla #201058
// WFM::SCROpen returns negative integer in case of failure
if (Installation::scr_handle == nil || Installation::scr_handle < 0) {
y2error ("Cannot switch to the system");
ErrorDuringSCRSwitch (Installation::destdir);
return false;
}
Installation::scr_destdir = "/";
WFM::SCRSetDefault (Installation::scr_handle);
// re-init tmpdir from new SCR !
Directory::ResetTmpDir();
// bnc #433057
// Even if SCR switch worked, run a set of some simple tests
if (TestTheNewSCRHandler() != true) {
y2error ("Cannot switch to the system");
ErrorDuringSCRSwitch (Installation::destdir);
return false;
}
}
else
{
y2error ("unknown function: %1", func);
ret = nil;
}
y2debug("ret=%1", ret);
y2milestone("switch_scr_finish finished");
return ret;
} /* EOF */
ACC SHELL 2018