From 260664457392001a9922c4d2734795359d78e174 Mon Sep 17 00:00:00 2001
From: Mason James <mtj@kohaaloha.com>
Date: Mon, 11 Apr 2016 21:08:07 +1200
Subject: [PATCH] Bug 13216 - fix koha-shell to work with git/dev installs
Content-Type: text/plain; charset="utf-8"

The aim of this patch is to enable developers to begin testing Koha tools from a gitified Koha directory, using koha-shell

this patch adds a new --gitify arg to koha-shell, to be used with the new -d option

to test new --gitify arg...

1/ apply 1st patch

2/ run a "koha-shell -c 'which koha-*'" on a Koha tool, with -d arg

 # perl ~/koha-master/debian/scripts/koha-shell  -d ~/koha-master  -c 'which koha-list ' moof
/usr/sbin/koha-list <<<<

3/ observe existing /usr/share/koha/* file is selected, hmm...

4/ apply 2nd patch - and repeat 2/ with --gitify arg

 # perl ~/koha-master/debian/scripts/koha-shell  -d ~/koha-master  -g -c 'which koha-list ' moof
~/koha-master/debian/scripts/koha-list <<<<

5/ observe file from the git repo is now selected

 .-=bonus points, xXxtra merit=-.
6/ run tool to make sure it works
 # perl ~/koha-master/debian/scripts/koha-shell  -d ~/koha-master  -g -c 'koha-list' moof
...

7/ run the old tool too
 # perl ~/koha-master/debian/scripts/koha-shell  -c 'koha-list' moof
...
---
 debian/scripts/koha-shell | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/debian/scripts/koha-shell b/debian/scripts/koha-shell
index 26fa411..941dbde 100755
--- a/debian/scripts/koha-shell
+++ b/debian/scripts/koha-shell
@@ -22,7 +22,7 @@ Getopt::Long::Configure("bundling");
 
 my %opts;
 my $res = GetOptions( \%opts, "command|c=s", "help|h", "login|l", "shell|s=s",
-    "preserve-environment|p|m", "verbose|v", "kohadir|d=s" );
+    "preserve-environment|p|m", "verbose|v", "kohadir|d=s", "gitify|g" );
 
 if ( !$res || $opts{help} ) {
     show_help( !$res );
@@ -46,16 +46,18 @@ if ( $opts{kohadir} ) {
 else {
     $kohadir = '/usr/share/koha/lib';
 }
+
 # Now we're set up, build the 'su' command
 my @su_args;
 push @su_args, '/usr/bin/sudo';
 push @su_args, '--preserve-env' if $opts{'preserve-environment'};
 push @su_args, '--login' if $opts{login};
 push @su_args, "-u", "$instance-koha";
+push @su_args, "env ";
+push @su_args, "PATH=$kohadir/debian/scripts".':$PATH KOHA_GITIFY=1 ' if  $opts{gitify};
 push @su_args,
-    "env "
-  . "KOHA_CONF=/etc/koha/sites/$instance/koha-conf.xml "
-  . "PERL5LIB=$kohadir $shell"
+    "KOHA_CONF=/etc/koha/sites/$instance/koha-conf.xml "
+  . "PERL5LIB=$kohadir $shell "
   . ( $opts{command} ? " -c '$opts{command}'" : '' );
 
 print "Command: '".join("' '",@su_args)."'\n" if $opts{verbose};
@@ -90,6 +92,7 @@ Options:
     -s, --shell SHELL               use SHELL instead of the one from your environment
     -v, --verbose                   output the full command that will be executed
     -d, --kohadir /path/to/koha     use a different PERL5LIB directory, for example in a git install.
+    -g, --gitify                    use koha-shell for a git type install, with -d option
 
 The default shell is the one currently in use. Refer to su(1) for more detail
 on these options.
-- 
2.1.4