Browse Source

Split Shellex.pm into it's own repo so I can use it elsewhere

spesk1 4 years ago
parent
commit
b09cbbbf6a
3 changed files with 17 additions and 70 deletions
  1. 15 3
      lib/SimplyGit/Git.pm
  2. 0 65
      lib/SimplyGit/Shellex.pm
  3. 2 2
      sg

+ 15 - 3
lib/SimplyGit/Git.pm

@@ -2,18 +2,30 @@ package SimplyGit::Git;
 use strict;
 use warnings;
 use Log::Log4perl qw(:easy);
-use lib ".";
-use SimplyGit::Shellex qw(shellex findBin knocker);
+use lib "/usr/local/lib/";
+use Shellex::Shellex qw(shellex findBin);
 use Exporter qw(import);
 our @EXPORT_OK = qw(
 	readConfig getStatus returnState addFiles 
 	commitChanges pushChanges stashAndReset resetFromUpstream 
 	updateGitIgnore appendRepoUserConfig parseSGConfig 
-	warnOnUser basicClone basicPull
+	warnOnUser basicClone basicPull knocker
 );
 
 # TODO: Add info/debug logging for all subroutines
 
+sub knocker($$$) {
+
+	my $target = shift;
+	my $portRef = shift;
+	my $logger = shift;
+	my $nmapCmd = findBin("nmap",$logger);
+	foreach my $port (@$portRef) {
+		shellex("$nmapCmd -Pn --host_timeout 201 --max-retries 0 -p $port $target > /dev/null",$logger);
+	}
+
+}
+
 sub checkPath($$) {
 
 	my $path = shift;

+ 0 - 65
lib/SimplyGit/Shellex.pm

@@ -1,65 +0,0 @@
-package SimplyGit::Shellex;
-use strict;
-use warnings;
-use Log::Log4perl qw(:easy);
-use Exporter qw(import);
-our @EXPORT_OK = qw(shellex findBin knocker);
-
-sub knocker($$$) {
-
-	my $target = shift;
-	my $portRef = shift;
-	my $logger = shift;
-	my $nmapCmd = findBin("nmap",$logger);
-	foreach my $port (@$portRef) {
-		shellex("$nmapCmd -Pn --host_timeout 201 --max-retries 0 -p $port $target > /dev/null",$logger);
-	}
-
-}
-
-sub shellex {
-
-        my $cmd = shift;
-	my $logger = shift;
-	if ( defined $logger && $logger ne '' ) {
-		$logger->info("Running: $cmd 2>&1");
-	}
-
-        my $output = `$cmd 2>&1`;
-	chomp $output;
-	my $rc = $?;
-	if ( defined $logger && $logger ne '' ) {
-		$logger->info("Returned: $rc");
-	}
-
-	if ( $rc != 0 ) {
-		if ( defined $logger && $logger ne '' ) {
-			$logger->error("$cmd returned non-zero: $rc");
-		}
-
-		print "$cmd returned non-zero: $rc\n";
-		exit 1;
-	}
-
-        return $output;
-
-}
-
-sub findBin {
-
-	my $cmd = shift;
-	my $logger = shift;
-	my $binPath = shellex("which $cmd",$logger);
-	my $rc = $?;
-	chomp $binPath;
-	if ( $rc != 0 ) {
-		if ( defined $logger && $logger ne '' ) {
-			$logger->error("Couldn't find a path for $cmd, exiting...");
-		}
-		exit 1;
-	} else {
-		return $binPath;
-	}
-
-}
-1;

+ 2 - 2
sg

@@ -7,12 +7,12 @@ use Getopt::Long qw(GetOptions);
 use Log::Log4perl qw(:easy);
 # TODO: This needs to be scoped properly
 use lib "/usr/local/lib";
-use SimplyGit::Shellex qw(shellex findBin knocker);
+use Shellex::Shellex qw(shellex findBin);
 use SimplyGit::Git qw(
 	readConfig getStatus returnState addFiles 
 	commitChanges pushChanges stashAndReset resetFromUpstream 
 	updateGitIgnore appendRepoUserConfig parseSGConfig 
-	warnOnUser basicClone basicPull
+	warnOnUser basicClone basicPull knocker
 );
 
 sub initSG($) {