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

  1. /**
  2.  * Module:         inst_target_selection.ycp
  3.  *
  4.  * Authors:         Klaus Kaempf (kkaempf@suse.de)
  5.  *
  6.  * Purpose:         This module selects the harddisk(s) for installation.
  7.  *            -Harddisk recognition
  8.  *            -Selecting the harddisk for the installation by
  9.  *             the user ( if possible harddisks > 1 ).
  10.  *            -Write selected harddisk(s) into "target_is" of user_settings
  11.  *
  12.  * user_settings:    "target_is":<devicename> (key to "targets" map)
  13.  *            if custom, set "target_is":"CUSTOM"
  14.  *
  15.  * $Id: inst_target_selection.ycp,v 1.66 2000/03/09 10:54:33 kkaempf Exp $
  16.  */
  17. {
  18.     boolean test_mode    = lookup ( user_settings, "test_mode", false );
  19.  
  20.     // if we get here in update mode it's a BUG
  21.  
  22.     if (lookup ( user_settings, "instmode", `install) == `update) {
  23.     return `cancel;
  24.     }
  25.  
  26.     // reset old target selections and partitionings
  27.  
  28.     define reset_target (map target_info) ``{
  29.     list partitions = lookup (target_info, "partitions", []);
  30.  
  31.     // filter out all "create" paritions, they will be re-created at exit
  32.     //   (this ensures a 'clean' partition list if this dialogue is re-entered
  33.  
  34.     partitions = filter (`pentry, partitions, ``(!lookup (pentry, "create", false)));
  35.  
  36.     // reset all "delete" paritions, they will be re-created at exit
  37.     //   (this ensures a 'clean' partition list if this dialogue is re-entered
  38.  
  39.     partitions = maplist (`pentry, partitions, ``(add (pentry, "delete", false)));
  40.  
  41.     return add (target_info, "partitions", partitions);
  42.     };
  43.  
  44.     define check_for_reset (string old_target, string new_target, map targets) ``{
  45.     if (old_target == "")
  46.         return $[];
  47.     if (old_target == new_target)
  48.         return $[];
  49.  
  50.     if (old_target == "CUSTOM") {
  51.        // clear all old targets
  52.        map new_targets = $[];
  53.        foreach (`tname, `tinfo, targets, ``{
  54.           new_targets = add (new_targets, tname, reset_target (tinfo));
  55.        });
  56.        targets = new_targets;
  57.     }
  58.     else {
  59.        // just clear the old target
  60.        //   (the new target will be cleared in the following module
  61.        targets = add (targets, old_target, reset_target (lookup (targets, old_target, $[])));
  62.     }
  63.  
  64.     return targets;
  65.     };
  66.  
  67.   map targetMap = lookup ( user_settings, "targets", $[]);
  68.   string target_is  = lookup ( user_settings, "target_is", "");
  69.  
  70.   if ( test_mode && (targetMap == nil) || (size(targetMap) == 0) ) {
  71.       y2log(.warning, "inst_target_part", 1, "***** Test mode active - using fake values *****");
  72.  
  73.       targetMap =
  74.       $[
  75.         "/dev/hda":
  76.           $[
  77.             "bus" : "IDE", "cyl_count" : 53040, "cyl_size" : 516096,
  78.             "device" : "/dev/hda", "name" : "1. IDE, 25.49 GB, /dev/hda, (empty)",
  79.             "partitions" : [ ],
  80.             "vendor" : "WDC"
  81.           ],
  82.         "/dev/hdb":
  83.           $[
  84.             "bus" : "IDE", "cyl_count" : 53040, "cyl_size" : 516096,
  85.             "device" : "/dev/hdb", "name" : "2. IDE, 25.49 GB, /dev/hdb, (windows)",
  86.             "partitions" : [
  87.               $["fsid" : 1, "fstype" : "FAT12",
  88.                 "nr" : 1, "region" : [ 0, 513 ], "type" : `primary
  89.               ]
  90.             ],
  91.             "vendor" : "WDC"
  92.           ],
  93.         "/dev/hdc":
  94.           $[
  95.             "bus" : "IDE", "cyl_count" : 53040, "cyl_size" : 516096,
  96.             "device" : "/dev/hdc", "name" : "3. IDE, 25.49 GB, /dev/hdb, (full)",
  97.             "partitions" : [
  98.               $["fsid" : 4, "fstype" : "FAT16",
  99.                 "nr" : 1, "region" : [ 0, 513 ], "type" : `primary
  100.             ],
  101.               $["fsid" : 4, "fstype" : "FAT16",
  102.                 "nr" : 2, "region" : [ 513, 513 ], "type" : `primary
  103.             ],
  104.               $["fsid" : 4, "fstype" : "FAT16",
  105.                 "nr" : 3, "region" : [ 1026, 513 ], "type" : `primary
  106.             ],
  107.               $["fsid" : 4, "fstype" : "FAT16",
  108.                 "nr" : 4, "region" : [ 1539, 51500 ], "type" : `primary
  109.             ]
  110.             ],
  111.             "vendor" : "WDC"
  112.           ],
  113.         "/dev/sda" :
  114.           $[
  115.             "bus" : "SCSI", "cyl_count" : 8748, "cyl_size" : 1048576,
  116.             "device" : "/dev/sda", "name" : "1. SCSI, 8.54 GB, /dev/sda, (linux)",
  117.             "partitions" : [
  118.               $["fsid" : 130, "fstype" : "Linux swap",
  119.                 "nr" : 1, "region" : [ 0, 513 ], "type" : `primary
  120.               ],
  121.               $["fsid" : 131,"fstype" : "Linux native",
  122.                 "nr" : 2, "region" : [ 513, 8235 ], "type" : `primary
  123.               ]
  124.             ],
  125.             "vendor" : "IBM"
  126.           ],
  127.         "/dev/sdb" :
  128.           $[
  129.             "bus" : "SCSI", "cyl_count" : 8748, "cyl_size" : 1048576,
  130.             "device" : "/dev/sdb", "name" : "2. SCSI, 8.54 GB, /dev/sda, (apple)",
  131.             "partitions" : [
  132.               $["fsid" : 130, "fstype" : "Linux swap",
  133.                 "nr" : 1, "region" : [ 0, 513 ], "type" : `pdisk
  134.               ],
  135.               $["fsid" : 131,"fstype" : "Linux native",
  136.                 "nr" : 2, "region" : [ 513, 8235 ], "type" : `pdisk
  137.               ]
  138.             ],
  139.             "vendor" : "IBM"
  140.           ]
  141.       ];
  142.  
  143.       user_settings = add( user_settings, "targets", targetMap );
  144.   }
  145.  
  146.   term contents = `Dummy();
  147.  
  148.   if (size(targetMap) != 0) {
  149.  
  150.     if (test_mode) y2log (.milestone, "inst_target_selection", 1, "found targetMap, target_is "+target_is);
  151.  
  152.     // loop over targetMap and build radio buttons for selection
  153.     // dont use foreach here since we need a counter (as a shortcut)
  154.     // anyway
  155.  
  156.     term buttonbox = `VBox();
  157.  
  158.     integer i = 0;
  159.     foreach (`tname, `tdata, targetMap, ``{
  160.     string tline = "&" + (i+1) + ": " + lookup (tdata, "name", "?");
  161.     buttonbox = add(buttonbox, `Left(`RadioButton(`id(tname), tline, (target_is == tname))));
  162.     i = i + 1;
  163.     });
  164.  
  165.     buttonbox = add(buttonbox, `Label( " " ) );
  166.     buttonbox = add(buttonbox, `Left(`RadioButton(`id("CUSTOM"),
  167.                           // Check box for expert partitioning mode rather than
  168.                           // just selecting one of the hard disks and use
  169.                           // a standard partitioning scheme
  170.                           _( "&Custom partitioning - for experts" ),
  171.                           (target_is == "CUSTOM")
  172.                           )
  173.                      )
  174.             );
  175.  
  176.     // This dialog selects the target disk for the installation.
  177.     // Below this label, all targets are listed that can be used as installation target
  178.  
  179.     contents = `Frame ( _("Choose a hard disk"),
  180.             `RadioButtonGroup(`id(`options), `HSquash(buttonbox) )
  181.             );
  182.   }
  183.   else {
  184.     if (test_mode) y2log (.milestone, "inst_target_selection", 1, "NO targetMap");
  185.     // normally the target is located on hard disks. Here no hard disks can be found.
  186.     // YaST2 cannot install - now the fallback YaST must be used
  187.     contents = `Label (_("No disks found, please use the update CD for installation."));
  188.   }
  189.  
  190.  
  191.   // There are several hard disks found. Linux is completely installed on
  192.   // one hard disk - this selection is done here
  193.   // "Preparing Hard Disk - Step 1" is the description of the dialog what to do
  194.   // while the following locale is the help description
  195.   // help part 1 of 3
  196.   string helptext = UI(_("<p>
  197. All hard disks that have been automatically detected on your system
  198. are shown here. Please select the hard disk to install SuSE Linux on.
  199. </p>"));
  200.   // help part 2 of 3
  201.   helptext = helptext + UI(_("
  202. <p>
  203. Under certain conditions not all of your hard disks might be
  204. auto-detected properly. If you wish to install SuSE Linux on such a
  205. hard disk, you might want to use <b>YaST1</b> as described in the manual.
  206. </p>"));
  207.   // help part 3 of 3
  208.   helptext = helptext + UI(_("
  209. <p>
  210. For experts, there is the <b>custom partitioning</b> option for full
  211. control about how to partition your hard disk(s) and assigning
  212. partitions to your SuSE Linux installation.
  213. </p>
  214. <br>"));
  215.  
  216. // first step of hd prepare, select a single disk or "expert" partitioning
  217.   any dlg = UI(`SetWizardContents( _("Preparing Hard Disk - Step 1" ),
  218.                   contents, helptext, Args(0), Args(1)));
  219.   any ret = nil;
  220.  
  221.   // Event handling
  222.  
  223.   any option = nil;
  224.  
  225.   while (option == nil) {
  226.     ret = UI(`UserInput());
  227.     if (ret == `next || ret == `back) {
  228.       option = UI(`QueryWidget(`id(`options), `CurrentButton));
  229.       if (option == nil) {
  230.     if ( ret != `back ) {
  231.       // there is a selection from that one option has to be chosen - at the moment
  232.       // no option is chosen
  233.       UI(`DisplayMessage(_("You have to choose one of the\noptions in order to continue.")));
  234.       continue;
  235.     }
  236.       }
  237.       else if (option == "CUSTOM") {
  238.       map new_targets = check_for_reset (target_is, option, targetMap);
  239.       if (new_targets != $[])
  240.           user_settings = add (user_settings, "targets", new_targets);
  241.       user_settings = add (user_settings, "target_is", option);
  242.       }
  243.       else {
  244.       map new_targets = check_for_reset (target_is, option, targetMap);
  245.       if (new_targets != $[])
  246.           user_settings = add (user_settings, "targets", new_targets);
  247.       user_settings = add (user_settings, "target_is", option);
  248.       } // if (option)
  249.  
  250.     } // if (ret == back|next)
  251.  
  252.     break;
  253.  
  254.   } // while (option == nil)
  255.  
  256.   return ret;
  257. }
  258.