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

  1.  
  2. /**
  3.  * Module:         inst_rpmcopy.ycp
  4.  *
  5.  * Authors:        Mathias Kettner (kettner@suse.de)
  6.  *            Klaus Kaempf (kkaempf@suse.de) (initial)
  7.  *
  8.  * Purpose: 
  9.  * Install all the RPM packages the user has selected.
  10.  * Show installation dialogue. Show progress bars.
  11.  * Request CD change from user.
  12.  *
  13.  * user_settings read:    "continue_mode"
  14.  *            "language"
  15.  *            "install_info"
  16.  *            "packages_installed"
  17.  *
  18.  * user_settings write: ---
  19.  *             
  20.  *            
  21.  * SCR: Read(.yast2.instsource.cdnum)    
  22.  *
  23.  * $Id: inst_rpmcopy.ycp,v 1.84.4.1 2000/03/22 16:43:01 kkaempf Exp $
  24.  */ 
  25.  
  26. {
  27.     integer maxnumbercds = 8;
  28.  
  29.     map installMap = SCR(`Read(.etc.install_inf));
  30.  
  31.     // Check if the source is remountable
  32.     boolean remountable = true;
  33.  
  34.     string boot_src = "";
  35.     integer current_cd = 0;
  36.     string bootmode = lookup (installMap, "bootmode", "");
  37.     list cddrives = [];
  38.     list cddevices = [];
  39.  
  40.     if (bootmode == "CD") {
  41.     boot_src = "/dev/" + lookup (installMap, "cdrom", "cdrom");
  42.     cddevices = add (cddevices, boot_src);
  43.     cddrives = SCR(`Read(.probe.byclass.storage_device.cdrom));
  44.     foreach (`drive, cddrives, ``{
  45.         if (!contains (cddevices, drive))
  46.         cddevices = add (cddevices, lookup (drive, "dev_name", ""));
  47.     });
  48.     remountable = true;
  49.     }
  50.     else if (bootmode == "Net") {
  51.     boot_src = lookup (installMap, "server", "")
  52.            + ":"
  53.            + lookup (installMap, "serverdir", "");
  54.     cddevices = add (cddevices, boot_src);
  55.     integer nfscd = 1;
  56.     while (nfscd <= maxnumbercds) {
  57.         cddevices = add (cddevices, boot_src + "/CD" + nfscd);
  58.         nfscd = nfscd + 1;
  59.     }
  60.     remountable = false;
  61.     }
  62.     else if (bootmode == "Harddisk") {
  63.     boot_src = lookup (installMap, "partition", "");
  64.     cddevices = add (cddevices, boot_src);
  65.     integer hdcd = 1;
  66.     while (hdcd <= maxnumbercds) {
  67.         cddevices = add (cddevices, boot_src + "/CD" + hdcd);
  68.         hdcd = hdcd + 1;
  69.     }
  70.     remountable = false;
  71.     }
  72.     y2log (.milestone, "inst_rpmcopy", 1, sformat("bootmode: %1, boot_src: %2, remountable: %3, cddevices: %4", bootmode, boot_src, remountable, cddevices));
  73.  
  74.     // Tell the user to change the CD.
  75.     define ChangeCD(integer cdnum) ``{
  76.     if (size (cddevices) == 0) {
  77.         Shell ("/bin/mount "+boot_src+" /var/adm/mount");
  78.     }
  79.     else {
  80.         current_cd = 0;
  81.         Shell ("/bin/mount "+select(cddevices, current_cd)+" /var/adm/mount");
  82.     }
  83.     
  84.     integer|void actcdnum = nil;
  85.     while (true) {
  86.         actcdnum = SCR(`Read(.yast2.instsource.cdnum));
  87.         if (actcdnum == cdnum) return true;
  88.         else {
  89.         Shell ("/bin/umount /var/adm/mount");
  90.         current_cd = current_cd+1;
  91.         if (current_cd >= size (cddevices)) {        // list exhausted
  92.             current_cd = 0;                // restart at 0
  93.             // advise user to insert the right CD
  94.             string message = sformat(UI(_("Please insert CD %1.")), cdnum);
  95.             if (is(actcdnum, integer)) 
  96.             // inform user about current CD
  97.             message = sformat(UI(_("%1\nCurrently CD %2 is inserted.")), message, actcdnum);
  98.             UI(`DisplayMessage(message));
  99.         }
  100.         if (size (cddevices) == 0) {
  101.             Shell ("/bin/mount "+boot_src+" /var/adm/mount");
  102.         }
  103.         else {
  104.             Shell ("/bin/mount "+select(cddevices, current_cd)+" /var/adm/mount");
  105.         }
  106.         }
  107.     }
  108.     };
  109.  
  110.     UI(``{
  111.     define RpmDialog(integer maxpacs) ``{
  112.         // Announce number of packages that will be installed
  113.         SetWizardContents(sformat(_("Installing %1 software packages"), maxpacs), 
  114.                   `VBox(
  115.                     `ProgressBar(`id(`package), " ", 100),
  116.                     `ProgressBar(`id(`numpacs), " ", maxpacs),
  117.                     // Label for disk usage progress bar
  118.                     `ProgressBar(`id(`diskusage), _("Disk Usage"), 100),
  119.                     `PushButton(`id(`cancel), _("&Cancel"))),
  120.                   // report software will be installed
  121.                   _("\
  122. <p>
  123. The selected software will be installed.
  124. </p>
  125.  
  126. <p>
  127. And if you're feeling bored watching this screen take the time to
  128. browse through appendix F of
  129. the manual; this appendix tries to answer <em>Frequently Asked
  130. Questions</em> (FAQ).
  131. </p>
  132.  
  133. <p>
  134. Don't hesitate to have a look at the <em>SuSE Support Database</em> 
  135. (http://sdb.suse.de) if you want to know more about the
  136. software coming with <b>SuSE Linux</b>.
  137. </p>
  138. <br>
  139. "), false, false);
  140.     };
  141.     });
  142.  
  143.     // define macros for the ui that is called by the package
  144.     // installer in order to update the progressbars.
  145.  
  146.     UI(``{
  147.     define ShowProgressBars(
  148.         string pacname,
  149.         string pack_descr,
  150.         integer percent,
  151.         integer current_number,
  152.         integer disk_usage,
  153.         integer disk_capacity)
  154.         ``{ 
  155.         // display package and package description
  156.         ChangeWidget(`id(`package),   `Label, sformat(_("%1 - %2"), pacname, pack_descr));
  157.         ChangeWidget(`id(`package),   `Value, percent);
  158.         // inform user about installation progress
  159.         ChangeWidget(`id(`numpacs),   `Label, sformat(_("%1 packages installed"), current_number+1));
  160.         ChangeWidget(`id(`numpacs),   `Value, current_number+1);
  161.         integer how_much = (disk_usage * 100) / disk_capacity;
  162.         ChangeWidget(`id(`diskusage), `Value, how_much);
  163.         if (how_much > 95) {
  164.         // warn user about exhausted diskspace during installation of packages
  165.         // this is a popup with options "continue" and "cancel"
  166.         if (!ContinueCancel(_("Diskspace exhausted !"),
  167.             // Continue button
  168.             _("C&ontinue"),
  169.             // Cancel button
  170.             _("&Cancel") ) )
  171.           return `diskfull;
  172.         }
  173.         any r = PollInput();
  174.         // in case of cancel ask user if he really wants to quit installation
  175.         if (r == `cancel && YesOrNo(_("Do you really want\nto quit the installation?"), _("&Yes"), _("&No")))
  176.         return `cancel;
  177.         return nil;
  178.     };
  179.     });
  180.  
  181.     boolean continue_mode = lookup(user_settings, "continue_mode", false);
  182.     string language = lookup(user_settings, "language", default_language);
  183.  
  184.     string target = "/mnt";
  185.     if (continue_mode) {
  186.     target = "/";
  187.  
  188.     string ckb_cmd = lookup(user_settings, "ckb_cmd", "");
  189.     string xkb_cmd = lookup(user_settings, "xkb_cmd", "");
  190.  
  191.     UI(`SetLanguage(language));
  192.     if (ckb_cmd != "")
  193.         Shell (ckb_cmd);
  194.     if (xkb_cmd != "")
  195.         Shell (xkb_cmd);
  196.     y2log (.milestone, "continue", 1, "lang: "+language+"; ckb: "+ckb_cmd+"; xkb: "+xkb_cmd);
  197.  
  198.     UI(`SetConsoleFont (lookup(user_settings, "console_magic", ""),
  199.                 lookup(user_settings, "console_font", ""),
  200.                 lookup(user_settings, "console_screenmap", ""),
  201.                 lookup(user_settings, "console_unicodemap", "")));
  202.  
  203.     }
  204.  
  205.     // List of all packages to install
  206.     list install_info = [];
  207.  
  208.     // Prepare the source
  209.     string source = "/var/adm/mount/suse/";
  210.  
  211.     if (continue_mode) {
  212.     Shell("echo "+ "'YaST2 Version " + SCR(`Read(.probe.version)) + "' > /dev/tty2");
  213.     y2log (.milestone, "inst_rpmcopy", 3, "Starting second part of package installation");
  214.         install_info = Read("/var/lib/YaST2/pacs_to_install.ycp");
  215.     }
  216.     else {
  217.     y2log (.milestone, "inst_rpmcopy", 4, "Starting first part of package installation");
  218.     // Make sure, CD 1 is inserted
  219.     ChangeCD(1);
  220.  
  221.     // save info and update.in_ from CD1 for generating update.inf for YaST1
  222.     // see inst_finish for update.inf generation
  223.  
  224.     string shellcmd = "cp " + source + "setup/descr/info /tmp/info";
  225.     Shell (shellcmd);
  226.     shellcmd = "cp " + source + "setup/descr/update.in_ /tmp/update.in_";
  227.     Shell (shellcmd);
  228.  
  229.     // Initialize the target system.
  230.     CallModule("packager", [nil, `init, `root(target)]);
  231.     UI(`SetModulename("inst_rpmcopy"));
  232.  
  233.     install_info = lookup(user_settings, "install_info");
  234.     }
  235.  
  236.     // Now that we know how many packages to install, we can show the dialog
  237.     
  238.     integer packages_installed = 0;
  239.  
  240.     if (continue_mode) {
  241.     // get the number of already installed packages
  242.     packages_installed = lookup (user_settings, "packages_installed", 0);
  243.     }
  244.     y2log (.milestone, "inst_rpmcopy", 1, sformat("%1 packages have been installed", packages_installed));
  245.  
  246.     any dlg = UI(`RpmDialog(size(install_info) + packages_installed));
  247.  
  248.     if (!continue_mode) {
  249.     // First install the base system. This has to be done with the %pre
  250.     // and %post scripts handled separately and not by rpm, because
  251.     // without a minimal system being installed no scripts can be executed
  252.     // chroot in the new system.  We filter the pacdesc list and extract
  253.     // only the base packages, and only those that are contained in our
  254.     // package selection. This filtered list we convert into a list
  255.     // containing only the package filename and the label in the current
  256.     // language.
  257.  
  258.     // Base packages must be on CD1
  259.     list base_packages = filter(`v, install_info, ``(select(v, 3) && (select(v, 2) == 1)));
  260.     _debug(base_packages);
  261.  
  262.     any ret = 
  263.         CallModule("packager", [``ShowProgressBars, `add(source, base_packages), 
  264.                  `root(target), 
  265.                  `manual_scripts,
  266.                  `number(0)]);
  267.  
  268.     UI(`SetModulename("inst_rpmcopy"));
  269.  
  270.     packages_installed = packages_installed + size(base_packages);
  271.  
  272.     if (ret == `cancel) return `cancel;
  273.     if (ret == `diskfull) break;
  274.     else if (ret == `error) UI(`DisplayMessage(_("RPM returned an error")));
  275.     else if (ret != `ok) UI(`DisplayMessage(_("The packager returned an unknown code")));
  276.  
  277.     // Filter out the packages for the first round of install
  278.     install_info = filter(`v, install_info, ``(!(select(v, 3) && (!remountable || (select(v, 2) == 1)))));
  279.     }
  280.  
  281.     // Install the software from CD1 to CDmax, but not the already
  282.     // installed base packages
  283.  
  284.     integer cdnum = 1;
  285.     while (cdnum <= maxnumbercds)
  286.     {
  287.     list this_cd_packages =    
  288.         filter(`v, install_info, ``(select(v, 2) == cdnum)); 
  289.     y2log (.debug, "inst_rpmcopy", 6, sformat("this_cd_packages: %1", this_cd_packages));
  290.  
  291.     if (this_cd_packages != []) 
  292.     {
  293.         if (remountable) ChangeCD(cdnum);
  294.         any ret = CallModule("packager", [``ShowProgressBars, `add(source, this_cd_packages),
  295.                                        `root(target), 
  296.                                        `number(packages_installed)]);
  297.         UI(`SetModulename("inst_rpmcopy"));
  298.         packages_installed = packages_installed + size(this_cd_packages);
  299.         if (ret == `cancel) return `cancel;
  300.         if (ret == `diskfull) break;
  301.     }
  302.  
  303.     install_info = filter(`v, install_info, ``(select(v, 2) != cdnum));
  304.  
  305.     // break on first round with CDs
  306.     if (!continue_mode && remountable) break;
  307.  
  308.     cdnum = cdnum + 1;
  309.     }
  310.  
  311.     if (!continue_mode) {
  312.         // Write out a list of packages that must be installed
  313.         // in the second phase
  314.     Write("/mnt/var/lib/YaST2/pacs_to_install.ycp", install_info);
  315.     user_settings = add (user_settings, "packages_installed", packages_installed);
  316.     }
  317.     else
  318.     // Everything done, remove that thing.
  319.     Shell("rm /var/lib/YaST2/pacs_to_install.ycp");
  320.  
  321.     if (remountable) {
  322.     Shell ("/bin/umount /var/adm/mount");
  323.     }
  324.  
  325.     return `next;
  326. }
  327.