home *** CD-ROM | disk | FTP | other *** search
/ Caldera Network Desktop 1.0 / caldera-network-desktop-1.0.bin / images / ramdisk2-beta.img / usr / lib / perl / probe_cd < prev    next >
Text File  |  1995-12-04  |  5KB  |  233 lines

  1. # CD-ROM Probing Routines -*-perl-*-
  2.  
  3. ##
  4. ## Variables
  5. ##
  6.  
  7. # $rh_mountpath is point at which to mount the device
  8. #     with the RHS stuff on it.  
  9. # $rpppath is the path from $rhspath to the rpp directory,
  10. #     which is used to verify that this is indeed RHS stuff
  11.  
  12. # $rh_mountdevice is the device to use in the mount call
  13. # $rh_mountdevicetype is the filesystem type to use in the mount call
  14.  
  15. $cddev = "";
  16. $cddevenglish = "";
  17.  
  18. @cdroms = (
  19.        "mcd", "Mitsumi",
  20.        "scd0", "1st SCSI",
  21.        "scd1", "2nd SCSI",
  22.        "cdu535", "Sony CDU-535",
  23.        "sonycd", "Sony CDU-31A",
  24.        "hda", "First drive on primary IDE interface",
  25.        "hdb", "Second drive on primary IDE interface",
  26.        "hdc", "First drive on secondary IDE interface",
  27.        "hdd", "Second drive on secondary IDE interface",
  28.        "sbpcd0", "1st SoundBlaster PRO (or Panasonic?)",
  29.        "sbpcd1", "2nd SoundBlaster PRO (or Panasonic?)",
  30.        "sbpcd2", "3rd SoundBlaster PRO (or Panasonic?)",
  31.        "sbpcd3", "4th SoundBlaster PRO (or Panasonic?)",
  32.        "aztcd", "Aztech CD-268"
  33.        );
  34.  
  35. ##
  36. ## Functions
  37. ##
  38.  
  39. ## attempt_cd_mount will set $cddev, $cddevenglish
  40. ##
  41.  
  42. sub attempt_cd_mount {
  43.     local ($mode, $arg1, $arg2) = @_;
  44.     local ($cdi, $ret);
  45.  
  46.     if ($mode eq "probe") {
  47.     print "Probing for Red Hat CD-ROM...\n";
  48.     $cdi = 0;
  49.     while ($cdi < @cdroms - 1) {
  50.         $cddev = "/dev/$cdroms[$cdi]";
  51.         $cddevenglish = $cdroms[$cdi + 1];
  52.         print "\nTrying $cddev...\n";
  53.         $hold_on_error = 0;
  54.         print "Invoking mount w/ path $rh_mountpath\n";
  55.         $ret = &invoke("mount -t iso9660 -o ro $cddev $rh_mountpath");
  56.         print "mount returned $ret\n";
  57.         $hold_on_error = 1;
  58.         if ($ret == 0) {
  59.         # We mounted it - is it our CD ?
  60.         $ret = &verify_rhs_files;
  61.         if ($ret == 1) {
  62.             print "Success!\n";
  63.             $rh_mountdevice = $cddev;
  64.             $rh_mountdevicetype = "iso9660";
  65.             return 1;
  66.         }
  67.         print "No Red Hat stuff here.\n";
  68.         &invoke_no_output("umount $rh_mountpath");
  69.         }
  70.         print "Failed\n";
  71.         $cdi += 2;
  72.     }
  73.     print "Total failure.  Hit Enter to continue.";
  74.     <STDIN>;
  75.     return 0;
  76.     } elsif ($mode eq "device") {
  77.     # Try to mount $arg1
  78.     $hold_on_error = 0;
  79.     $ret = &invoke("mount -t $arg2 -o ro $arg1 $rh_mountpath");
  80.     $hold_on_error = 1;
  81.     if ($ret == 0) {
  82.         # We mounted it - is it our CD ?
  83.         $ret = &verify_rhs_files;
  84.         if ($ret == 1) {
  85.         $cddev = $arg1;
  86.         $cddevenglish = $arg1;
  87.         $rh_mountdevice = $cddev;
  88.         $rh_mountdevicetype = $arg2;
  89.         return 1;
  90.         }
  91.         print "No Red Hat stuff here.\n";
  92.         &invoke_no_output("umount $rh_mountpath");
  93.     }
  94.     <STDIN>;
  95.     return 0;
  96.     }
  97.     return -1;
  98. }
  99.  
  100. sub get_device {
  101.     local ($device, $type);
  102.  
  103.     while (!$device || !$type) {
  104.     $device = "";
  105.     $type = "";
  106.  
  107.     if (! &rhs_inputbox ("Device name", 
  108. <<EOM
  109. >
  110. Please enter the full device name (including /dev/).
  111. >
  112. EOM
  113.                  , 70, "/dev/")) {
  114.         next;
  115.         }
  116.     $device = $dialog_result;
  117.  
  118.     if (! &rhs_inputbox ("Filesystem Type",
  119. <<EOM
  120. >
  121. Please enter the filesystem type (iso9660, minix, ext2, msdos, hpfs, etc)
  122. >
  123. EOM
  124.                      , 70, "")) {
  125.             next;
  126.     }
  127.     $type = $dialog_result;
  128.     }
  129.  
  130.     return ($device, $type);
  131. }
  132.  
  133. sub mount_partition {
  134.     local ($device, $type, $success);
  135.  
  136.     ($device, $type) = &get_device;
  137.     $success = 0;
  138.  
  139.     while (1) {
  140.     $success = &attempt_cd_mount ("device", $device, $type);
  141.  
  142.     if ($success == 1) {
  143.         # if respond OK return 1
  144.         if (&rhs_yesno ( "Success",
  145. <<EOM
  146. I think I\'ve found the Red Hat stuff
  147. on the $device drive.
  148. >
  149. Is this correct?
  150. EOM
  151.                    , 50)) {
  152.         return 1;
  153.         }
  154.     }
  155.  
  156.     $again = 1;
  157.       REPEAT:
  158.     while ($again) {
  159.         $ret = &rhs_menu ("Error",
  160. <<EOM
  161. >
  162. >Red Hat file not found!
  163. >What should I do now?
  164. >
  165. EOM
  166.                   , 60, 2,
  167.                   "Again", "Try again",
  168.                   "Quit", "Give up");
  169.         next REPEAT if (! $ret);
  170.         if ($dialog_result eq "Quit") {
  171.         return 0;
  172.         } elsif ($dialog_result eq "Again") {
  173.         ($device, $type) = &get_device;
  174.         } else {
  175.         next REPEAT;
  176.         }
  177.  
  178.         $again = 0;
  179.     }
  180.     }
  181. }
  182.  
  183. sub probe_rhs_cdrom {
  184.     local ($ret, $success, $mode, $again, $arg1, $arg2, $arg3);
  185.     
  186.     $success = 0;
  187.  
  188.     while (1) {
  189.     $success = &attempt_cd_mount ("probe");
  190.  
  191.     if ($success == 1) {
  192.         # if respond OK return 1
  193.         if (&rhs_yesno ( "Success",
  194. <<EOM
  195. I think I\'ve found the Red Hat CD-ROM
  196. in the $cddevenglish CD-ROM drive, which
  197. I found on device $cddev.
  198. >
  199. Is this correct?
  200. EOM
  201.                    , 50)) {
  202.         return 1;
  203.         }
  204.     }
  205.  
  206.     $again = 1;
  207.       REPEAT:
  208.     while ($again) {
  209.         $ret = &rhs_menu ("Error",
  210. <<EOM
  211. >
  212. >Red Hat CD-ROM not found!
  213. >What should I do now?
  214. >
  215. EOM
  216.                   , 60, 2,
  217.                   "Probe", "Probe again",
  218.                   "Quit", "Give up");
  219.         next REPEAT if (! $ret);
  220.         if ($dialog_result eq "Quit") {
  221.         return 0;
  222.         } elsif ($dialog_result ne "Probe") {
  223.         next REPEAT;
  224.         }
  225.  
  226.         $again = 0;
  227.     }
  228.     }
  229. }
  230.  
  231. ###################
  232. 1;
  233.