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

  1. /**
  2.  * Module:         inst_prepdisk.ycp
  3.  *
  4.  * Authors:        Mathias Kettner (kettner@suse.de) (initial)
  5.  *            Stefan Schubert (schubi@suse.de)
  6.  *
  7.  * Purpose:
  8.  * Displays a progress bar showing progress of disk preparation.
  9.  * The user has the opportunity to cancel the installation. The 
  10.  * disks are partitioned. Swap is created and used. File systems
  11.  * are created for the new partitions. Mount points are created
  12.  * and mounted for the targets /mnt and /mnt/boot.
  13.  *            
  14.  *            
  15.  *
  16.  * user_settings read:    "targets"
  17.  *            
  18.  *
  19.  * user_settings write: "boot_device"
  20.  *            "swap_device"
  21.  *            "root_device"
  22.  *
  23.  *            
  24.  * SCR:    Write(.disk + topath("." + substring (targetdevice, 5)) + .partitions, targetpartitions)
  25.  *    Write (.exec.mkdir, [ <mountpoint>, 0755 ])        
  26.  *    Shell ("/bin/mount <device> <mountpoint>")
  27.  *
  28.  * $Id: inst_prepdisk.ycp,v 1.69 2000/03/10 12:59:20 kkaempf Exp $
  29.  */
  30.  
  31. {
  32.   any      targets        = lookup ( user_settings, "targets" );
  33.   boolean test_mode        = lookup ( user_settings, "test_mode", false );
  34.   boolean this_is_for_real    = ! test_mode;
  35.  
  36.  
  37.   _debug ( "BEGINNING of inst_prepdisk" );
  38.   // Define macro that creates a dialog with progressbar
  39.  
  40.   UI(``{
  41.       define MakefsDialog() ``{
  42.     
  43.         // html-format
  44.       // advise the user to wait for completion
  45.       // part 1 of 2
  46.       string helptext = _("\
  47. <p>
  48. Please stand by while your hard disk is prepared.</p>");
  49.       // part 2 of 2
  50.     helptext = helptext + _("\
  51. <p>
  52. Depending on the size of your hard disk and your processor speed, this    action
  53. might take some time.  5 minutes are not unusal for disks larger than 4 GB.  
  54. Often, the progress meter doesn't show a linear progress; even if it looks 
  55. slow near the end (\"95 %\"), please be patient: the formatting    tool has to 
  56. perform various checks.    </p><br>");
  57.       // hard disk will be made ready for installing Linux
  58.       SetWizardContents(_("Preparing Your Harddisk"),
  59.                 `VBox(
  60.                   `ProgressBar(`id(`progress), " ", 100),
  61.                   `HCenter(// button: cancel harddisk preparation
  62.                        `PushButton(`id(`cancel), _("&Cancel")))), 
  63.                 helptext, false, false);
  64.       };
  65.   });
  66.  
  67.   // define macros for the ui that is called by the package
  68.   // installer in order to update the progressbars.
  69.  
  70.  
  71.   UI(``{
  72.       define UpdateProgressBar(integer percent)
  73.       ``{ 
  74.       ChangeWidget(`id(`progress), `Value, percent);
  75.       any r = PollInput();
  76.       // popup window after 'cancel' pressed: make sure user wants to quit installation
  77.       if (r == `Id(`cancel) && YesOrNo(_("Do you really want\nto quit the installation?")))
  78.           return `cancel;
  79.       return nil;
  80.       };
  81.   });
  82.  
  83.  
  84.   UI(`MakefsDialog());
  85.  
  86.   // Begin with the actual work
  87.   // 1. Partitioning all disks
  88.  
  89.  
  90.     // remember special devices for LILO
  91.     string boot_device = "";
  92.     list swap_devices = [];
  93.     string root_device = "";
  94.  
  95.     map running_swap = SCR(`Read(.run.swapon_s));
  96.  
  97.     foreach (`targetdevice,`target, targets, ``{
  98.     // every disk
  99.     any partitions = lookup ( target, "partitions" );
  100.     _debug("Target: ", targetdevice );
  101.     if ( this_is_for_real )    {
  102.         boolean result = 
  103.         SCR(`Write(.disk + topath("." + substring (targetdevice, 5)) + .partitions, partitions));
  104.  
  105.         if ( !result ) {
  106.         y2log (.error, "prepdisk", 1, "Oops, fdisk failed for device ", targetdevice);
  107.         string showOops = sformat (UI(_("The disk has an unsupported partition table\nPlease re-partition disk %1")), targetdevice);
  108.         UI(`DisplayMessage(showOops));
  109.         return `back;
  110.         }
  111.     }
  112.     foreach (`pentry, partitions, ``{
  113.               string device = targetdevice + lookup (pentry, "nr");
  114.         string mountpoint = lookup (pentry, "mount", "");
  115.         boolean do_format = lookup (pentry, "format", false);
  116.         if (!lookup (pentry, "delete", false)) {        // only those which aren't deleted
  117.             if (mountpoint == "/boot")
  118.             boot_device = device;
  119.             else if ((mountpoint == "swap")
  120.                  && (lookup (running_swap, substring (device, 4, size(device)), "") == ""))
  121.             swap_devices = add (swap_devices, [ device, do_format]);
  122.             else if (mountpoint == "/")
  123.             root_device = device;
  124.         }
  125.         _debug ("         Partition:",pentry );
  126.       });
  127.  
  128.     if ( boot_device == "" ) boot_device = root_device;
  129.  
  130.   });
  131.  
  132.   // Remember the devices for later, when we must unmount them
  133.  
  134.     user_settings = add(user_settings, "boot_device", boot_device);
  135.     if (size (swap_devices) > 0)
  136.     user_settings = add(user_settings, "swap_device", select (select (swap_devices, 0), 0));
  137.     user_settings = add(user_settings, "root_device", root_device);
  138.  
  139.   _debug("boot_device:", boot_device );
  140.   _debug("swap_devices:", swap_devices );
  141.   _debug("root_device:", root_device );
  142.  
  143.     if ( this_is_for_real ) {
  144.     // 2. Create and use swap devices
  145.     foreach (`swaplist, swap_devices, ``{
  146.         string swapdev = select (swaplist, 0);
  147.         if ((select (swaplist, 1) == true)        // format == yes ?
  148.         && (0 != Shell("mkswap "+ swapdev)))
  149.         UI(`DisplayMessage(sformat(UI(_("Couldn't setup swap partition %1")), swapdev)));
  150.         if (0 != Shell("swapon "+swapdev))
  151.         UI(`DisplayMessage(sformat(UI(_("Couldn't setup swap partition %1")), swapdev)));
  152.     });
  153.  
  154.     // 2.1 only 5% buffer vm
  155.  
  156. //    Shell ("echo 5 > /proc/sys/vm/bdflush");
  157.     }
  158.  
  159.   
  160.   // 3. Create filesystems
  161.  
  162.   boolean cancel = false;
  163.   integer fsid_native = 131;
  164.  
  165.   foreach (`targetdevice,`target, targets, ``{
  166.  
  167.     // every disk
  168.     any partitions = lookup ( target, "partitions" );
  169.  
  170.     foreach(`partition, partitions, ``{
  171.  
  172.             //every partition which is to be formatted
  173.         boolean format = lookup ( partition, "format", false);
  174.         string mountPoint = lookup (partition, "mount", "" );
  175.   
  176.               if ( !cancel
  177.          && format
  178.          && (partition != $[])
  179.          && (mountPoint != "")
  180.          && (mountPoint != "swap"))
  181.               {
  182.           // announce partition to be formatted
  183.           string partitionName = targetdevice + lookup (partition, "nr", 0 );
  184.           string mountPoint = lookup (partition, "mount", "" );
  185.  
  186.           UI(`ChangeWidget(`id(`progress), `Label, sformat(UI(_("Formatting %1 as %2")), partitionName, mountPoint)));
  187.             any ret = `ok;
  188.       
  189.             if ( this_is_for_real )
  190.             {
  191.                   // Format native (ext2fs and reiser) partitions
  192.  
  193.             if (lookup (partition, "fsid", 0) == fsid_native)
  194.             {
  195.                 if (lookup (partition, "used_fs", `unknown) == `reiser )
  196.                 {
  197.                 ret = CallModule("makereiserfs", [``UpdateProgressBar, partitionName, 0, 0]);
  198.                 }
  199.                 else
  200.                 {
  201.                 ret = CallModule("makefs", [``UpdateProgressBar, partitionName, 0, 0]);
  202.                 }
  203.                 UI(`SetModulename("inst_prepdisk"));
  204.             }
  205.             else
  206.                 ret = `ok;
  207.             }
  208.             else
  209.             {
  210.                   // Fake formatting
  211.  
  212.                   integer progress = 0;
  213.           
  214.                   while ( progress < 100 )
  215.                   {
  216.                   UI( `UpdateProgressBar ( progress ) );
  217.                   sleep ( 300 ); // millisec
  218.                   progress = progress + 3;
  219.                   }
  220.             }
  221.  
  222.       
  223.             if ( ret == `cancel )
  224.             {   
  225.                   cancel = true;
  226.             }
  227.             else if ( ret != `ok )
  228.             {
  229.                   // report any formatting errors
  230.                   // UI(`DisplayMessage(sformat(UI(_("Couldn't format partition %1")), partitionName)));
  231.             }
  232.         }
  233.       });
  234.   });
  235.  
  236.   
  237.   if ( cancel )
  238.       return `cancel;
  239.  
  240.     if ( this_is_for_real ) {
  241.  
  242.     // 4. Mount "/" and "/boot" and all other targets with mountpoints
  243.  
  244.     // now mount all native partitions with a mountpoint
  245.  
  246.     map mountPoints = lookup(user_settings, "mountpoints", $[]);
  247.  
  248.     Mkdir("/mnt");
  249.  
  250.     foreach (`mountpoint,`mountval, mountPoints, ``{
  251.         if ((mountpoint != "") && (mountpoint != "swap")) {
  252.         SCR(`Write (.exec.mkdir, [ "/mnt"+mountpoint, 0755 ]));
  253.         if (select (mountval, 1) == fsid_native) {
  254.             Shell ("/bin/mount "+select (mountval, 0)+" /mnt"+mountpoint);
  255.         }
  256.         }
  257.     });
  258.     Mkdir("/mnt/proc");
  259.     Shell ("/bin/mount -t proc proc /mnt/proc");
  260.     if (lookup (user_settings, "usb_type", 0) != 0)
  261.         Shell ("/bin/mount -t usbdevfs usbdevfs /mnt/proc/bus/usb");
  262.     }
  263.  
  264.   _debug ("END inst_prepdisk.ycp");
  265.  
  266.   return `next;
  267. }
  268.