d837bad3d3377cac7f6d06a4e60d2064abd9fe5a
commit d837bad3d3377cac7f6d06a4e60d2064abd9fe5a
Author: spesk1 <spesk@pm.me>
Date: Fri Jun 21 12:06:54 2019 -0400

Split of Shellex.pm from simply-git

diff --git a/README.md b/README.md
index f9e5fef..593ac20 100644
--- a/README.md
+++ b/README.md
@@ -2,3 +2,8 @@

General purpose module that I use for shelling out in a way that I like in Perl.
May or may not be useful to others.
+
+## Depends on ##
+* which
+* Log4Perl Perl lib
+* Assumes your shell is bash
diff --git a/install.sh b/install.sh
new file mode 100755
index 0000000..e8fad0f
--- /dev/null
+++ b/install.sh
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+libDir="/usr/local/lib/Shellex/"
+
+if [ ! -d $libDir ]; then
+ echo "Making $libDir"
+ sudo mkdir -p $libDir
+fi
+
+echo "Calling sudo to copy libs"
+sudo cp ./lib/Shellex/* $libDir
diff --git a/lib/Shellex/Shellex.pm b/lib/Shellex/Shellex.pm
new file mode 100644
index 0000000..f30948f
--- /dev/null
+++ b/lib/Shellex/Shellex.pm
@@ -0,0 +1,53 @@
+package Shellex::Shellex;
+use strict;
+use warnings;
+use Log::Log4perl qw(:easy);
+use Exporter qw(import);
+our @EXPORT_OK = qw(shellex findBin);
+
+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;