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

  1.  
  2. /**
  3.  * Module:         inst_startup.ycp
  4.  *
  5.  * Authors:        Mathias Kettner (kettner@suse.de)
  6.  *            Klaus Kaempf (kkaempf@suse.de) (initial)
  7.  *
  8.  * Purpose: 
  9.  * This module does the startup:
  10.  * - Set hostname and domainname
  11.  * - Determine architecture and boot mode
  12.  * - Detect the mouse and mouse device (create /dev/mouse)
  13.  * - Detect floppy drives
  14.  * - Find IDE controllers and status enabled/disabled
  15.  * - Find SCSI controllers and status enabled/disabled
  16.  * - Find RAID controllers and status enabled/disabled
  17.  * - Probe all controllers for disks
  18.  * - Probe all disks for partition data
  19.  * 
  20.  *
  21.  * user_settings read: ---
  22.  *            
  23.  *
  24.  * user_settings write: "targets"
  25.  *            "architecture"
  26.  *            "boot_mode"
  27.  *            "has_floppy"
  28.  *            "mouse"
  29.  *            "mouse_id"
  30.  *
  31.  *            
  32.  * SCR: Read(.probe.architecture)
  33.  *    Read(.probe.boot_arch)
  34.  *    Read(.probe.byclass.mouse)              
  35.  *    Read(.probe.byclass.storage_device.floppy)        
  36.  *    Read(.probe.byclass.storage)
  37.  *    Read(.probe.again)
  38.  *    
  39.  *
  40.  * $Id: inst_startup.ycp,v 1.75 2000/03/09 14:14:34 kkaempf Exp $
  41.  */ 
  42.  
  43. {
  44.     // --------------------------------------------------------------
  45.     // determine architecture and start SCR()
  46.  
  47.     string architecture = SCR(`Read(.probe.architecture));
  48.     user_settings = add (user_settings, "architecture", architecture);
  49.  
  50.     // get test_mode flag from user_settings
  51.     boolean test_mode = lookup(user_settings, "test_mode", false);
  52.  
  53.     Shell("echo "+ "'YaST2 Version " + SCR(`Read(.probe.version)) + "' > /dev/tty2");
  54.  
  55.     // --------------------------------------------------------------
  56.     // set up dialogue
  57.  
  58.     term contents =
  59.      `VBox(
  60.     // startup text, same as in installation.ycp
  61.     `Left(`Heading ( _("YaST2\nInitializing ..."))),
  62.     // label to progress bar for startup initialization
  63.     `HVCenter(`ProgressBar(`id(`bar), _("Checking system")))
  64.      );
  65.     any dlg = UI(`SetWizardContents("", contents, "", false, false));
  66.  
  67.     // --------------------------------------------------------------
  68.     // Progress: 5 %        Startup
  69.  
  70.     integer pvalue = 10;
  71.     UI(`ChangeWidget(`id(`bar), `Value, pvalue));
  72.  
  73.     integer usb_type = SCR(`Read(.probe.usb_type));
  74.     user_settings = add (user_settings, "usb_type", usb_type);
  75.  
  76.     y2log (.milestone, "startup", 1, "usb_type "+usb_type);
  77.     // --------------------------------------------------------------
  78.     // Progress: 10 %     USB
  79.  
  80.     pvalue = 10;
  81.     UI(`ChangeWidget(`id(`bar), `Value, pvalue));
  82.  
  83.     // --------------------------------------------------------------
  84.     // Set hostname and domainname to something reasonable.
  85.     // Some programs depend on it (rpm install scripts, Xlib)
  86.  
  87.     if (!test_mode) {
  88.     Shell("hostname linux");
  89.     Shell("domainname local");
  90.  
  91.     // fallback for br_FR
  92.     Symlink ("/usr/share/locale/fr", "/usr/share/locale/br");
  93.     }
  94.  
  95.     string boot_mode = SCR(`Read(.probe.boot_arch));
  96.     user_settings = add (user_settings, "boot_mode", boot_mode);
  97.  
  98.     y2log (.milestone, "inst_startup", 1, "arch "+architecture+", boot "+boot_mode);
  99.  
  100.     // --------------------------------------------------------------
  101.     // mouse detection
  102.     // linuxrc only does a dummy mouse setup for x11
  103.     // the real mouse detection and activation is done here
  104.  
  105.     // hw-probe for mouse, result is a map since no subclass given
  106.     map|void mouseprobe = SCR(`Read(.probe.byclass.mouse));
  107.  
  108.     map mouse_map = $[];            // filled in later
  109.     string mouse_id = "";
  110.  
  111.     if ((mouseprobe != nil) && (mouseprobe != $[])) {
  112.  
  113.     // evaluate probed mice in the order PS/2, USB, serial, Busmouse
  114.  
  115.     list bus = lookup (mouseprobe, "ps2", []);
  116.     if (bus == []) bus = lookup (mouseprobe, "usb", []);
  117.     if (bus == []) bus = lookup (mouseprobe, "serial", []);
  118.     if (bus == []) bus = lookup (mouseprobe, "bus", []);
  119.  
  120.     if (bus != []) {
  121.  
  122.         // get value from bus, select first mouse
  123.         map firstmouse = select (bus, 0);
  124.  
  125.         map mprotocol = lookup (firstmouse, "mouse", $[]);
  126.         string mdevice = lookup (firstmouse, "dev_name", "");
  127.  
  128.         if ((size (mprotocol) > 0) && (mdevice != "")) {
  129.  
  130.         string mgpm   = lookup (mprotocol, "gpm", "");
  131.         string mxf86  = lookup (mprotocol, "xf86", "");
  132.         boolean emul3 = lookup (mprotocol, "emul3", true);
  133.  
  134.         if ((mgpm != "") || (mxf86 != "")) {
  135.             // fake device here, set /dev/mouse
  136.             mouse_map = $["gpm"      : mgpm,
  137.                   "xf86"  : mxf86,
  138.                   "device": "/dev/mouse",
  139.                   "emul3" : emul3 ];
  140.  
  141.             mouse_id = mgpm;
  142.             if (mdevice == "/dev/ttyS0") mouse_id = mouse_id + "0";
  143.  
  144.             if (!test_mode) {
  145.             Symlink (mdevice, "/dev/mouse"); 
  146.             SetXMouse (mouse_map);
  147.             }
  148.  
  149.             // re-enter real device for inst_finish
  150.             mouse_map = add (mouse_map, "device", mdevice);
  151.  
  152.         } // mouse data found in protocol
  153.  
  154.         } // mprotocol found
  155.  
  156.     } // known subclass (bus) found
  157.  
  158.     } // mouseprobe
  159.  
  160.     user_settings = add (user_settings, "mouse_id", mouse_id);
  161.     user_settings = add (user_settings, "mouse", mouse_map);
  162.  
  163.     y2log (.milestone, "startup", 1, "mouse_id "+mouse_id);
  164.  
  165.     // --------------------------------------------------------------
  166.     // Progress: 20 %        Mouse probed
  167.  
  168.     pvalue = 20;
  169.     UI(`ChangeWidget(`id(`bar), `Value, pvalue));
  170.  
  171.     // --------------------------------------------------------------
  172.     // do we have a floppy drive attached ?
  173.  
  174.     boolean has_floppy = false;
  175.     list|void floppy_drives = SCR(`Read(.probe.byclass.storage_device.floppy));
  176.     if (floppy_drives != nil) {
  177.     string floppy_device = lookup (select (floppy_drives, 0), "dev_name", "");
  178.     if (floppy_device != "") {
  179.         has_floppy = true;
  180.         user_settings = add (user_settings, "floppy_device", floppy_device);
  181.     }
  182.     }
  183.     user_settings = add (user_settings, "has_floppy", has_floppy);
  184.  
  185.     y2log (.milestone, "startup", 1, "floppy probed");
  186.  
  187.     // --------------------------------------------------------------
  188.     // Progress: 30 %        Floppy probed
  189.  
  190.     pvalue = 30;
  191.     UI(`ChangeWidget(`id(`bar), `Value, pvalue));
  192.  
  193.  
  194.     // --------------------------------------------------------------
  195.     // find 'storage' controllers
  196.  
  197.     // probe complete 'storage' tree, result is a map
  198.  
  199.     map|void controllers = SCR(`Read(.probe.byclass.storage));
  200.  
  201.     if (controllers == nil) {
  202.  
  203.     y2log (.milestone, "inst_startup", 4, "no controllers");
  204.  
  205.     // Oops, no storage controllers ?
  206.     return `cancel;
  207.     }
  208.  
  209.  
  210.     // --------------------------------------------------------------
  211.     // Progress: 40 %        Controllers probed
  212.  
  213.     pvalue = 40;
  214.     UI(`ChangeWidget(`id(`bar), `Value, pvalue));
  215.  
  216.  
  217.     // --------------------------------------------------------------
  218.     // now check for modules to load
  219.  
  220.     // function to initialize controllers
  221.     // I: list of maps from Read(.probe.byclass.storage.[ide|scsi|raid] ...
  222.     // O: list of loaded modules
  223.  
  224.     define init_controllers (map all_modules, list controller_list, boolean manual_mode) ``{
  225.  
  226.     map controller = $[];
  227.     integer cindex = 0;
  228.     list ioresources = [];
  229.  
  230.     y2log(.milestone, "inst_startup", 4, sformat("controller_list: %1", controller_list));
  231.  
  232.     while (cindex < size (controller_list)) {    // use while(), continue not allowed in foreach()
  233.  
  234.         controller = select (controller_list, cindex);
  235.  
  236.         cindex = cindex + 1;
  237.  
  238.         // for every IDE controller it is checked whether
  239.             // the controller is disabled in BIOS
  240.  
  241.         ioresources = lookup (lookup (controller, "resource", $[]), "io", []);
  242.         y2log (.debug, "inst_startup", 5, sformat("ioresources: %1", ioresources));
  243.         if (size (ioresources) == 0)
  244.         continue;
  245.  
  246.         // continue if disabled in BIOS
  247.         if (lookup (select (ioresources, 0), "active", true) == false)
  248.         continue;
  249.  
  250.         // check module information
  251.         // skip controller if no module info available
  252.         map module = lookup (controller, "module", $[]);
  253.         y2log (.milestone, "inst_startup", 6, sformat("module: %1", module));
  254.         if (module == $[])
  255.         continue;
  256.  
  257.         // skip controller if module already active
  258.         if (lookup (module, "active", true) == true)
  259.         continue;
  260.  
  261.         // get module loading information
  262.     
  263.         string module_name = lookup (module, "name", "");
  264.         if (module_name == "")
  265.         continue;
  266.  
  267.         // possible modules.conf entry
  268.         string module_conf = lookup (module, "conf", "");
  269.  
  270.         all_modules = add (all_modules, module_name, module_conf);
  271.  
  272.         string mod_args = lookup (module, "args", "");
  273.         if (mod_args != "")
  274.         mod_args = " " + mod_args;
  275.  
  276.         if (lookup (module, "modprobe", false) == true) {
  277.         if (!test_mode) Shell("/sbin/modprobe "+module_name+mod_args);
  278.             y2log (.milestone, "startup", 1, "/sbin/modprobe "+module_name+mod_args);
  279.         }
  280.         else {
  281.         if (!test_mode) Shell("/sbin/insmod "+module_name+mod_args);
  282.             y2log (.milestone, "startup", 1, "/sbin/insmod "+module_name+mod_args);
  283.         }
  284.  
  285.     } // while (controller)
  286.  
  287.     return all_modules;
  288.  
  289.     }; // init_controllers ()
  290.  
  291.     // --------------------------------------------------------------
  292.     // now probe & initialize controllers
  293.  
  294.     map install_inf = SCR(`Read(.etc.install_inf));
  295.     boolean manual_mode = false;
  296.     if (lookup (install_inf, "manual", "") == "1") {
  297.     manual_mode = true;
  298.     }
  299.  
  300.     map moduleMap = $[];
  301.  
  302.     y2log (.debug, "inst_startup", 7, "Checking for ide controllers...");
  303.     moduleMap = init_controllers (moduleMap, lookup (controllers, "ide", []), manual_mode);
  304.     y2log (.debug, "inst_startup", 8, "Checking for scsi controllers...");
  305.     moduleMap = init_controllers (moduleMap, lookup (controllers, "scsi", []), manual_mode);
  306.     y2log (.debug, "inst_startup", 9, "Checking for raid controllers...");
  307.     moduleMap = init_controllers (moduleMap, lookup (controllers, "raid", []), manual_mode);
  308.  
  309.     user_settings = add (user_settings, "modules", moduleMap);
  310.  
  311.     // --------------------------------------------------------------
  312.     // Progress: 50 %        All modules loaded
  313.  
  314.     pvalue = 50;
  315.     UI(`ChangeWidget(`id(`bar), `Value, pvalue));
  316.  
  317.     y2log (.milestone, "startup", 1, "all controllers initialized");
  318.  
  319.     // --------------------------------------------------------------
  320.     // now check for disks 'behind' controllers
  321.  
  322.     map targets = $[];
  323.     list|void all_disks = SCR(`Read(.probe.disk));
  324.  
  325.     y2log (.milestone, "startup", 1, "disks probed");
  326.  
  327.     if ((all_disks == nil) || (all_disks == [])) {
  328.     // somehow, we couldn't find any harddisks for installation. This is a fatal error,
  329.     // we can't do anything about it
  330.     UI(`DisplayMessage(_("No disks found for installation\nPlease check your hardware")));
  331.     return `cancel;
  332.     }
  333.  
  334.     integer progress_per_disk = (100-pvalue) / size (all_disks);
  335.  
  336.     // loop over all_disks, constructing targets map
  337.  
  338.     integer ide_count = 0;
  339.     integer scsi_count = 0;
  340.     integer raid_count = 0;
  341.  
  342.     foreach (`disk, all_disks, ``{
  343.  
  344.     map target = $[];
  345.  
  346.     string bus = lookup (disk, "bus", "?");
  347.     string dname = "";
  348.     integer i = 0;
  349.  
  350.     // ------------------------------------------------------
  351.     // check bus, count disks per bus
  352.  
  353.     if (bus == "IDE") {        ide_count = ide_count + 1; i = ide_count;
  354.     } else if (bus == "SCSI") {    scsi_count = scsi_count + 1; i = scsi_count;
  355.     } else if (bus == "RAID") {    raid_count = raid_count + 1; i = raid_count;
  356.     } else {            i = 1;        // Oops, which bus ?
  357.     }
  358.  
  359.     target = add (target, "bus", bus);
  360.  
  361.     // ------------------------------------------------------
  362.     // construct disk name for user
  363.  
  364.     dname = ""+i+". "+bus+", ";
  365.  
  366.     // needed also later as key
  367.     string ddevice = lookup (disk, "dev_name", "?");
  368.  
  369.     // strip /dev/ from ddevice, convert to path for fdisk
  370.  
  371.     path diskpath = topath ("." + substring (ddevice, 5));
  372.     path fullpath = .disk + diskpath;
  373.  
  374.     y2log (.milestone, "startup", 1, "disk_size ? "+ddevice);
  375.  
  376.     // call fdisk agent to get size information
  377.  
  378.     integer cyl_count = SCR(`Read(fullpath+.disk_size));
  379.     integer cyl_size = SCR(`Read(fullpath+.bytes_per_unit));
  380.  
  381.     target = add (target, "cyl_count", cyl_count);
  382.     target = add (target, "cyl_size", cyl_size);
  383.  
  384.     // ------------------------------------------------------
  385.     // construct full target name
  386.  
  387.     dname = dname + UI(`size_text(cyl_count * cyl_size)) + ", " + ddevice + ", ";
  388.  
  389.     string dinfo = lookup (disk, "vendor", "");
  390.     target = add (target, "vendor", dinfo);
  391.  
  392.     if (dinfo != "") dname = dname + dinfo + "-";
  393.     dinfo = lookup (disk, "device", "");
  394.     target = add (target, "model", dinfo);
  395.     
  396.     if (dinfo != "") dname = dname + dinfo;
  397.  
  398.     target = add (target, "name", dname);
  399.  
  400.     // ------------------------------------------------------
  401.     // check partitions
  402.  
  403.     y2log (.milestone, "startup", 1, "partitions ?"+dname);
  404.  
  405.     list partitions = check4partitions (diskpath, architecture);
  406.  
  407.     target = add (target, "partitions", partitions);
  408.  
  409.     // add constructed target map to list of all targets
  410.  
  411.     if (target != $[]) targets = add (targets, ddevice, target);
  412.  
  413.     pvalue = pvalue + progress_per_disk;
  414.     UI(`ChangeWidget(`id(`bar), `Value, pvalue));
  415.  
  416.     }); // foreach (`disk)
  417.  
  418.     if (test_mode) SCR(`Write(.dumpto.tmp.targets, targets));
  419.  
  420.     user_settings = add (user_settings, "targets", targets);
  421.  
  422.     // --------------------------------------------------------------
  423.     // keep dialogue open in test_mode
  424.  
  425.     //    if (test_mode) UI(`UserInput());
  426.  
  427.     return `next;
  428. }
  429.