home *** CD-ROM | disk | FTP | other *** search
/ ftp.parl.clemson.edu / 2015-02-07.ftp.parl.clemson.edu.tar / ftp.parl.clemson.edu / pub / pvfs / contrib / mkmgrconf-redhat8.0 next >
Text File  |  2003-02-05  |  8KB  |  315 lines

  1. #!/usr/bin/perl
  2. # Script to setup iodtab and pvfsdir files for PVFS
  3. # This file creates both .iodtab and .pvfsdir files and makes sure all
  4. # user entries are correct before creating them.
  5. #
  6. # $Log: mkmgrconf,v $
  7. # Revision 1.2  2000/12/18 16:52:48  rbross
  8. # Dunno.
  9. #
  10. # Revision 1.1  2000/12/18 16:27:18  rbross
  11. # moved mkiodtab to mkmgrconf
  12. #
  13. # Revision 1.1.1.1  1999/08/10 17:11:31  rbross
  14. # Original 1.3.3 sources
  15. #
  16.  
  17. # ***********************************
  18. # initialization
  19. # ***********************************
  20. $rootdir = "/";
  21. print("This script will make the .iodtab and .pvfsdir files\nin the metadata directory of a PVFS file system.\n");
  22. if ($< != 0) {
  23.     print("This script should be run as root.\n");
  24.     exit(-1);
  25. }    
  26. print("\n");
  27. #setup STDOUT to flush (unbuffered) -- (confusing, I know!)
  28. select STDOUT; $| = 1;
  29.  
  30. # ***********************************
  31. # get root directory
  32. # ***********************************
  33. print("Enter the root directory (metadata directory):\n");
  34. $rootdir = <STDIN>;
  35. chop($rootdir);
  36.  
  37. # ***********************************
  38. # verify directory exists, if not ask to create
  39. # ***********************************
  40. if (!(opendir(DIR, $rootdir))) {
  41.     print("$rootdir does not exist\n");
  42.     print("Shall we create it?(y or n)\n");
  43.     $resp = <STDIN>;
  44.     chop($resp);
  45.     # if not create, exit program with error
  46.     if ($resp !~ /^y$/) {
  47.         print("Goodbye\n");
  48.         exit(-1);
  49.     }    
  50.     # open new directory with standard permissions (755)
  51.     @temp = split(//,755);
  52.     $temp = $temp[2]*1 + $temp[1]*8 + $temp[0]*64;
  53.     if (!mkdir($rootdir, $temp)) {
  54.         print("$rootdir: mkdir failed (mode = 755)");
  55.         exit(-1);
  56.     }
  57. }    
  58.  
  59. # ***********************************
  60. # get uid
  61. # ***********************************
  62. # All sections from here on use this while(1) which breaks only when the
  63. # user enters in a correct response (e.g. valid user id).
  64. while (1) {
  65.     print("Enter the user id of directory: \n");
  66.     $user = <STDIN>;
  67.     chop($user);
  68.     # verify uid
  69.     if ($user =~ /^[0-9]+$/) {
  70.         if ((@temp = getpwuid($user)) == NULL) {
  71.             print("$user: Invalid user id...try again\n");
  72.             next;
  73.         }
  74.     }
  75.     else {
  76.         if ((@temp = getpwnam($user)) == NULL) {
  77.             print("$user: Invalid user id...try again\n");
  78.             next;
  79.         }
  80.     }
  81.     last;
  82. }
  83. $uid = $temp[2];
  84.  
  85. # ***********************************
  86. # get gid
  87. # ***********************************
  88. while (1) {
  89.     print("Enter the group id of directory: \n");
  90.     $group = <STDIN>;
  91.     chop($group);
  92.     # verify gid
  93.     if ($group =~ /^[0-9]+$/) {
  94.         if ((@temp = getgrgid($group)) == NULL) {
  95.             print("$group: Invalid group id...try again\n");
  96.             next;
  97.         }
  98.     }
  99.     else {
  100.         if ((@temp = getgrnam($group)) == NULL) {
  101.             print("$group: Invalid group id...try again\n");
  102.             next;
  103.         }
  104.     }
  105.     last;
  106. }
  107. $gid = $temp[2];
  108.  
  109. # ***********************************
  110. # get mode
  111. # ***********************************
  112. while(1) {
  113.     print("Enter the mode of the root directory: \n");
  114.     $mode = <STDIN>;
  115.     chop($mode);
  116.     # verify valid mode
  117.     if ($mode !~ /^[0-7]+$/) {
  118.         print("$mode: Invalid mode...try again\n");
  119.         next;
  120.     }
  121.     $omode = oct($mode);
  122.     if ($omode & ~(oct(777))) {
  123.         print("$mode: Invalid mode...try again\n");
  124.         next;
  125.     }
  126.     last;
  127. }
  128. # make it a directory mode
  129. $omode |= 0040000;
  130.  
  131. # ***********************************
  132. # get hostname
  133. # ***********************************
  134. while(1) {
  135.     print("Enter the hostname that will run the manager: \n");
  136.     $host = <STDIN>;
  137.     chop($host);
  138.     print("Searching for host...");
  139.     if ((@temp = gethostbyname($host)) == NULL) {
  140.         print("\n$host: Invalid hostname...try again\n");
  141.         next;
  142.     }
  143.     print("success\n");
  144.     last;
  145. }
  146.  
  147. # ***********************************
  148. # get manager port number
  149. # ***********************************
  150. while(1) {
  151.     print("Enter the port number on the host for manager: \n");
  152.     print("(Port number 3000 is the default)\n");
  153.     $port = <STDIN>;
  154.     chop($port);
  155.     if ($port == NULL) {
  156.         $port = 3000;
  157.         last;
  158.     }
  159.     if ($port < 1024 || $port >= 65536 || $port !~ /^[0-9]+$/) {
  160.         print("$port: Invalid port number...try again\n");
  161.         next;
  162.     }    
  163.     last;
  164. }
  165.  
  166. # ***********************************
  167. # get I/O node locations
  168. # ***********************************
  169. # LOOP label defined for nested next command below
  170. LOOP: while(1) {
  171.     print("Enter the I/O nodes: (can use form node1, node2, ... or\n");
  172.     print("nodename{#-#,#,#})\n");
  173.     $inputline = <STDIN>;
  174.     chop($inputline);
  175.     # parse input (commas first, then brackets)
  176.  
  177. #######################################################
  178. # WARNING: BIG HACK!
  179. # the following line crashes on some versions of perl (most often on 
  180. # Redhat 8.0), so we comment it out and replace it with some hopefully
  181. # equivalent regex logic -PHC
  182. #
  183.  
  184.     # @parse = split(/[, ]+/, $inputline);
  185.  
  186.     # store input line in default variable 
  187.     $_ = $inputline;
  188.     # initialize array index counter
  189.     $i = 0;
  190.     # while there is still text left
  191.     while($_)
  192.     {
  193.         # strip out the first matching word (delimited by comma or white sp)
  194.         s/^[\s,]*[^\s,]+//;
  195.         # save the matching string that was stripped out
  196.         $foo = "$&";
  197.         # pull leading and trailing white sp off
  198.         $foo =~ s/[\s,]+//g;
  199.         # stick it in the array
  200.         $parse[$i] = $foo;
  201.         # increment array index
  202.         $i++;
  203.         # loop around and continue on next word
  204.     }
  205.  
  206. # WARNING: END BIG HACK!
  207. ########################################################
  208.  
  209.     $numinodes = 0;
  210.     for($i=0; $parse[$i] !~ /^$/;$i++) {
  211.         # expand parsed input that contains brackets
  212.         if ($parse[$i] =~ /{/) {
  213.             @arrayline = split(/[{}, ]+/, $parse[$i]);
  214.             $prefix = @arrayline[0];
  215.             $count = @arrayline - 1;
  216.             for ($j = 1; $j <= $count; $j++) { 
  217.                 if (@arrayline[$j] =~ /-/) {
  218.                     @temparray = split(/-/, $arrayline[$j]);
  219.                     for ($k = @temparray[0]; $k <= @temparray[1]; $k++) {
  220.                         @inodes[$numinodes] = $arrayline[0].$k;
  221.                         $numinodes++;
  222.                     }    
  223.                 } else { 
  224.                     @inodes[$numinodes] = $arrayline[0].$arrayline[$j];
  225.                     $numinodes++;
  226.                 }    
  227.             }
  228.         }
  229.         else {
  230.             @inodes[$numinodes] = $parse[$i];
  231.             $numinodes++;
  232.         }
  233.     }
  234.  
  235.     # make sure i/o nodes exist
  236.     # may need to flush here? (what is flush command in perl?)
  237.     print("Searching for hosts...");
  238.     $fail = 0;
  239.     for($i=0;$inodes[$i] !~ /^$/;$i++) {
  240.         if ((@temp = gethostbyname($inodes[$i])) == NULL) {
  241.             @badhosts[$fail] = $inodes[$i];
  242.             $fail++;
  243.         }
  244.     }
  245.     # if any of the lookups failed, try again
  246.     if ($fail) {
  247.         print("\nInvalid I/O node(s): @badhosts...try again\n");
  248.         next LOOP;
  249.     }
  250.     print("success\n");
  251.     last;
  252. }
  253. print("I/O nodes: @inodes\n");
  254.  
  255. # ***********************************
  256. # get iod port number
  257. # ***********************************
  258. while(1) {
  259.     print("Enter the port number for the iods: \n");
  260.     print("(Port number 7000 is the default)\n");
  261.     $nodeport = <STDIN>;
  262.     chop($nodeport);
  263.     if ($nodeport == NULL) {
  264.         $nodeport = 7000;
  265.         last;
  266.     }
  267.     if ($nodeport < 1024 || $nodeport >= 65536 || $nodeport !~ /^[0-9]+$/) {
  268.         print("$port: Invalid port number...try again\n");
  269.         next;
  270.     }    
  271.     last;
  272. }
  273.  
  274. # ***********************************
  275. # Write to .iodtab
  276. # ***********************************
  277. $iodtab = ">".$rootdir."/.iodtab";
  278. if (!open(IODTAB, "$iodtab")) {
  279.     print("$iodtab: open error\n");
  280.     exit(-1);
  281. }
  282. print IODTAB ("# .iodtab\n");
  283. $date = localtime(time);
  284. print IODTAB ("# Created by mkiodtab - $date\n");
  285. print IODTAB ("#\n");
  286. print IODTAB ("# node:port #\n");
  287. $count = @inodes;
  288. for ($i = 0; $i < $count; $i++) {
  289.     print IODTAB ("@inodes[$i]:$nodeport\n");
  290. }    
  291. close(IODTAB);
  292. chmod(0755, $rootdir."/.iodtab");
  293.  
  294. # Write to .pvfsdir
  295. $pvfsdir = ">".$rootdir."/.pvfsdir";
  296. if (!open(PVFSDIR, "$pvfsdir")) {
  297.     print("$pvfsdir: open error\n");
  298.     exit(-1);
  299. }
  300. # get inode from stat structure
  301. $inode = (stat(PVFSDIR))[1];
  302. print PVFSDIR ("$inode\n");
  303. print PVFSDIR ("$uid\n");
  304. print PVFSDIR ("$gid\n");
  305. printf PVFSDIR ("%07o\n", $omode);
  306. print PVFSDIR ("$port\n");
  307. print PVFSDIR ("$host\n");
  308. print PVFSDIR ("$rootdir\n");
  309. print PVFSDIR ("\/\n");
  310. close(PVFSDIR);
  311. chmod(0755, $rootdir."/.pvfsdir");
  312.  
  313. # finished
  314. print ("Done!\n");
  315.