source: main/trunk/greenstone2/bin/script/cancel_build.pl@ 24375

Last change on this file since 24375 was 1970, checked in by sjboddie, 23 years ago

Added more usage information to all perl programs and removed a few
programs that are no longer useful.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 4.5 KB
Line 
1#!/usr/bin/perl -w
2
3###########################################################################
4#
5# cancel_build.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) 2000 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
29# This program will create a .kill file within the GSDLCOLLECTDIR/collect-name
30# directory which will cause any import.pl or buildcol.pl processes running
31# on that collection to abort.
32# It then cleans any mess left laying around the collection (including the
33# import directory !!).
34# cancel_build.pl is really only intended to be called from within the
35# library's collectoraction and isn't much use for anything else. As such it
36# should be rewritten in C++ one day and included in the collectoraction
37# itself.
38
39BEGIN {
40 die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
41 unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
42}
43
44use util;
45use parsargv;
46use File::Copy;
47
48sub print_usage {
49 print STDERR "\n";
50 print STDERR "cancel_build.pl: Cancel a build in progress. This script is\n";
51 print STDERR " called from the collector and is not intended\n";
52 print STDERR " for general use.\n\n";
53 print STDERR " usage: $0 [options] collection-name\n\n";
54 print STDERR " options:\n";
55 print STDERR " -collectdir directory Collection directory (defaults to " .
56 &util::filename_cat ($ENV{'GSDLHOME'}, "collect") . ")\n\n";
57}
58
59&main();
60
61sub main {
62 if (!parsargv::parse(\@ARGV, 'collectdir/.*/', \$collectdir)) {
63 &print_usage();
64 die "\n";
65 }
66
67 my $collection = pop @ARGV;
68 if (!defined $collection || $collection !~ /\w/) {
69 print STDERR "no collection specified\n";
70 &print_usage();
71 die "\n";
72 }
73
74 my $cdir = &util::filename_cat ($collectdir, $collection);
75 if ($collectdir eq "") {
76 $collectdir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect");
77 $cdir = &util::filename_cat ($collectdir, $collection);
78 } elsif (!-d $cdir) {
79 $cdir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $collection);
80 }
81
82 if (! -d $cdir) {
83 print STDERR "Collection does not exist ($cdir)\n";
84 exit (1);
85 }
86
87 # create .kill file
88 my $killfile = &util::filename_cat ($cdir, ".kill");
89 if (!open (KILLFILE, ">$killfile")) {
90 print STDERR "Couldn't create .kill file ($killfile)\n";
91 exit (1);
92 }
93 print KILLFILE "kill $collection\n";
94 close KILLFILE;
95
96 sleep (2); # just give it a chance to die gracefully;
97
98 # remove archives, building, and import directories
99 &util::rm_r (&util::filename_cat ($cdir, "import"));
100 &util::rm_r (&util::filename_cat ($cdir, "building"));
101 &util::rm_r (&util::filename_cat ($cdir, "archives"));
102
103 # remove any other temporary files that may have been left laying around
104 # by the build
105 my $buildfile = &util::filename_cat ($collectdir, ".build");
106 &util::rm ($buildfile) if -e $buildfile;
107 my $bldfile = &util::filename_cat ($collectdir, "$collection.bld");
108 &util::rm ($bldfile) if -e $bldfile;
109 my $bldfile_d = &util::filename_cat ($collectdir, "$collection.bld.download");
110 &util::rm ($bldfile_d) if -e $bldfile_d;
111 my $bldfile_i = &util::filename_cat ($collectdir, "$collection.bld.import");
112 &util::rm ($bldfile_i) if -e $bldfile_i;
113 my $bldfile_b = &util::filename_cat ($collectdir, "$collection.bld.build");
114 &util::rm ($bldfile_b) if -e $bldfile_b;
115 my $bldfile_f = &util::filename_cat ($collectdir, "$collection.bld.final");
116 &util::rm ($bldfile_f) if -e $bldfile_f;
117
118 # if there's an archives.org directory, rename it back to archives
119 if (-d &util::filename_cat ($cdir, "archives.org")) {
120 &File::Copy::move (&util::filename_cat ($cdir, "archives.org"),
121 &util::filename_cat ($cdir, "archives"));
122 }
123}
Note: See TracBrowser for help on using the repository browser.