home *** CD-ROM | disk | FTP | other *** search
/ Education Sampler 1992 [NeXTSTEP] / Education_1992_Sampler.iso / Utilities / TarChive / TapeErase < prev    next >
Text File  |  1992-08-19  |  3KB  |  92 lines

  1. #!/usr/local/bin/perl
  2. #Copyright 1992    Sherwood Botsford
  3.  
  4. $Label = $ARGV[0];
  5. if ($Label eq "") {
  6.     print "\nLeast worthy tape slave requests label you wish to erase.\n";
  7.     print "Once provided, Humble Servant will:\n";
  8.     print "\t1. Unregister the tape\n";
  9.     print "\t2. Remove the tape's log files from \n";
  10.     print "\t   Most Exhalted User's backup directory\n";
  11.     print "\t3.    Write a new end of media mark on the tape.\n\n";
  12.     exit;
  13.     }
  14.  
  15. print "\nVerifying that indeed $Label is registered here.\n\n";
  16.  
  17. if ( ! -e "/usr/local/tapelabels/$Label" ) {
  18.     print "\tRitual deferences, but $Label is not registered here.\n";
  19.     print "\tWould Most Gracious User please check his typing.\n\n";
  20.     exit;
  21.     }
  22.  
  23. print "\nVerifying that you own this tape.\n\n";
  24.  
  25. if ( ! -o "/usr/local/tapelabels/$Label" ) {
  26.     print ("
  27.         Pardon intrusion by this mere servant,
  28.         but you don't own $Label.
  29.         Although unworthy, humble tape slave is honourable.
  30.         Only the tape's owner can command erasing a tape.
  31.         \n");
  32.  
  33.     exit;
  34.     }
  35.  
  36.  
  37. require("TapeLibrary.perl");
  38.  
  39. #
  40. #     Read Volume label
  41. #
  42.     $tapelabel = &CheckVolumeLabel($Code);
  43.     print "Tape is labeled $tapelabel\n\n";
  44. #
  45. #    Check the label
  46.  
  47. #    A series of checks are made.  CheckVolumeLabel tries to read 
  48. #    the first file on the tape.  If that returns blank, or more than a 
  49. #    single line, or a single line that doesn't match with the name of tape, 
  50. #    or a tape name that is not owned by the user, then the user is bumped. 
  51.  
  52.     if ($Code == 100 ) {
  53.         print "Verified that this tape is registered on this server.\n";
  54.         print "Verified that $user owns this tape. \n";
  55.         }
  56.     if ($Code == 102 ) {
  57.           print "Begging forgiveness for rude interuption but this tape has no label.\n";
  58.         print "Humble tar slave is not permitted to write to an unlabeled tape.\n\n";
  59.         &Quit(102);
  60.         }
  61.     if ( $Code == 103 ) {
  62.           print "Excuse Interuption, but this label is not registered\n";
  63.         print "Cannot unregister an unregistered tape.  \n";
  64.         &Quit(102);
  65.         }
  66.     if ($Code == 104 ) {
  67.           print "Most Humble Apologies, but you do not own this tape.\n";
  68.         print "Only the Owner can unregister a tape.\n";
  69.         &Quit(102);
  70.         }
  71.  
  72. if ( $tapelabel ne $Label ) {
  73.     print("
  74.         Humble groveling servant begs to intrude:
  75.         You have asked this most lowly one to erase label $label
  76.         But on looking at the tape, it is labeled differently, 
  77.         as $tapelabel.  Plenteous apologies, but my master has 
  78.         decreed that they must match before I do this deed.
  79.         \n");
  80.     &Quit;
  81.     }
  82.  
  83. &RewindTape;
  84.  
  85. print "Erasing Tape.\n\n";
  86. &WriteMark(1);
  87. print "Unregistering Tape \n\n";
  88. system ("rm /usr/local/tapelabels/$tapelabel");
  89. print "Removing Log files from user directory\n\n";
  90. system "rm -f ~/backups/${tapelabel}-*";
  91. print "$label has been erased\n";
  92.