ACC SHELL
/**
* File: modules/AutoInstall.ycp
* Package: Auto-installation
* Summary: Auto-installation related functions module
* Author: Anas Nashif <nashif@suse.de>
*
* $Id: AutoInstall.ycp 61896 2010-04-28 12:05:15Z ug $
*/
{
module "AutoInstall";
textdomain "autoinst";
import "Profile";
import "Mode";
import "Stage";
import "AutoinstConfig";
import "AutoInstallRules";
import "Report";
import "TFTP";
global boolean autoconf = false;
global define boolean callbackTrue_boolean_string(string dummy) {
return true;
}
global define boolean callbackFalse_boolean_string(string dummy) {
return false;
}
global define boolean callbackTrue_boolean_string_integer(string dummy, integer dummy2) {
return true;
}
global define boolean callbackFalse_boolean_string_integer(string dummy, integer dummy2) {
return false;
}
global define void callback_void_map(map<string,any> dummy_map) {
return;
}
global define boolean callbackTrue_boolean_map(map<string,any> dummy_map) {
return true;
}
global define boolean callbackFalse_boolean_map(map<string,any> dummy_map) {
return false;
}
global define boolean callbackTrue_boolean_map_integer(map<string,any> dummy_map, integer dummy) {
return true;
}
global define boolean callbackFalse_boolean_map_integer(map<string,any> dummy_map, integer dummy) {
return false;
}
global define boolean callbackTrue_boolean_string_map_integer(string dummy, map<string,any> dummy_map, integer dummy_int) {
return true;
}
global define boolean callbackFalse_boolean_string_map_integer(string dummy, map<string,any> dummy_map, integer dummy_int) {
return false;
}
global define boolean callbackTrue_boolean_string_string(string dummy1, string dummy2) {
return true;
}
global define boolean callbackFalse_boolean_string_string(string dummy1, string dummy2) {
return false;
}
global define boolean callbackTrue_boolean_string_string_integer(string dummy1, string dummy2, integer dummy3) {
return true;
}
global define boolean callbackFalse_boolean_string_string_integer(string dummy1, string dummy2, integer dummy3) {
return false;
}
global define boolean callbackTrue_boolean_string_string_string(string dummy1, string dummy2, string dummy3) {
return true;
}
global define boolean callbackFalse_boolean_string_string_string(string dummy1, string dummy2, string dummy3) {
return false;
}
/**
* Read saved data in continue mode
* @return boolean true on success
*/
global define boolean Continue()
{
//
// First check if there are some other control files availabe
// i.e. for post-installation only
//
boolean ret = false;
if ( SCR::Read(.target.size, AutoinstConfig::autoconf_file) != -1 )
{
y2milestone("XML Post installation data found: %1", AutoinstConfig::autoconf_file );
ret = Profile::ReadXML ( AutoinstConfig::autoconf_file );
SCR::Execute(.target.bash, sformat("/bin/mv %1 %2",
AutoinstConfig::autoconf_file, AutoinstConfig::cache));
return (ret);
}
else
{
ret = Profile::ReadProfileStructure ( AutoinstConfig::parsedControlFile );
if ( Profile::current == $[] || !ret ) {
y2milestone( "No saved autoinstall data found" );
return (false);
} else {
y2milestone( "Found and read saved autoinst data");
SCR::Execute(.target.remove, AutoinstConfig::parsedControlFile);
return (true);
}
}
return false;
}
/**
* Constructer
* @return void
*/
global define void AutoInstall()
{
if (Stage::cont ())
{
boolean ret = Continue();
if (ret && size ( Profile::current ) > 0) {
y2milestone("Enabling Auto-Installation mode");
Mode::SetMode("autoinstallation");
} else if (Mode::autoinst ()) {
y2milestone("No autoyast data found, switching back to manual installation");
Mode::SetMode("installation");
}
}
else if (Stage::initial ())
{
if ( SCR::Read(.target.size, AutoinstConfig::xml_tmpfile) != -1
&& size ( Profile::current ) == 0)
{
y2milestone("autoyast: %1 found", AutoinstConfig::xml_tmpfile);
// Profile is available and it has not been parsed yet.
Profile::ReadXML( AutoinstConfig::xml_tmpfile );
}
}
return;
}
/**
* Save configuration
* @return boolean true on success
*/
global define boolean Save()
{
if (Mode::autoinst ())
return (Profile::SaveProfileStructure( AutoinstConfig::parsedControlFile ));
else
return true;
}
/**
* Finish Auto-Installation by saving misc files
* @param string destdir
* @return void
*/
global define void Finish ( string destdir )
{
list dircontents = (list)SCR::Read(.target.dir, AutoinstConfig::tmpDir
+ "/pre-scripts/");
if (size(dircontents) > 0 )
{
SCR::Execute(.target.bash, "/bin/cp " + AutoinstConfig::tmpDir
+ "/pre-scripts/* " + destdir + AutoinstConfig::scripts_dir);
SCR::Execute(.target.bash, "/bin/cp " + AutoinstConfig::tmpDir
+ "/pre-scripts/logs/* " + destdir + AutoinstConfig::logs_dir);
}
SCR::Execute(.target.bash, sformat("/bin/cp %1 %2%3",
"/tmp/profile/autoinst.xml" , destdir , AutoinstConfig::xml_file) );
SCR::Execute(.target.bash, sformat("/bin/chmod 700 %1%2",
destdir , AutoinstConfig::xml_file) );
SCR::Execute(.target.bash, sformat("/bin/cp %1 %2%3",
AutoinstConfig::profile_dir+"/pre-autoinst.xml" , destdir , AutoinstConfig::cache) );
SCR::Execute(.target.bash, sformat("/bin/chmod 700 %1%2",
destdir , AutoinstConfig::cache+"/pre-autoinst.xml") );
return;
}
/**
* Put PXE file on the boot server using tftp
* @return true on success
*/
global boolean PXELocalBoot ()
{
string tmpdir = (string)SCR::Read(.target.tmpdir);
string hexfile = sformat("%1/%2", tmpdir, AutoInstallRules::hostid );
map pxe = Profile::current["pxe"]:$[];
string dest_file = pxe["filename"]:AutoInstallRules::hostid;
if( dest_file == "__MAC__" ) {
string mac = AutoInstallRules::mac;
dest_file = sformat ("01-%1-%2-%3-%4-%5-%6", substring(mac,0,2), substring(mac,2,2), substring(mac,4,2),
substring(mac,6,2), substring(mac,8,2), substring(mac,10,2));
}
string server = pxe["tftp-server"]:"";
if (server!="" && pxe["pxe_localboot"]:false)
{
y2milestone("putting pxe local boot file '%2' on server :%1", server, dest_file);
string config = pxe["pxelinux-config"]:"";
string dir = pxe["pxelinux-dir"]:"pxelinux.cfg";
if (config == "")
{
config = "DEFAULT linux\nLABEL linux\n localboot 0";
}
SCR::Write(.target.string, hexfile, config);
return TFTP::Put(server, dir + "/" + dest_file, hexfile );
}
return true;
}
/**
* Turn off the second stage of autoyast
*
*/
global boolean TurnOff () {
if( ! Profile::current["general","mode","second_stage"]:true ) {
y2milestone("switching from autoinstallation to manual installation in second stage");
SCR::Execute(.target.bash, "/bin/grep -v -i '^autoyast:' /etc/install.inf > /tmp/install.inf.new");
SCR::Execute(.target.bash, "/bin/mv /tmp/install.inf.new /etc/install.inf");
}
}
//EOF
}
ACC SHELL 2018