blob: e9aedd8efa383c36c5da49f81bf365576b2376d9 (
plain)
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
72
73
74
75
76
|
#!/usr/bin/env perl
#
# vim: set ts=4:noet
#
# sboclean
# script to clean stuff left around from sbotools.
#
# author: Jacob Pipkin <j@dawnrazor.net>
# license: WTFPL <http://sam.zoy.org/wtfpl/COPYING>
use 5.16.0;
use strict;
use warnings FATAL => 'all';
use SBO::Lib;
use File::Basename;
use Getopt::Long qw(:config bundling);
use File::Path qw(remove_tree);
my $self = basename ($0);
sub show_usage () {
print <<EOF
Usage: $self (options) [package]
Options:
-h|--help:
this screen.
-v|--version:
version information.
-d|--clean-dist:
clean distfiles.
-w|--clean-work:
clean working directories.
-i|--interactive:
be interactive.
EOF
}
my ($help, $vers, $clean_dist, $clean_work, $interactive);
GetOptions (
'help|h' => \$help,
'version|v' => \$vers,
'clean-dist|d' => \$clean_dist,
'clean-work|w' => \$clean_work,
'interactive|i' => \$interactive,
);
show_usage and exit 0 if $help;
show_version and exit 0 if $vers;
show_usage, die "You must specify at least one of -d or -w.\n" unless
($clean_dist || $clean_work);
sub remove_stuff ($) {
exists $_[0] or script_error 'remove_stuff requires an argument';
-d $_[0] or say 'Nothing to do.' and return 1;
my $dir = shift;
opendir (my $dh, $dir);
FIRST: while (my $ls = readdir $dh) {
next FIRST if $ls =~ /^(\.){1,2}$/;
my $full = "$dir/$ls";
if ($interactive) {
print "Remove $full? [n] ";
next FIRST unless <STDIN> =~ /^[Yy]/;
}
unlink $full if -f $full;
remove_tree ($full) if -d $full;
}
}
remove_stuff $config{SBO_HOME} .'/distfiles' if $clean_dist;
remove_stuff '/tmp/SBo' if $clean_work;
exit 0;
|