home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 May / Chip_2000-05_cd2.bin / suse / inst-sys / lib / YaST2 / clients / inst_sw_select.ycp < prev    next >
Encoding:
Text File  |  2000-03-30  |  13.8 KB  |  472 lines

  1.  
  2. /**
  3.  * Module:         inst_sw_select.ycp
  4.  *
  5.  * Authors:        Mathias Kettner <kettner@suse.de>
  6.  *            Klaus Kaempf <kkaempf@suse.de> (initial)
  7.  *            Stefan Hundhammer <sh@suse.de>
  8.  *            Stefan Schubert <schubi@suse.de>
  9.  *
  10.  * Purpose:
  11.  * Displays software selection screen. Show checkboxes for software
  12.  * categories. Let the user select his software.
  13.  *
  14.  * user_settings read:    "softwaresel"
  15.  *            "language"
  16.  *            "install_info"
  17.  *
  18.  *
  19.  * user_settings write: "softwaresel"
  20.  *            "install_info"
  21.  *
  22.  *
  23.  *
  24.  * 
  25.  *
  26.  * $Id: inst_sw_select.ycp,v 1.38 2000/03/09 10:47:44 kkaempf Exp $
  27.  */
  28.  
  29. {
  30.     // ------------------------------------------------------------------------
  31.     // collect mountpoint:device as map to get a sorted list
  32.  
  33.     boolean going_backwards = Args(2);
  34.  
  35.     map targetMap = lookup(user_settings, "targets", $[]);
  36.     if ( lookup(user_settings, "test_mode", false) == true )
  37.     {
  38.        // TEST VALUES !!!
  39.     targetMap = $[
  40.               "/dev/sda":$[
  41.                        "bus":"SCSI",
  42.                        "name":"1. SCSI, 8.54 GB, /dev/sda, IBM-DNES-309170W",
  43.                        "cyl_count":1114,                               
  44.                        "cyl_size":8224768,                            
  45.                        "vendor":"IBM DNES-309170W",                      
  46.                        "partitions":[
  47.                              $["fsid":131,    // YES: mount
  48.                               "mount":"/boot",        
  49.                               "fstype":"Linux native",
  50.                               "nr":1,
  51.                               "region":[1, 254],
  52.                               "type":`primary],
  53.                              $["delete":true,    // NO: no mount
  54.                                "fsid":130,
  55.                               "fstype":"Linux swap",
  56.                               "nr":2,
  57.                               "region":[255, 299],
  58.                               "type":`primary],
  59.                              $["create":false,    // NO: create false
  60.                                "fsid":131,
  61.                               "mount":"/var",
  62.                               "fstype":"Linux native",
  63.                               "nr":3,
  64.                               "region":[300, 499],
  65.                               "type":`primary],
  66.                              $["create":true,      // YES: create true + mount  
  67.                                "fsid":131,
  68.                                "mount":"/",
  69.                                "nr":4,
  70.                                "format":true,
  71.                                "region":[500, 844],
  72.                                "type":`primary
  73.                              ]
  74.                        ]
  75.               ],
  76.               "/dev/sdb":$[
  77.                        "bus":"SCSI",
  78.                        "name":"1. SCSI, 8.54 GB, /dev/sda, IBM-DNES-309170W",
  79.                        "cyl_count":11141,                               
  80.                        "cyl_size":8224768,                            
  81.                        "vendor":"IBM DNES-309170-XEW",                      
  82.                        "partitions":[
  83.                              $["fsid":131,        // NO: nothing
  84.                               "fstype":"Linux native",
  85.                               "nr":1,
  86.                               "region":[1, 254],
  87.                               "type":`primary],
  88.                              $["create":true,        // NO: no mount
  89.                                "fsid":130,
  90.                               "fstype":"Linux swap",
  91.                               "nr":2,
  92.                               "region":[255, 299],
  93.                               "type":`primary],
  94.                              $["delete":true,        // NO: delete false
  95.                                "fsid":131,
  96.                               "mount":"/var",
  97.                               "fstype":"Linux native",
  98.                               "nr":3,
  99.                               "region":[300, 499],
  100.                               "type":`primary],
  101.                              $[ "delete":false,          // YES: delete true
  102.                                "fsid":130,
  103.                               "mount":"/usr",
  104.                               "fstype":"Linux swap", // user-visible string
  105.                               "nr":4,    // partition number, as seen by linux (!)
  106.                               "region": [500,10871], // start end of region in cyl.s
  107.                               "use":true,  // mark as 'used' in inst_target_partition
  108.                               "type":`primary    
  109.                              ]
  110.                        ] ] ];
  111.   
  112.        // End TEST VALUES 
  113.     }
  114.  
  115.     if (!going_backwards) {
  116.  
  117.         // debug
  118.     SCR(`Write (.dumpto.tmp.targets, targetMap));
  119.  
  120.     map mountPoints = $[];
  121.     list swapPoints = [];
  122.  
  123.     foreach (`targetdevice,`target, targetMap, ``{
  124.         any partitions = lookup ( target, "partitions" );
  125.         foreach (`partition, partitions, ``{
  126.         string partitionName = targetdevice + lookup (partition, "nr", 0 );
  127.         string mountPoint = lookup (partition, "mount", "" );
  128.         integer fsid = lookup (partition, "fsid", 0);
  129.         if (mountPoint != "") {
  130.             if (mountPoint == "swap")
  131.             swapPoints = add (swapPoints, [partitionName, fsid, targetdevice]);
  132.             else
  133.             mountPoints = add (mountPoints, mountPoint, [partitionName, fsid, targetdevice]);
  134.         }
  135.         });
  136.     });
  137.  
  138.     if (size (swapPoints) > 0)
  139.         mountPoints = add (mountPoints, "swap", swapPoints);
  140.  
  141.     SCR(`Write (.dumpto.tmp.mounts, mountPoints));
  142.     user_settings = add(user_settings, "mountpoints", mountPoints);
  143.     }
  144.  
  145.     // ------------------------------------------------------------------------
  146.  
  147.     list current_sel     = lookup(user_settings, "softwaresel", [.default]);
  148.     // setting user_settings:softwaresel, if it has not been set
  149.     user_settings = add(user_settings, "softwaresel", current_sel);
  150.     string language      = lookup(user_settings, "language", default_language);
  151.     boolean retval = false;
  152.  
  153.     _debug("Current softwaresel:", current_sel);
  154.  
  155.     map lang2yast1 = $[
  156.       "en_GB"    : "english",
  157.       "en_US"    : "english",
  158.       "en"     : "english",
  159.       "de_DE"    : "german",
  160.       "de_CH"    : "german",
  161.       "de"      : "german",
  162.       "br_FR"    : "french",
  163.       "fr_FR"    : "french",
  164.       "fr_CH"    : "french",
  165.       "fr"       : "french",
  166.       "it_IT"    : "italian",
  167.       "es_ES"    : "spanish",
  168.       "nl_NL"    : "dutch",
  169.       "pt_PT"    : "portuguese",
  170.       "pt_BR"    : "brazilian",
  171.       "hu_HU"    : "hungarian",
  172.       "pl_PL"    : "polish",
  173.       "el_GR"    : "greek",
  174.       "ru_RU.KOI8-R" : "russian",
  175.       "cs_CZ"    : "czech",
  176.       "sk_SK"    : "slovak"
  177.     ];
  178.  
  179.  
  180.     string  long_language     = lookup(lang2yast1, language, "english");
  181.  
  182.     //
  183.     // Initialize PKGINFO server
  184.     //
  185.  
  186.  
  187.     string infopath =  "/var/adm/mount/suse/setup/descr";
  188.     string dudir = "/var/adm/mount/suse/setup/du/du.dir";
  189.     
  190.     if ( lookup(user_settings, "test_mode", false) )
  191.     {
  192.     // TEST VALUES !!!
  193.  
  194.     dudir =  "/dist/6.3-i386/suse/setup/du/du.dir";
  195.  
  196.     infopath = "/dist/6.3-i386/suse/setup/descr";
  197.  
  198.     }
  199.  
  200.     UI(`OpenDialog(`opt(`decorated ),`Label(_("One moment please..."))));
  201.  
  202.     // Get information about available partitions
  203.     list partition = get_partition_info( targetMap, true );
  204.  
  205.     retval = PKGINFO (`setEnvironment( 
  206.         $["packageinfopath":infopath, "common.pkd":"common.pkd", "language":long_language, 
  207.         "dudir":dudir,    "partition":partition]
  208.         ));
  209.  
  210.     PKGINFO( `setDebugLevel(0) );
  211.  
  212.     UI(`CloseDialog());
  213.  
  214.     _debug( "Return setEnvironment:", retval );
  215.  
  216.     // screen title for software selection
  217.     locale title = _("Software Selection");
  218.  
  219.     list pacsels = [];
  220.     
  221.     if ( lookup(user_settings, "test_mode", false) )
  222.     {
  223.     pacsels = filter(`sel,
  224.           Read("/lib/YaST2/pacsel/index.ycp"),
  225.               ``(select(sel, 1) != .paylist));
  226.     }
  227.     else
  228.     {
  229.     pacsels = filter(`sel,
  230.           Read("/var/adm/mount/suse/setup/descr/pacsel/index.ycp"),
  231.               ``(select(sel, 1) != .paylist));
  232.     }
  233.  
  234.     // Construct Box with Checkbox for each software category
  235.  
  236.     // Title of frame around "basic software"
  237.     term baseconfs = `VBox();
  238.  
  239.     foreach(`sel, pacsels, ``{
  240.     path   selid   = select(sel, 0);
  241.     path   group   = select(sel, 1);
  242.     map    langmap = select(sel, 2);
  243.  
  244.     string seldesc = translate(langmap, language );
  245.  
  246.     if ( group == .baseconf )
  247.     {
  248.         baseconfs = add(baseconfs, `Left(`RadioButton(`id(selid),`opt(`notify),
  249.                             seldesc,
  250.                             contains (current_sel, selid))));
  251.     }
  252.     });
  253.  
  254.     string wrn_msg = "";
  255.     boolean added = false;
  256.  
  257.     // Checking: already selected addons or single selection?
  258.     if ( size(current_sel) > 1 || PKGINFO ( `isSingleSelected() ) )
  259.     {
  260.     // Display warning message
  261.     wrn_msg = UI(_("\
  262. You have already chosen something from \"Detailed selection\"\n\
  263. You will lose that selection if you change the basic selection."));
  264.     added = true;
  265.     }
  266.     
  267.     // Build and show dialog
  268.     
  269.     term contents = `HVSquash(
  270.                   `VBox(`VBox(
  271.                       `HSquash(`Frame( "", `RadioButtonGroup(`id(`baseconf),`opt(`notify), baseconfs) )),
  272.                       `Label( " " ),    // just to add some spacing
  273.                       // Push button that will pop up the detailed
  274.                       // software selection (e.g. Multimedia, Games,
  275.                       // KDE, Gnome, ... - not the individual packages!)
  276.                       `PushButton( `id(`details),  _("&Detailed selection...") )
  277.                       ),
  278.                     `Label( " " ),
  279.                     `Label( `id(`wrn_label), wrn_msg )
  280.                     )
  281.                  );
  282.  
  283.  
  284.     // explain choosable system configurations
  285.     // but beware: some of the text in <b>'s, e.g. Default comes from the index file,
  286.     // translations must be consistent with po/index/index.??.po
  287.     // help part 1 of 3
  288.     string helptext = UI(_("<p>
  289. The SuSE Linux <b>Default</b> system is a good software
  290. base for most systems. You will not need to insert all of the CDs that 
  291. come with SuSE Linux for this selection. Further software from the
  292. other CDs can always be added later. 
  293. </p>"));
  294.     // help part 2 of 3
  295.     helptext = helptext + UI(_("<p>
  296. The <b>Minimal</b> system includes just the bare essentials necessary
  297. to safely run SuSE Linux. Please notice that this selection <b><i>does not include
  298. graphical desktop environments</i></b>, i.e. no X11, no KDE, no Gnome etc.
  299. Select this option as a base for your own custom selection, for
  300. dedicated server systems that don't need a graphical desktop or for
  301. systems that are short on disk space and/or memory.
  302. </p>"));
  303.     // help part 3 of 3
  304.     helptext = helptext + UI(_("<p>
  305. <b>Almost everything</b> includes every software package that comes
  306. with SuSE  Linux except the sources. Please make sure you have a lot of
  307. disk space available when you select this option.
  308. </p>
  309.  
  310. <p>
  311. For more control about what software to install select
  312. <b>Detailed selection</b>.
  313. </p>
  314. <br>"));
  315.  
  316.  
  317.  
  318.     UI(`SetWizardContents(title, contents, helptext, Args(0),Args(1)));
  319.  
  320.  
  321.     // get all packages to install
  322.     list package_list = CallFunction( `inst_pkg_toinstall( user_settings ) );    
  323.  
  324.     _debug ( "Required packages:", package_list );
  325.  
  326.     // Initialize server with the packages which have to be installed, but without resetting 
  327.     // single-selected packages.
  328.     PKGINFO ( `setInstallSelection ( package_list, true ) );
  329.     PKGINFO ( `setSourceInstallation(lookup(user_settings, "install_sources", false)) );
  330.  
  331.     any ret = nil;
  332.     boolean error_found = false;
  333.     while (true)
  334.     {
  335.  
  336.         list(map) required_partition = PKGINFO ( `getDiskSpace ( partition ) )   ;
  337.         
  338.     _debug("Required partitions :",required_partition );
  339.  
  340.     // Construct a popup like:
  341.     // +-----------------------------------------------+
  342.     // | Partition / needs 200 KB more disk space.     |
  343.     // | Partition etc needs 40 MB more disk space.    |
  344.     // |                                               |
  345.     // | Please deselect some packages.                |
  346.     // +-----------------------------------------------+
  347.         string message = "";
  348.  
  349.         foreach( `par, required_partition,
  350.           ``{ 
  351.             if ( lookup( par, "free", 0 ) < 0 )
  352.             {
  353.                     message = message + sformat ( UI(_("Partition \"%1\" needs %2 more disk space.")),
  354.                                             lookup ( par, "name" ), 
  355.                         UI( `size_text(lookup ( par, "free" ) * -1 *1024) ) ) + "\n";
  356.             }
  357.               } );            
  358.     if ( size ( message ) > 0 )
  359.         {
  360.          message = message + "\n" +  UI(_("Please deselect some packages."));
  361.             _debug("Warning:", message );
  362.                 UI(`DisplayMessage(message));
  363.          error_found = true;
  364.         }
  365.     else
  366.         {
  367.          error_found = false;
  368.         }
  369.  
  370.     list save_sel = [];
  371.     save_sel = add(save_sel, UI(`QueryWidget(`id(`baseconf), `CurrentButton)));
  372.  
  373.         ret = UI(`UserInput());
  374.  
  375.         // Add the selection of the basic group
  376.         current_sel = [];
  377.     current_sel = add(current_sel, UI(`QueryWidget(`id(`baseconf),`CurrentButton)));
  378.  
  379.     if ( save_sel != current_sel )
  380.         {
  381.         // boolean single = PKGINFO ( `isSingleSelected());
  382.         // _debug ( "isSingleSelected:", single );
  383.         // single is replaced by added -> see above
  384.         
  385.         if ( !added
  386.          || UI(`YesOrNo(_("Do you really want\nto reset your detailed selection?"), _("&Yes"), _("&No") ) ) )
  387.         {
  388.         user_settings = add(user_settings, "softwaresel", current_sel);
  389.         _debug( "Add current_sel to user_settings: ", current_sel );
  390.                 // Reset source-selected
  391.         user_settings = add(user_settings, "install_sources", false);
  392.  
  393.         list package_list = CallFunction( `inst_pkg_toinstall( user_settings ) );    
  394.  
  395.         _debug ( "Required packages:", package_list );
  396.  
  397.         // Initialize pkginfo-server and reset ALL single-selected packages
  398.         PKGINFO ( `setInstallSelection ( package_list ) );
  399.         PKGINFO ( `setSourceInstallation(lookup(user_settings, "install_sources", false)) );
  400.  
  401.         if ( added )
  402.         {
  403.             // rebuild
  404.             ret = `again;
  405.             break;  
  406.         }
  407.         else
  408.         {
  409.                     // goto size-calculation
  410.             continue;
  411.         }
  412.         
  413.         }
  414.         else
  415.         {
  416.         // rebuild the former selected RadioButton
  417.         ret = `again;
  418.         break;
  419.         }
  420.     }
  421.         
  422.         if (ret == `cancel || ret == `back ) break;
  423.  
  424.         if ( ret == `details )
  425.         {
  426.          any details_ret = `again;
  427.          while ( details_ret == `again )
  428.          {
  429.              details_ret = CallFunction( `inst_sw_details( true, true ) );
  430.            }
  431.  
  432.          if ( details_ret == `back )
  433.              {
  434.              ret = `again;
  435.              }
  436.          else if ( details_ret == `next )
  437.              ret = `next;
  438.          else if ( details_ret == `cancel )
  439.              ret = `cancel;
  440.            break;
  441.         }
  442.  
  443.     if ( ret == `next && !error_found ) break;
  444.  
  445.     }
  446.  
  447.     if ( ret == `next )
  448.     {
  449.     // setting user_setting.install_info for packages which have to be installed
  450.     list install_info =  PKGINFO ( `getInstallSet() );
  451.     _debug ( "Writing install_info: ", install_info );
  452.     user_settings = add ( user_settings , "install_info", install_info );
  453.  
  454.     // get totally used space for package selection
  455.     list(map) req_part = PKGINFO( `getDiskSpace( partition ) );
  456.     integer used = 0;
  457.     
  458.     foreach( `part, req_part,
  459.          ``{
  460.         used = used + lookup( part, "used" );
  461.     } );  
  462.     _debug( "Totally used space: ", used*1024 );
  463.  
  464.     user_settings = add ( user_settings, "neededspace", used*1024 );
  465.  
  466.         // adding manual packages
  467.     CallFunction( `inst_add_pkg_toinstall( user_settings ) );    
  468.     }
  469.     _debug ( "inst_sw_select return :", ret );
  470.     return ret;
  471. }
  472.