#!/usr/bin/env perl # # sbofind # script to locate something in a local SlackBuilds tree. # # author: Jacob Pipkin # date: Boomtime, the 39th day of Discord in the YOLD 3178 # license: WTFPL use SBO::Lib; use File::Basename; use Getopt::Std; use strict; use warnings FATAL => 'all'; my %config = %SBO::Lib::config; my $self = basename ($0); sub show_usage { print <) { unless ($found eq 'TRUE') { if ($line =~ $regex) { $found = 'TRUE'; my @split = split (' ', $line); chomp ($name = $split[2]); next FIRST; } } else { if ($line =~ /LOCATION/) { $found = 'FALSE'; my @split = split (' ', $line); chomp (my $location = $split[2]); $location =~ s#^\.##; push (@findings, {$name => $config{SBO_HOME} . $location} ); } } } sub get_file_contents { script_error ('get_file_contents requires an argument') unless exists $_[0]; script_error ('get_file_contents argument is not a file') unless -f $_[0]; my $file = shift; open my $fh, '<', $file; my $contents = do {local $/; <$fh>}; $contents =~ s/\n/\n /g; $contents =~ s/ $//g; return $contents; } # pretty formatting if (exists $findings[0]) { my @listing = ("\n"); for my $hash (@findings) { while (my ($key, $value) = each %{$hash}) { push (@listing, "SBo: $key\n"); push (@listing, "Path: $value\n"); push (@listing, "info: ". get_file_contents ("$value/$key.info") ) if $show_info eq 'TRUE'; push (@listing, "README: ". get_file_contents ("$value/README") ) if $show_readme eq 'TRUE'; push (@listing, "\n"); } } print $_ for @listing; } else { print "Nothing found for search term: $search\n"; } exit 0;