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 / fstab < prev    next >
Text File  |  1995-12-04  |  9KB  |  460 lines

  1. ## -*-perl-*-
  2.  
  3. # Routines to set up the filesystem hierarchy
  4.  
  5. # This is where we mount the new Linux filesystem
  6. $fsmount = "/mnt";
  7.  
  8. # %fsformat{device} is used to determine file system types
  9. # if a device is not listed there, we ask the user for the type
  10.  
  11. %fs_pars = ();
  12. %fs_types = ();
  13. %fs_sizes = ();
  14. %fs_mountpoints = ();
  15.  
  16. # Indicates that the installation filesystem is mounted
  17. $fs_mounted = 0;
  18.  
  19. $root_dev = "";
  20.  
  21. sub fstab_reset {
  22.  
  23.     %fs_pars = ();
  24.     %fs_types = ();
  25.     %fs_sizes = ();
  26.     %fs_mountpoints = ();
  27.     %fsformat = ();
  28.     $root_dev = "";
  29. }
  30.  
  31. sub mountpoint_sort {
  32.     $fs_mountpoints{$a} cmp $fs_mountpoints{$b};
  33. }
  34.  
  35. sub init_filesystems {
  36.     local ( %fsinfolist, $dev, $size );
  37.     local ( $p, $r );
  38.     
  39.     if ($fs_mounted) {
  40.     if (! &rhs_menu("Warning",
  41. <<EOM
  42. >
  43. The installation filesystems are already mounted.  DO NOT
  44. make changes to the filesystem mountpoints unless you first
  45. unmount the filesystems and erase them.
  46. >
  47. What do you want to do?
  48. >
  49. EOM
  50.                , 70, 3,
  51.                "Unmount the filesystems", "",
  52.                "Unmount and erase the filesystems", "",
  53.                "Forget it -- do not change the filesystems", "")) {
  54.         return 1;
  55.     }
  56.     if ($dialog_result eq "Forget it -- do not change the filesystems") {
  57.         return 1;
  58.     } elsif ($dialog_result eq "Unmount the filesystems") {
  59.         return 0 if (! &unmount_filesystems);
  60.     } elsif ($dialog_result eq "Unmount and erase the filesystems") {
  61.         return 0 if (! &unmount_filesystems);
  62.         return 0 if (! &erase_filesystems);
  63.     }
  64.     }
  65.  
  66.     ## Find all disk partitions
  67.  
  68.     &rhs_infobox ("Filesystems",
  69. <<EOM
  70. >
  71. Looking for Linux partitions...
  72. >
  73. EOM
  74.           , 60);
  75.  
  76.     %fsinfolist = get_partitions("ext2");
  77.  
  78.     if (!keys(%fsinfolist)) {
  79.         &rhs_msgbox ( "Filesystems",
  80. <<EOM
  81. >
  82. You don\'t appear to have any Linux partitions on your system.
  83. You must create at least one before continuing.
  84. >
  85. EOM
  86.                      , 60);
  87.         return 0;
  88.     }
  89.  
  90.     ## Select paritions and mount points
  91.     ## First the special case where there is only one partition
  92.     if (keys(%fsinfolist) == 1) {
  93.     ($dev) = keys(%fsinfolist);
  94.     $fsinfolist{$dev} =~ /^.*(.{9})$/;
  95.     $size = $1;
  96.     chop($size);
  97.  
  98.     $root_dev = $dev;
  99.     $fs_pars{$dev} = $dev;
  100.     $fs_types{$dev} = "ext2";
  101.     $fs_sizes{$dev} = $size;
  102.     $fs_mountpoints{$dev} = "/";
  103.  
  104.     return 1;
  105.     }
  106.  
  107.   SELNEWPAR:
  108.     while(1) {
  109.         $msg =
  110. <<EOM
  111. Your Linux filesystem is set up thusly:
  112. >   Device  Type  Blocks  Location
  113. EOM
  114.     ;
  115.         foreach $ent (sort mountpoint_sort (keys(%fs_mountpoints))) {
  116.             $msg .= sprintf(">%-9s %5s%7s  %s\n", $ent, $fs_types{$ent},
  117.                             $fs_sizes{$ent}, $fs_mountpoints{$ent});
  118.         }
  119.     $msg .= ">";
  120.     if (! &rhs_menu("Filesystems", $msg, 60, 4,
  121.             "Add", "Add a new partition",
  122.             "Remove", "Remove a partition",
  123.             "Edit", "Change the location of a partition",
  124.             "Done", "Continue with install")) {
  125.         %fs_pars = ();
  126.         %fs_types = ();
  127.         %fs_sizes = ();
  128.         %fs_mountpoints = ();
  129.         return 0;
  130.     }
  131.     
  132.     if ($dialog_result eq "Add") {
  133.         &fs_add_filesystem(%fsinfolist);
  134.     } elsif ($dialog_result eq "Remove") {
  135.         &fs_remove_filesystem;
  136.     } elsif ($dialog_result eq "Edit") {
  137.         &fs_edit_filesystem;
  138.     } elsif ($dialog_result eq "Done") {
  139.         if (&fs_verify_fstab) {
  140.         return 1;
  141.         }
  142.     }
  143.     } # while(1)
  144.     
  145.     # should never get here
  146. }
  147.  
  148. sub fs_verify_fstab {
  149.     local ( $ent, $oent );
  150.  
  151.     ## Check for duplicate mount points
  152.     foreach $ent (values (%fs_mountpoints)) {
  153.     if ($ent eq $oent) {
  154.         &rhs_msgbox("Error",
  155. <<EOM
  156. >
  157. The following mount point is used twice!  Only one
  158. partition can be mounted at any one mount point.
  159. >
  160. $ent
  161. >
  162. EOM
  163.             , 60);
  164.         return 0;
  165.     }
  166.     $oent = $ent;
  167.     }
  168.  
  169.     ## Check for a "/" filesystem
  170.  
  171.     $root_dev = "";
  172.     foreach $ent (keys (%fs_mountpoints)) {
  173.     if ($fs_mountpoints{$ent} eq "/") {
  174.         $root_dev = $ent;
  175.         last;
  176.     }
  177.     }
  178.     if ( $root_dev eq "" ) {
  179.     &rhs_msgbox("Error",
  180. <<EOM
  181. >
  182. You have not specified a root parition!
  183. >
  184. You must have a single parition mounted at \"/\".
  185. >
  186. EOM
  187.             , 60);
  188.     return 0;
  189.     }
  190.  
  191.     return 1;
  192. }
  193.  
  194. sub fs_remove_filesystem {
  195.     local ( %fstmp, $ent, $dev );
  196.  
  197.     $fstmp = ();
  198.     foreach $ent (sort mountpoint_sort (keys(%fs_mountpoints))) {
  199.     $fstmp{$ent} = sprintf("%5s%7s  %-12.12s\n", $fs_types{$ent},
  200.                    $fs_sizes{$ent}, $fs_mountpoints{$ent});
  201.     }
  202.  
  203.     if (! &rhs_menua("Filesystems",
  204. <<EOM
  205. >
  206. Which partition do you want to remove?
  207. >
  208. EOM
  209.              , 45, %fstmp)) {
  210.     return 0;
  211.     }
  212.     $dev = $dialog_result;
  213.     delete $fs_pars{$dev};
  214.     delete $fs_sizes{$dev};
  215.     delete $fs_types{$dev};
  216.     delete $fs_mountpoints{$dev};
  217.  
  218.     return 1;
  219. }
  220.  
  221. sub fs_edit_filesystem {
  222.     local ( %fstmp, $ent, $dev );
  223.  
  224.     $fstmp = ();
  225.     foreach $ent (sort mountpoint_sort (keys(%fs_mountpoints))) {
  226.     $fstmp{$ent} = sprintf("%5s%7s  %-12.12s\n", $fs_types{$ent},
  227.                    $fs_sizes{$ent}, $fs_mountpoints{$ent});
  228.     }
  229.  
  230.     if (! &rhs_menua("Filesystems",
  231. <<EOM
  232. >
  233. Which partition do you want to edit?
  234. >
  235. EOM
  236.              , 45, %fstmp)) {
  237.     return 0;
  238.     }
  239.     $dev = $dialog_result;
  240.  
  241.     if (! &rhs_inputbox("Filesystems",
  242. <<EOM
  243. >
  244. Where do you want to mount $dev?
  245. >
  246. EOM
  247.             , 70, $fs_mountpoints{$dev})) {
  248.     return 0;
  249.     }
  250.     $fs_mountpoints{$dev} = $dialog_result;
  251.  
  252.     return 1;
  253. }
  254.  
  255. sub fs_add_filesystem {
  256.     local ( %fsinfolist ) = @_;
  257.     local ( %fstmp, $ent, $entb, $dev, $size );
  258.  
  259.     %fstmp = ();
  260.   ADDNEWPARB:
  261.     foreach $ent (sort keys (%fsinfolist)) {
  262.     foreach $entb (sort keys (%fs_pars)) {
  263.         next ADDNEWPARB if ($ent eq $entb);
  264.     }
  265.     $fsinfolist{$ent} =~ /(.*) (.*) (.*)/;
  266.     $fstmp{$ent} = sprintf("%9s %9s %9s", $1, $2, $3);
  267.     }
  268.  
  269.     if (! &rhs_menua("Filesystems",
  270. <<EOM
  271. >
  272. Which partition do you want to add?
  273. >
  274. >      Device       Start       End    Blocks
  275. EOM
  276.              , 54, %fstmp)) {
  277.     return 0;
  278.     }
  279.  
  280.     $dev = $dialog_result;
  281.     $fstmp{$dev} =~ /^.*(.{9})$/;
  282.     $size = $1;
  283.     chop($size);
  284.     return &fs_add($dev, $size);
  285. }
  286.  
  287. sub fs_add {
  288.     local ( $dev, $size ) = @_;
  289.     local ( $mountpoint );
  290.  
  291.     if (! &rhs_inputbox("Filesystems",
  292. <<EOM
  293. >
  294. Where do you want to mount $dev?
  295. >
  296. EOM
  297.             , 70, "")) {
  298.     return 0;
  299.     }
  300.     $mountpoint = $dialog_result;
  301.  
  302.     if ($fsformat{$dev}) {
  303.     $type = $fsformat{$dev};
  304.     } else {
  305.     if (! &rhs_menu("Filesystems",
  306. <<EOM
  307. >
  308. What type of filesystem is on this partition?
  309. >
  310. EOM
  311.             , 50, 3,
  312.             "ext2", "Second Extended FS",
  313.             "minix", "Minix FS",
  314.             "msdos", "MS-DOS FS")) {
  315.         return 0;
  316.     }
  317.     $type = $dialog_result;
  318.     }
  319.  
  320.     $fs_pars{$dev} = $dev;
  321.     $fs_types{$dev} = $type;
  322.     $fs_sizes{$dev} = $size;
  323.     $fs_mountpoints{$dev} = $mountpoint;
  324.  
  325.     return 1;
  326. }
  327.  
  328. sub mount_filesystems {
  329.  
  330.     local ( $ent, $ret );
  331.  
  332.     if ($fs_mounted) {
  333.     &rhs_msgbox("Notice",
  334. <<EOM
  335. >
  336. Your Linux filesystem is already mounted.
  337. >
  338. EOM
  339.             , 60);
  340.     return 1;
  341.     }
  342.  
  343.     $ret = 0;
  344.     foreach $ent (sort mountpoint_sort (keys(%fs_mountpoints))) {
  345.     if ($fs_mountpoints{$ent} ne "/") {
  346.         &invoke("mkdir -p $fsmount$fs_mountpoints{$ent}");
  347.     }
  348.     $ret += &invoke("mount -t $fs_types{$ent} $ent $fsmount$fs_mountpoints{$ent}");
  349.     }
  350.  
  351.     if ($ret) {
  352.     &rhs_msgbox("Error",
  353. <<EOM
  354. >
  355. An error occurred while mounting the filesystem.
  356. >
  357. You need to repeat the Fstab step and reorganize your filesystem.
  358. You should then Unmount your filesystem, and Mount it again.
  359. >
  360. EOM
  361.             , 60);
  362.     $fs_mounted = 0;
  363.     return 0;
  364.     } else {
  365.     if (! $express_install) {
  366.         &rhs_msgbox("Success",
  367. <<EOM
  368. >
  369. Your Linux filesystem was mounted successfully.
  370. >
  371. EOM
  372.             , 60);
  373.     }
  374.     $fs_mounted = 1;
  375.     return 1;
  376.     }
  377. }
  378.  
  379. sub unmount_filesystems {
  380.  
  381.     local ( $ent );
  382.  
  383.     if (! $fs_mounted) {
  384.     if (! &rhs_yesno("Notice",
  385. <<EOM
  386. >
  387. Your Linux filesystem does not appear to be mounted.
  388. >
  389. Go ahead and unmount it anyway?
  390. >
  391. EOM
  392.              , 60)) {
  393.         return 1;
  394.     }
  395.     }
  396.  
  397.     foreach $ent (reverse sort mountpoint_sort (keys(%fs_mountpoints))) {
  398.     &invoke("umount $ent");
  399.     }
  400.     
  401.     
  402.     $fs_mounted = 0;
  403.     return 1;
  404. }
  405.  
  406. sub erase_filesystems {
  407.  
  408.     &rhs_msgbox("Notice",
  409. <<EOM
  410. >
  411. Erasing filesystems is not supported at this time.
  412. To get the same effect, unmount, re-format, and
  413. remount your filesystem.
  414. >
  415. EOM
  416.         , 60);
  417.  
  418.     return 0;
  419. }
  420.  
  421. sub finish_fstab {
  422.  
  423.     local ( $ent );
  424.  
  425.     open(FD, ">$fsmount/etc/fstab");
  426.  
  427.     print FD
  428. <<EOM
  429. #
  430. # /etc/fstab
  431. #
  432. # You should be using fstool (in the control-panel) to edit this!
  433. #
  434.  
  435. EOM
  436.     ;
  437.  
  438.     foreach $ent (sort mountpoint_sort (keys(%fs_mountpoints))) {
  439.     printf(FD "%-30s %-15s %-6s %s 1 %d\n", $ent, $fs_mountpoints{$ent},
  440.            $fs_types{$ent}, "defaults", ($ent eq $root_dev) ? 1 : 2);
  441.     }
  442.  
  443. print FD
  444. <<EOM
  445.  
  446. #
  447. # proc filesystem
  448. #
  449.  
  450. EOM
  451.     ;
  452.     printf(FD "%-30s %-15s %-6s %s\n", "/proc", "/proc", "proc", "defaults");
  453.     printf(FD "%-30s %-15s %-6s %s 0 0\n", "/dev/fd0", "/mnt/floppy", "ext2", "defaults,noauto");
  454.  
  455.     close FD;
  456. }
  457.  
  458. #######################################
  459. 1;
  460.