ACC SHELL

Path : /usr/share/YaST2/modules/
File Upload :
Current File : //usr/share/YaST2/modules/Mode.ycp

/**
 * File:	modules/Mode.ycp
 * Module:	yast2
 * Summary:	Installation mode
 * Authors:	Klaus Kaempf <kkaempf@suse.de>
 * Flags:	Stable
 *
 * $Id: Mode.ycp 61236 2010-03-10 15:39:50Z mvidner $
 *
 * Provide installation mode information.
 * Mostly values from /etc/install.inf
 * See linuxrc documentation for detailed docs about this.
 */

{

module "Mode";

textdomain "base";

/**
 * Current mode
 */
string _mode = nil;

/**
 * Current testing mode
 */
string _test = nil;

/**
 * We do one automatic check whether _test should be set to testsuite.
 */
boolean test_autochecked = false;

/**
 * Current UI mode
 */
string _ui = "dialog";


/**
 * initialize everything from command-line of y2base
 */
global void Initialize () {
    _mode = "normal";
    _test = "none";
    integer arg_count = size(WFM::Args());
    integer arg_no = 0;
    while ( arg_no < arg_count )
    {
	// parsing for main mode
	if (WFM::Args(arg_no) == "initial"
	    || WFM::Args(arg_no) == "continue"
	    || WFM::Args(arg_no) == "firstboot")
        {
	    _mode = "installation";
        }
	// parsing for test mode
	else if (WFM::Args(arg_no) == "test" || WFM::Args(arg_no) == "demo")
	{
	    _test = "test";
	    y2warning("***** Test mode enabled *****");
	}
	else if (WFM::Args(arg_no) == "screenshots"  )
	{
	    _test = "screenshot";
	    y2warning("***** Screen shot mode enabled *****");
	}

	arg_no = arg_no + 1;
    }

    // only use the /etc/install.inf agent when file is present
    // and installation is being processed
    // FIXME remove the part below and let it be set in clients
    if (_mode == "installation"
	&& SCR::Read (.target.size, "/etc/install.inf") != -1)
    {
	boolean autoinst = SCR::Read (.etc.install_inf.AutoYaST) != nil;
        if (autoinst)
        {
	    _mode="autoinstallation";
        }

	boolean repair = SCR::Read (.etc.install_inf.Repair ) != nil;
        if (repair)
        {
	    _mode ="repair";
        }
    }
}

// main mode definitions

/**
 * Returns the current mode name. It's one of
 * "installation", "normal", "update", "repair", "autoinstallation", "autoinst_config"
 */
global string mode () {
    if (_mode == nil)
    {
	Initialize ();
    }

    return _mode;
}

global void SetMode (string new_mode) {
    if (_mode == nil)
	Initialize ();

    if (! contains (
	[ "installation", "update", "normal", "repair",
	    "autoinstallation", "autoinst_config",
	    "live_installation"
	],
	new_mode))
    {
	y2error ("Unknown mode %1", new_mode);
    }

    y2milestone ("setting mode to %1", new_mode);
    _mode = new_mode;
}

global boolean commandline();

// test mode definitions

global string testMode () {
    if (_test == nil)
	Initialize ();
    if (!test_autochecked) {
        // bnc#243624#c13: Y2ALLGLOBAL is set by yast2-testsuite/skel/runtest.sh
        if (getenv ("Y2MODETEST") != nil || getenv ("Y2ALLGLOBAL") != nil) {
	    _test = "testsuite";
	}
	test_autochecked = true;
    }

    return _test;
}

global void SetTest (string new_test_mode) {
    if (_test == nil)
	Initialize ();

    if (! contains (
	[ "none", "test", "demo", "screenshot", "testsuite", ],
	new_test_mode))
    {
	y2error ("Unknown test mode %1", new_test_mode);
    }
    _test = new_test_mode;
}

// UI mode definitions

/**
 * Returns the current UI mode.
 * It's one of "commandline", "dialog", "none"
 */
global string ui () {
    return _ui;
}

global void SetUI (string new_ui) {
    if (! contains (
	[ "commandline", "dialog", "none", ],
	new_ui))
    {
	y2error ("Unknown UI mode %1", new_ui);
    }
    _ui = new_ui;
}

// main mode wrappers

/**
 * we're doing a fresh installation
 */
global boolean installation () {
    return mode () == "installation" || mode () == "autoinstallation"
	|| mode () == "live_installation";
}

/**
 * we're doing a fresh installation from live CD/DVD
 */
global boolean live_installation () {
    return mode () == "live_installation";
}

/**
 * we're doing an update
 */
global boolean update () {
    return mode () == "update";
}

global boolean Depeche () {
    return true;
}

/**
 * normal, running system
 */
global boolean normal () {
    return mode () == "normal";
}

/**
 * start repair module
 */
global boolean repair () {
    return mode () == "repair";
}

/**
 * doing auto-installation
 */
global boolean autoinst () {
    return mode () == "autoinstallation";
}

/**
 * configuration for auto-installation, only in running system
 */
global boolean config () {
    return mode () == "autoinst_config";
}

// test mode wrappers

/**
 * Just testing.
 * See installation/Test-Scripts/doit*
 */
global boolean test () {
    return testMode () == "test" || testMode () == "screenshot"
        || testMode () == "testsuite";
}

/**
 * dump screens to /tmp. Implies @ref #demo .
 * See installation/Test-Scripts/yast2-screen-shots*
 */
global boolean screen_shot () {
    return testMode () == "screenshot";
}

/**
 * Returns whether running in testsuite.
 */
global boolean testsuite () {
    return testMode () == "testsuite";
}

// UI mode wrappers

/**
 * we're running in command line interface
 * @return true if command-line is running
 */
global boolean commandline () {
    return ui () == "commandline";
}

} // EOF

ACC SHELL 2018