1 | #!/usr/bin/perl -w
|
---|
2 |
|
---|
3 | ###########################################################################
|
---|
4 | #
|
---|
5 | # delcol.pl --
|
---|
6 | # A component of the Greenstone digital library software
|
---|
7 | # from the New Zealand Digital Library Project at the
|
---|
8 | # University of Waikato, New Zealand.
|
---|
9 | #
|
---|
10 | # Copyright (C) 1999 New Zealand Digital Library Project
|
---|
11 | #
|
---|
12 | # This program is free software; you can redistribute it and/or modify
|
---|
13 | # it under the terms of the GNU General Public License as published by
|
---|
14 | # the Free Software Foundation; either version 2 of the License, or
|
---|
15 | # (at your option) any later version.
|
---|
16 | #
|
---|
17 | # This program is distributed in the hope that it will be useful,
|
---|
18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
20 | # GNU General Public License for more details.
|
---|
21 | #
|
---|
22 | # You should have received a copy of the GNU General Public License
|
---|
23 | # along with this program; if not, write to the Free Software
|
---|
24 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
25 | #
|
---|
26 | ###########################################################################
|
---|
27 |
|
---|
28 | BEGIN {
|
---|
29 | die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
|
---|
30 | unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
|
---|
31 | }
|
---|
32 |
|
---|
33 | use util;
|
---|
34 | use parsargv;
|
---|
35 |
|
---|
36 | sub print_usage {
|
---|
37 | print STDERR "\n";
|
---|
38 | print STDERR "delcol.pl: Deletes (forever) a collection.\n\n";
|
---|
39 | print STDERR " usage: $0 [options] collection-name\n\n";
|
---|
40 | print STDERR " options:\n";
|
---|
41 | print STDERR " -f Force deletion of collection without prompting\n\n";
|
---|
42 | }
|
---|
43 |
|
---|
44 | &main();
|
---|
45 |
|
---|
46 | sub main {
|
---|
47 | my $force = 0;
|
---|
48 | if (!parsargv::parse(\@ARGV, 'f', \$force)) {
|
---|
49 | &print_usage();
|
---|
50 | die "\n";
|
---|
51 | }
|
---|
52 |
|
---|
53 | # get and check the collection name
|
---|
54 | if (($collection = &util::use_collection(@ARGV)) eq "") {
|
---|
55 | &print_usage();
|
---|
56 | exit (1);
|
---|
57 | }
|
---|
58 |
|
---|
59 | if (!$force) {
|
---|
60 | print STDOUT "Are you sure you want to completely remove the $collection collection?\n";
|
---|
61 | print STDOUT "(the $ENV{'GSDLCOLLECTDIR'} directory will be deleted). [y/n]\n";
|
---|
62 | my $in = <STDIN>;
|
---|
63 | if ($in !~ /^y(es)?$/i) {
|
---|
64 | print STDOUT "Deletion of $collection collection cancelled\n";
|
---|
65 | exit (0);
|
---|
66 | }
|
---|
67 | }
|
---|
68 | # delete any temporary files that are laying around
|
---|
69 | my $tmpdir = &util::filename_cat ($ENV{'GSDLHOME'}, "tmp");
|
---|
70 | if (opendir (TMPDIR, $tmpdir)) {
|
---|
71 | my @tmpfiles = readdir (TMPDIR);
|
---|
72 | closedir TMPDIR;
|
---|
73 | map { &util::rm(&util::filename_cat($tmpdir, $_)) if $_ =~ /^$collection/; } @tmpfiles;
|
---|
74 | }
|
---|
75 |
|
---|
76 | &util::rm_r ($ENV{'GSDLCOLLECTDIR'});
|
---|
77 |
|
---|
78 | # check if everything was deleted successfully
|
---|
79 | if (-d $ENV{'GSDLCOLLECTDIR'}) {
|
---|
80 | print STDERR "\ndelcol.pl WARNING: Not all files in $ENV{'GSDLCOLLECTDIR'} could\n";
|
---|
81 | print STDERR "be deleted\n";
|
---|
82 | exit (2);
|
---|
83 | }
|
---|
84 |
|
---|
85 | print STDERR "$collection collection successfully deleted\n";
|
---|
86 | exit (0);
|
---|
87 | }
|
---|