ACC SHELL
/**
* File: modules/AutoinstFile.ycp
* Package: AutoYaST
* Authors: Anas Nashif (nashif@suse.de)
* Summary: Handle complete configuration file dumps
*
* $Id: AutoinstFile.ycp 57442 2009-06-04 12:51:31Z ug $
*/
{
module "AutoinstFile";
textdomain "autoinst";
import "AutoinstConfig";
import "Summary";
include "autoinstall/io.ycp";
/* default value of settings modified */
global boolean modified = false;
/**
* Function sets internal variable, which indicates, that any
* settings were modified, to "true"
*/
global define void SetModified () {
y2milestone("SetModified");
modified = true;
}
/**
* Functions which returns if the settings were modified
* @return boolean settings were modified
*/
global define boolean GetModified () {
return modified;
}
global list<map> Files = [];
/**
* Settings Summary
*/
global define string Summary() ``{
string summary = "";
summary = Summary::AddHeader(summary, _("Configured Files:"));
if (size( Files ) > 0)
{
summary = Summary::OpenList(summary);
foreach(map file, Files, ``{
summary = Summary::AddListItem(summary, file["file_path"]:"" );
});
summary = Summary::CloseList(summary);
}
else
{
summary = Summary::AddLine(summary, Summary::NotConfigured());
}
return summary;
}
/**
* Import Settings
*/
global define boolean Import (list<map> settings) ``{
Files = settings;
return true;
}
/**
* Export Settings
*/
global define list<map> Export () ``{
return Files;
}
/**
* Write Settings
*/
global define boolean Write ()
{
import "AutoInstall";
y2milestone("Writing Files to the system");
if ( size( Files )==0 )
{
return true;;
}
integer counter = 0;
boolean success = false;
foreach(map file, Files,
``{
string alternate_location = sformat("%1/%2", AutoinstConfig::files_dir, counter);
string alter_file = sformat("file_%1", counter);
if( size(file["file_path"]:"dummy")-1 == findlastof(file["file_path"]:"", "/") ) {
// directory
SCR::Execute (.target.mkdir, file["file_path"]:alternate_location);
} else if (file["file_contents"]:"" != "") {
y2milestone("AutoInstall: Copying file %1", file["file_path"]:alternate_location );
list t = splitstring( file["file_path"]:alternate_location, "/");
integer pos = size(t) - 1;
// SCR::Write (.target.string, AutoInstall::var_dir + "/files" + t[pos]:alter_file, file["file_contents"]:"");
SCR::Write (.target.string, file["file_path"]:alternate_location , file["file_contents"]:"");
} else if( file["file_location"]:"" != "" ) {
if( issubstring( file["file_location"]:"", "relurl://" ) ) {
string l = file["file_location"]:"";
l = substring ( l, 9 );
string newloc = "";
if( AutoinstConfig::scheme == "relurl" ) {
y2milestone("autoyast profile was relurl too");
newloc = (string)SCR::Read(.etc.install_inf.ayrelurl);
map tok = URL::Parse(newloc);
y2milestone("tok = %1", tok);
newloc = tok["scheme"]:"" + "://" + tok["host"]:"" + "/" + dirname(tok["path"]:"") + l;
} else {
newloc = AutoinstConfig::scheme + "://" + AutoinstConfig::host + "/" + AutoinstConfig::directory + l;
}
file["file_location"] = newloc;
y2milestone("changed relurl to %1 for file", newloc);
}
y2milestone("trying to get file from %1 storing in %2", file["file_location"]:"", file["file_path"]:alternate_location);
if (!GetURL(file["file_location"]:"", file["file_path"]:alternate_location ) ) {
y2error("file could not be retrieved");
} else {
y2milestone("file was retrieved");
}
}
if (file["file_permissions"]:"" != "") {
SCR::Execute (.target.bash, sformat("chmod %1 %2", file["file_permissions"]:"", file["file_path"]:alternate_location ));
}
if (file["file_owner"]:"" != "") {
SCR::Execute (.target.bash, sformat("chown %1 %2", file["file_owner"]:"", file["file_path"]:alternate_location ));
}
map script = file["file_script"]:$[];
if (script != $[])
{
string current_logdir = AutoinstConfig::logs_dir;
list name_tok = splitstring(file["file_path"]:alternate_location, "/");
string scriptName = "";
if (size(name_tok)>0)
{
string name = name_tok[size(name_tok) - 1 ]:"";
scriptName = "script_" + name;
}
string scriptPath = sformat("%1/%2", AutoinstConfig::scripts_dir, scriptName);
y2milestone("Writing (file) script into %1", scriptPath);
SCR::Write(.target.string, scriptPath, script["source"]:"echo Empty script!");
// string message = sformat(_("Executing user supplied script: %1"), scriptName);
string scriptInterpreter = script["interpreter"]:"shell";
string executionString = "";
if (scriptInterpreter == "shell")
{
executionString = sformat("/bin/sh -x %1 2&> %2/%3.log", scriptPath, current_logdir, scriptName);
SCR::Execute (.target.bash, executionString);
}
else if (scriptInterpreter == "perl")
{
executionString = sformat("/usr/bin/perl %1 2&> %2/%3.log", scriptPath, current_logdir, scriptName);
SCR::Execute (.target.bash,executionString);
}
else if (scriptInterpreter == "python")
{
executionString = sformat("/usr/bin/python %1 2&> %2/%3.log", scriptPath, current_logdir, scriptName);
SCR::Execute (.target.bash,executionString);
}
else
{
y2error("Unknown interpreter: %1", scriptInterpreter);
}
y2milestone("Script Execution command: %1", executionString );
}
success = ( SCR::Execute (.target.bash, sformat("cp %1 %2", file["file_path"]:alternate_location, AutoinstConfig::files_dir)) == 0 );
counter = counter + 1;
});
return success;;
}
}
ACC SHELL 2018