ACC SHELL

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

/**
 * File:
 *   modules/AutoinstClone.ycp
 *
 * Package:
 *   Autoinstallation Configuration System
 *
 * Summary:
 *   Create a control file from an exisiting machine
 *
 * Authors:
 *   Anas Nashif <nashif@suse.de>
 *
 * $Id: AutoinstClone.ycp 59616 2009-11-19 13:42:28Z ug $
 *
 *
 */
{
    module "AutoinstClone";
    import "Mode";

    import "XML";
    import "Call";
    import "Profile";
    import "Y2ModuleConfig";
    import "Misc";
    import "Storage";
    import "AutoinstConfig";
    import "Report";

    include "autoinstall/xml.ycp";

    global map Profile = $[];
    integer bytes_per_unit = 0;


    // spceial treatment for base resources
    global list<string> base = [];

    // aditional configuration resources o be cloned
    global list<string> additional = [];


    /**
     * Constructor
     */
    global define void AutoinstClone()
    {
        //Mode::SetMode ("normal");
        return;
    }

    /**
     * Set root password
     */

     /* useless */
     /*
    define list root() ``{
        list<map> shadow = (list<map>) SCR::Read(.etc.shadow);
        map rootacct = (map) filter(map acct, shadow, ``(acct["username"]:"" == "root"))[0]:$[];
        list users = [];
        map rootacct_mod = $[];
        rootacct_mod["user_password"] = rootacct["password"]:"";
        rootacct_mod["encrypted"] = true;
        rootacct_mod["username"] = "root";
        users = add(users, rootacct_mod);
        return users;
    }
    */


    /**
     * Find mount points in running system
     * @param string device name
     * @param map partition
     * @param list mount points
     * @return string
     */
     /* useless */
     /*
    define string findMountpoint(string device, map p, list<map> mounts)
    {
        string mountPoint = "";
        foreach(map mount , mounts, ``{
            string m = sformat("%1%2", device ,  p["nr"]:nil);
            if (mount["spec"]:"" ==  m )
            {
                mountPoint = mount["file"]:"";
            }
        });
        return mountPoint;
    }
    */

    /**
     * Convert units to size
     * @param list region
     * @return integer size
     */
     /* useless */
     /*
    define integer units_to_size (list region)
    {
        integer units = (integer) region[1]:0;
        return (units * bytes_per_unit)  -  bytes_per_unit + 1;
    };
    */



    /**
     * General options
     * @return map general options
     */
    global define map General()
    {
        import "Mode";
        Mode::SetMode ("normal");

        map general = $[];
        map mouse = $[];
        mouse["id"]	    = Misc::SysconfigRead(.sysconfig.mouse.YAST_MOUSE, "probe" );
        general["mouse"]    = mouse;
        map mode = $[];
        mode["confirm"] = false;
        general["mode"] = mode;

        general["signature-handling"] = $[ 
            "accept_unsigned_file":true, 
            "accept_file_without_checksum":true, 
            "accept_unknown_gpg_key":true, 
            "accept_verification_failed":false, 
            "import_gpg_key":true,
            "accept_non_trusted_gpg_key":true
        ];

        Mode::SetMode ("autoinst_config");
        return general;
    }





     /**
      * Clone a Resource
      * @param string resource
      * @param map resource name
      * @return list
      */
     define boolean CommonClone(string resource, map resourceMap)
     {

         string data_type = resourceMap["X-SuSE-YaST-AutoInstDataType"]:"map";
         string auto = resourceMap["X-SuSE-YaST-AutoInstClient"]:"";
         resource = resourceMap["X-SuSE-YaST-AutoInstResource"]:resource;

         Call::Function(auto , ["Read"]);
         Call::Function(auto , ["SetModified"]);

         return true;

     }



     /**
      * Create a list of clonable resources
      * @return list list to be used in widgets
      */
     global define list createClonableList()
    {
         list items = [];
         foreach(string def_resource, map resourceMap, Y2ModuleConfig::ModuleMap, ``{
             y2debug("r: %1 => %2", def_resource, resourceMap["X-SuSE-YaST-AutoInstClonable"]:"false" );
             boolean clonable = ( resourceMap["X-SuSE-YaST-AutoInstClonable"]:"false" == "true" );
             if ( clonable ||
		  "partitioning" == def_resource || /* has no desktop file */
		  "software"     == def_resource || /* has no desktop file */
          "bootloader"   == def_resource )
             {
                 string desktop_file = substring( resourceMap["X-SuSE-DocTeamID"]:"", 4 );
                 string name = dpgettext("desktop_translations", "/usr/share/locale/", "Name("+desktop_file+".desktop): "+resourceMap["Name"]:"" );
                 if( name == "Name("+desktop_file+".desktop): "+resourceMap["Name"]:"" )
                     name = resourceMap["Name"]:"";
                 // Set resource name, if not using default value
                 string resource = resourceMap["X-SuSE-YaST-AutoInstResource"]:"";
                 if (resource == "")
                    resource = def_resource;
                 if (resource != "")
                 {
                     items = add(items, `item(`id(resource), name ) );
                 }
                 else
                 {
                     items = add(items, `item(`id(def_resource), name ) );
                 }
             }
         });
	 /* sort items for nicer display */
	 items = sort( term x, term y, (list<term>) items, {
	    /* x[1] corresponds to name */
	    return x[1]:"x" < y[1]:"y";
	 });
         return items;
     }

    /**
     * Build the profile
     * @return void
     */
    global define void Process()
    {
        y2debug("Additional resources: %1 %2", base, additional);
        Profile::Reset();
        Profile::prepare = true;
        Mode::SetMode("autoinst_config");
        foreach(string def_resource, map resourceMap, Y2ModuleConfig::ModuleMap, ``{

            // Set resource name, if not using default value
            string resource = resourceMap["X-SuSE-YaST-AutoInstResource"]:"";
            if (resource == "")
                resource = def_resource;
            y2debug("current resource: %1", resource);
            if (contains(additional, resource) )
            {
                boolean ret = CommonClone(def_resource, resourceMap);
            }

        });


        Call::Function("general_auto" , ["Import", General()]);
        Call::Function("general_auto" , ["SetModified"]);

        Call::Function("report_auto" , ["Import", Report::Export()]);
        Call::Function("report_auto" , ["SetModified"]);

        Profile::Prepare();
        return;
    }

    /**
     * Write the profile to a defined path
     * @param string outputFile Output file path
     * @return boolean true on success
     */
    global define boolean Write(string outputFile)
    {
        Process();
        boolean ret =  Profile::Save( outputFile );
        return ret;
    }


    /**
     * Export profile, Used only from within autoyast2
     * @return void
     */
    global define void Export()
        ``{

        import "Profile";
        Profile::Reset();
        Process();
        return;
    }
}

ACC SHELL 2018