Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / tests / afs-rmcell.pl
1 #!/usr/bin/env perl
2 #
3 # Remove cell files from this machine. Use with caution!
4 #
5
6 use warnings;
7 use strict;
8 use OpenAFS::Dirpath;
9 use OpenAFS::OS;
10 use OpenAFS::ConfigUtils;
11 use Term::ReadLine;
12 use Getopt::Long;
13 use Pod::Usage;
14
15 =head1 NAME
16
17 afs-rmcell - Delete AFS cell files from this machine.
18
19 =head1 SYNOPSIS
20
21 B<afs-rmcell> [B<--batch>] [B<--partition-id>=letter] [B<--help>] [B<--debug>]
22
23 =head1 DESCRIPTION
24
25 This script destroys the AFS database and volume files on this machine.
26 Use with caution!
27
28 =cut
29
30 my $debug = 0;
31 my $help = 0;
32 my $batch = 0;
33 my $partition_id = 'a';
34 my $path = $OpenAFS::Dirpath::openafsdirpath;
35 my $ostype = $path->{'ostype'};
36
37 #-----------------------------------------------------------------------------------
38 # main script
39
40 GetOptions(
41 "debug" => \$debug,
42 "help" => \$help,
43 "batch" => \$batch,
44 "partition-id=s" => \$partition_id,
45 "ostype=s" => \$ostype,
46 );
47
48 $OpenAFS::ConfigUtils::debug = $debug;
49
50 if ($help) {
51 pod2usage(1);
52 exit 0;
53 }
54
55 if ($> != 0) {
56 die "error: This script should run as root.\n";
57 }
58
59 # To be on the safe side, we do no accept the full partition name, just the letter id.
60 # You'll have to manually delete volume files for unconventional partition names.
61 unless ($partition_id=~/^(([a-z])|([a-h][a-z])|([i][a-v]))$/) {
62 die "error: Invalid partition id specified.\n".
63 "info: Please specify a valid partition abbreviation, for example --partition-id='a' for /vicepa\n";
64 }
65
66 unless ($batch) {
67 my $rl = new Term::ReadLine('afs-rmcell');
68 print "\n*** WARNING !! WARNING !! WARNING !! *** \n\n";
69 print "You are about to permanently DESTROY the OpenAFS\n";
70 print "configuration, databases, and volumes on this machine!\n";
71 my $answer = $rl->readline("Do you really want to destroy the AFS cell? (destroy/no) [no] ");
72 unless ($answer eq "destroy" ) {
73 print "info: must answer 'destroy' to continue.\n" if $answer!~/^n/i;
74 print "info: Aborted.\n";
75 exit 0;
76 }
77 }
78
79 my $os = OpenAFS::OS::create('ostype'=>$ostype, 'debug'=>$debug);
80
81 # make sure the client init script has the correct paths.
82 $os->configure_client();
83
84 run($os->command('client-stop'));
85 run($os->command('fileserver-stop'));
86 run($os->command('client-forcestop'));
87
88 $os->remove("$path->{'afsdbdir'}/prdb.DB0");
89 $os->remove("$path->{'afsdbdir'}/prdb.DBSYS1");
90 $os->remove("$path->{'afsdbdir'}/vldb.DB0");
91 $os->remove("$path->{'afsdbdir'}/vldb.DBSYS1");
92 $os->remove("$path->{'afsdbdir'}/kaserver.DB0");
93 $os->remove("$path->{'afsdbdir'}/kaserver.DBSYS1");
94 $os->remove("$path->{'afsbosconfigdir'}/BosConfig");
95 $os->remove("$path->{'afslogsdir'}/*");
96 $os->remove("$path->{'afslocaldir'}/*");
97 $os->remove("$path->{'afsconfdir'}/UserList");
98 $os->remove("$path->{'afsconfdir'}/ThisCell");
99 $os->remove("$path->{'afsconfdir'}/CellServDB");
100 $os->remove("$path->{'afsconfdir'}/KeyFile");
101 $os->remove("$path->{'afsconfdir'}/krb.conf");
102 $os->remove("$path->{'afsddir'}/ThisCell");
103 $os->remove("$path->{'afsddir'}/CellServDB");
104 $os->remove("/vicep$partition_id/AFSIDat ");
105 $os->remove("/vicep$partition_id/V*.vol");
106 $os->remove("/vicep$partition_id/Lock");
107