source: trunk/gsdl/bin/script/delcol.pl@ 1452

Last change on this file since 1452 was 1452, checked in by sjboddie, 24 years ago

* empty log message *

  • Property svn:keywords set to Author Date Id Revision
File size: 2.6 KB
Line 
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
28BEGIN {
29 die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
30 unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
31}
32
33use util;
34use parsargv;
35
36sub print_usage {
37 print STDERR "\n usage: $0 [options] collection-name\n\n";
38 print STDERR " options:\n";
39 print STDERR " -f Force deletion of collection without prompting\n\n";
40}
41
42&main();
43
44sub main {
45 my $force = 0;
46 if (!parsargv::parse(\@ARGV, 'f', \$force)) {
47 &print_usage();
48 die "\n";
49 }
50
51 # get and check the collection name
52 if (($collection = &util::use_collection(@ARGV)) eq "") {
53 &print_usage();
54 exit (1);
55 }
56
57 if (!$force) {
58 print STDOUT "Are you sure you want to completely remove the $collection collection?\n";
59 print STDOUT "(the $ENV{'GSDLCOLLECTDIR'} directory will be deleted). [y/n]\n";
60 my $in = <STDIN>;
61 if ($in !~ /^y(es)?$/i) {
62 print STDOUT "Deletion of $collection collection cancelled\n";
63 exit (0);
64 }
65 }
66 # delete any temporary files that are laying around
67 my $tmpdir = &util::filename_cat ($ENV{'GSDLHOME'}, "tmp");
68 if (opendir (TMPDIR, $tmpdir)) {
69 my @tmpfiles = readdir (TMPDIR);
70 closedir TMPDIR;
71 map { &util::rm(&util::filename_cat($tmpdir, $_)) if $_ =~ /^$collection/; } @tmpfiles;
72 }
73
74 &util::rm_r ($ENV{'GSDLCOLLECTDIR'});
75
76 # check if everything was deleted successfully
77 if (-d $ENV{'GSDLCOLLECTDIR'}) {
78 print STDERR "\ndelcol.pl WARNING: Not all files in $ENV{'GSDLCOLLECTDIR'} could\n";
79 print STDERR "be deleted\n";
80 exit (2);
81 }
82
83 print STDERR "$collection collection successfully deleted\n";
84 exit (0);
85}
Note: See TracBrowser for help on using the repository browser.