[ Here's an updated version of a Perl script I posted here 2 months ago ]
[ or so.  Enjoy.  If you use this, please send me e-mail so I can know  ]
[ someone uses it.  Otherwise I will stop posting updates here at all   ]
[ and just use it personally.                                           ]

New in revision 1.4
   1. Added checks to make sure person running vrm has an admin token.
   2. Added a check to make sure each mount point / volume to remove
      is actually a directory.

------------------------------ Snip ------------------------------------
#!/usr/local/bin/perl
#
# Copyright (c) Jeff Blaine 1994
# This script may be distributed freely without modification, but may not
# be used to gain profit in any way.
#
# Remove AFS 3.x volume and its mount point given just the mount point
# Usage: vrm mount_point
#
# Version below
# $Id: vrm,v 1.4 1994/10/24 17:06:33 jblaine Exp $

$TOKENS_CMD = '/usr/ciesin/bin/tokens';
$FS = '/usr/ciesin/bin/fs';
$VOS = '/usr/ciesin/bin/vos';

if ($ARGV[0] eq "") {
    &usage;
}

&AdminCheck;

foreach $dir (@ARGV) {
    if (! -d $dir) {
        print "Warning: $dir is not a directory -- skipping.\n";
        next;
    }
    open (FSLSM, "$FS lsmount $dir |");
    $line = <FSLSM>;
    close (FSLSM);
    $line =~ /#(.*)'/;
    $vol_ID = $1;
    print "The volume ID is: $vol_ID\n";
    open (VOSEXA, "$VOS exa $vol_ID |");
    while (<VOSEXA>) {
        $line = $_;
        if ($line =~ /^\s+server\s+(.*)\s+partition\s+(.*)\s+RW.+/) {
            $server = $1;
            $partition = $2;
            last;
        }
    }
    close (VOSEXA);
    if (!$server || !$partition) {
        print "Could not gather information from \"vos exa \" properly.\n";
        exit 1;
    }
    print "Deleting $vol_ID from $server $partition\n";
    system ("$VOS remove -server $server -partition $partition -id $vol_ID");
    print "Removing mount point: $dir\n";
    system ("$FS rmmount $dir");
}

sub usage {
    print STDERR "Usage: $0 mount_point\n";
    print STDERR "       Removes volume mounted at mount_point and the mount_point 
itself.\n";
    exit;
}

# -------------------------------------------------------------------------
# Make sure program is being run by someone with a valid AFS admin token
# -------------------------------------------------------------------------
sub AdminCheck {
    open (TOKENS, "$TOKENS_CMD |");
    @tokens = <TOKENS>;
    close(TOKENS);
    if ($tokens[3] !~ /AFS ID 1/ ) {
        print "This program has to be run by someone klogged as admin.\n";
        exit(1);
    }
}

Reply via email to