From cdff1e100bee21c0bc53429c84b6adb140bb86eb Mon Sep 17 00:00:00 2001 From: Mason James 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 set adds a --gitify arg and a --kohadir arg to koha-shell To test: gitify an install apply both patches, then copy patched koha-shell to /usr/sbin dir run sudo koha-shell instance run env | grep PERL5LIB, it should be set to /usr/share/koha/lib run sudo koha-shell -d /path/to/your/git/install instance run env | grep PERL5LIB, it should be set to /path/to/your/git/install run which koha-list, it should be set to /usr/sbin/koha-list run sudo koha-shell -g -d /path/to/your/git/install instance run env | grep PERL5LIB, it should be set to /path/to/your/git/install run env | grep PATH, it should be set to /path/to/your/git/install/debian/scripts:$PATH run env | grep KOHA_GITIFY, it should be set to 1 run which koha-list, it should be set to /path/to/your/git/install/debian/scripts/koha-list run koha-list, it should work as expected run sudo koha-shell -g instance, it should give error... 'You must supply --kohadir when using --gitify' https://bugs.koha-community.org/show_bug.cgi?id=13295 --- debian/scripts/koha-shell | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/debian/scripts/koha-shell b/debian/scripts/koha-shell index 26fa411..d011e66 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 ); @@ -38,6 +38,13 @@ if ( !-e "/etc/koha/sites/$instance" ) { show_help( 1, "The instance doesn't exist: $instance" ); exit(1); } + +# quit, if --gitify is used without a --kohadir arg +if ( exists $opts{gitify} and not exists $opts{kohadir} ) { + show_help( 1, "You must supply --kohadir when using --gitify" ); + exit(1); +} + my $shell = $opts{shell} || $ENV{SHELL} || '/bin/sh'; my $kohadir; if ( $opts{kohadir} ) { @@ -46,16 +53,21 @@ 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 "; + +# if --gitify, add --kohadir to $PATH and set useful KOHA_GITIFY env var +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 +102,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 (must also provide a --kohadir option) The default shell is the one currently in use. Refer to su(1) for more detail on these options. -- 2.1.4