File: uninstall.pl

package info (click to toggle)
redhat-cluster 3.0.12-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 10,620 kB
  • ctags: 14,431
  • sloc: ansic: 150,556; sh: 10,974; perl: 4,383; python: 3,022; makefile: 2,253; xml: 61
file content (71 lines) | stat: -rw-r--r-- 1,820 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/perl

##    Description: Basically the reverse of the install program, except it
##                 only supports a list of files and a directory as arguments

$| = 1;

use Getopt::Std;

# list all valid options here.  User will get errors if invalid options are 
# specified on the command line
getopts('hD');

$args = 1;

# We need at least two arguments to uninstall
if(!defined($ARGV[1])) {
    $args = 0;
}
    
# if the user set the help flag or didn't provide enough args, print help 
# and die.
if(defined($opt_h) || ($args == 0)) {
  $msg = "usage: $0 [OPTIONS] TARGET DIRECTORY\n";
  $msg = $msg . "\t-D\tRemove specified directory if empty\n";
  $msg = $msg . "\t-h\tDisplay this help message\n";
  die $msg;
}

# find out how many command line arguments we have
$length = $#ARGV;
# We need a special case if there is only one file specified
if($length > 1) {
  @filelist = @ARGV;
  $#filelist = $length - 1;
}
else {
  @filelist = @ARGV[0];
}

# the last argument is the directory
$dir = @ARGV[$length];

# prepend the directory name to all files in the filelist
$i = 0;
print "Attempting to remove the following files from directory $dir/:\n";
while($i < $length) {
  print "@filelist[$i] ";
  @filelist[$i] = "$dir/" . @filelist[$i];
  $i++;
}
print "\n";
  
#print "Files:@filelist\n";
#print "Directory: $dir\n";

# delete the files in filelist
$unlinked = unlink @filelist;
if($unlinked < $length) {
  print "Error! Unable to remove all files in $dir:\n\tYou may have to manually delete some of them.\n"
}
# if user specifed they want the directory deleted, try to delete it.  Print 
# error message if not able to delete directory, including error.
if(defined($opt_D)) {
  $result = rmdir($dir);
  if($result == FALSE) {
    print "Error! Unable to remove directory $dir/:\n\t$!\n";
  }
}