diff options
author | Jacob Pipkin <j@dawnrazor.net> | 2012-06-01 13:28:14 -0500 |
---|---|---|
committer | Jacob Pipkin <j@dawnrazor.net> | 2012-06-01 13:28:14 -0500 |
commit | 47267ccf2c352348d2d47ff0d91a628d09fdafa8 (patch) | |
tree | a408b2279dacca80a87a2b130ee8e19d7b28e4d9 | |
parent | 74d73ecb3b06a582a2bd8a388d0d5053f01ebcd8 (diff) | |
download | sbotools2-47267ccf2c352348d2d47ff0d91a628d09fdafa8.tar.xz |
sboclean script created.
-rwxr-xr-x | sboclean | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/sboclean b/sboclean new file mode 100755 index 0000000..987e142 --- /dev/null +++ b/sboclean @@ -0,0 +1,78 @@ +#!/usr/bin/env perl +# +# sboclean +# script to clean stuff left around from sbotools. +# +# author: Jacob Pipkin <j@dawnrazor.net> +# date: Boomtime, the 6th day of Confusion in the YOLD 3178 +# license: WTFPL <http://sam.zoy.org/wtfpl/COPYING> + +use SBO::Lib; +use File::Basename; +use Getopt::Std; +use File::Path qr(remove_tree); +use strict; +use warnings FATAL => 'all'; + +my %config = %SBO::Lib::config; +my $self = basename ($0); + +sub show_usage { + print <<EOF +Usage: $self (options) [package] + +Options: + -h: this screen. + -v: version information. + -d: clean distfiles. + -w: clean working directories. + -i: be interactive. + +EOF +} + +my %options; +getopts ('hvdwi', \%options); + +show_usage () && exit (0) if exists $options{h}; +show_version () && exit (0) if exists $options{v}; +my $clean_dist = exists $options{d} ? 'TRUE' : 'FALSE'; +my $clean_work = exists $options{w} ? 'TRUE' : 'FALSE'; +my $interactive = exists $options{i} ? 'TRUE' : 'FALSE'; + +if ($clean_dist eq 'FALSE' && $clean_work eq 'FALSE') { + show_usage (); + die "You must specify at least one of -d or -w.\n"; +} + +sub remove_stuff { + script_error ('remove_stuff requires an argument') unless exists $_[0]; + print "Nothing to do.\n" and return 1 unless -d $_[0]; + my $dir = shift; + opendir (my $dh, $dir); + FIRST: while (my $ls = readdir $dh) { + next if /^\.[\.]{0,1}$/; + if ($interactive eq 'TRUE') { + print "Remove $ls? [yn] "; + my $test = <STDIN>; + next FIRST unless $test =~ /^[Yy]/; + } + unlink $ls if -f $ls; + remove_tree $ls if -d $ls; + } +} + +sub clean_distfiles { + remove_stuff ($config{SBO_HOME} .'/distfiles'); + return; +} + +sub clean_workdirs { + remove_stuff ('/tmp/SBo'); + return; +} + +clean_distfiles () if $clean_dist eq 'TRUE'; +clean_workdirs () if $clean_work eq 'TRUE'; + +exit 0; |