Marcel de Rooy
08ece513cd
This patch makes the following changes: koha-foreach, koha-upgrade-schema (shell scripts): [1] Read default file [2] Include helper functions [3] Add call to adjust_paths_dev_install [4] Replace hardcoded path by $PERL5LIB koha-shell (perl script): [1] Remove hardcoded lib path [2] Add a sub that reads PERL5LIB from default or koha-conf, just as the shell scripts do. koha-plack (shell script), plack.psgi: [1] Add call to adjust_paths_dev_install [2] Remove hardcoded lib path [3] Add installer path to PERL5LIB, remove it from plack.pgsi koha-sitemap (shell script): [1] Add call to adjust_paths_dev_install [2] Remove hardcoded lib path [3] Add installer path to PERL5LIB [4] Adjust path for call to sitemap cron job koha-start-sip (shell script): [1] Read default file [2] Include helper functions [3] Add call to adjust_paths_dev_install [4] Adjust path to C4/SIP koha-stop-sip (shell script): [1] Remove KOHA_CONF and PERL5LIB (not needed to stop the daemon) [2] Same for paths in daemon client options NOTE: Script debian/scripts/koha-upgrade-to-3.4 has been left out intentionally. Test plan: [1] Regular install: Run koha-foreach echo Hi Run koha-upgrade-schema yourinstance Run koha-shell yourinstance If you have plack, run koha-plack --start|--stop yourinstance Run koha-sitemap --generate yourinstance Run koha-start-sip yourinstance Run koha-stop-sip yourinstance [2] Dev install [yourinstance] with <dev_install> in koha-conf.xml: Run koha-upgrade-schema yourinstance Run koha-shell yourinstance If you have plack: koha-plack --start|--stop yourinstance Run koha-sitemap --generate yourinstance Run koha-start-sip yourinstance Run koha-stop-sip yourinstance [3] Git grep on koha/lib You should no longer see occurrences in debian/scripts except: koha-translate: see report 16749 koha-upgrade-to-3.4: left out intentionally [4] Git grep on koha/bin You should only see hits for lines with koha-functions in the debian scripts except: koha-upgrade-to-3.4: left out intentionally Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Most scripts tested on Wheezy (although it would not matter much). Plack script tested on Jessie. Signed-off-by: Owen Leonard <oleonard@myacpl.org> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
104 lines
3.2 KiB
Perl
Executable file
104 lines
3.2 KiB
Perl
Executable file
#!/usr/bin/perl
|
|
# koha-shell -- put you in a shell with a koha environment set up
|
|
# Copyright 2012 Catalyst IT, Ltd
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
use Getopt::Long;
|
|
use Modern::Perl;
|
|
|
|
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" );
|
|
|
|
if ( !$res || $opts{help} ) {
|
|
show_help( !$res );
|
|
exit( !$res );
|
|
}
|
|
|
|
if ( !@ARGV ) {
|
|
show_help( 1, "An instance name must be supplied." );
|
|
exit(1);
|
|
}
|
|
my $instance = shift @ARGV;
|
|
if ( !-e "/etc/koha/sites/$instance" ) {
|
|
show_help( 1, "The instance doesn't exist: $instance" );
|
|
exit(1);
|
|
}
|
|
my $shell = $opts{shell} || $ENV{SHELL} || '/bin/sh';
|
|
|
|
# Now we're set up, build the 'su' command
|
|
my $perl5lib = read_perl5lib( $instance );
|
|
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 "
|
|
. "KOHA_CONF=/etc/koha/sites/$instance/koha-conf.xml "
|
|
. "PERL5LIB=$perl5lib $shell"
|
|
. ( $opts{command} ? " -c '$opts{command}'" : '' );
|
|
|
|
print "Command: '".join("' '",@su_args)."'\n" if $opts{verbose};
|
|
system("@su_args");
|
|
if ( $? == -1 ) {
|
|
print STDERR "failed to execute: $!\n";
|
|
}
|
|
elsif ( $? & 127 ) {
|
|
printf STDERR "child died with signal %d, %s coredump\n",
|
|
( $? & 127 ), ( $? & 128 ) ? 'with' : 'without';
|
|
}
|
|
|
|
sub show_help {
|
|
my ( $err, $msg ) = @_;
|
|
|
|
my $fh = $err ? *STDERR : *STDOUT;
|
|
say $fh "Error: " . $msg if $msg;
|
|
print $fh $_ while <DATA>;
|
|
}
|
|
|
|
sub read_perl5lib {
|
|
my ( $instance ) = @_;
|
|
|
|
# This simulates what the debian shell scripts do:
|
|
# Read /etc/default/koha-common
|
|
# Check dev_install in koha-conf.xml
|
|
|
|
my $result = `grep "^PERL5LIB=" /etc/default/koha-common`;
|
|
chomp $result;
|
|
$result =~ s/^PERL5LIB=\s*//;
|
|
my $dev_install = `xmlstarlet sel -t -v 'yazgfs/config/dev_install' /etc/koha/sites/$instance/koha-conf.xml`;
|
|
chomp $dev_install;
|
|
return $dev_install || $result;
|
|
}
|
|
|
|
__DATA__
|
|
koha-shell -- gives you a shell with your Koha environment set up
|
|
|
|
Usage: koha-shell [options] [instance name]
|
|
|
|
Options:
|
|
-c, --command COMMAND pass COMMAND to the invoked shell
|
|
-h, --help show this help and quit
|
|
-l, --login make the shell a login shell
|
|
-m, -p,
|
|
--preserve-environment do not reset environment variables
|
|
-s, --shell SHELL use SHELL instead of the one from your environment
|
|
-v, --verbose output the full command that will be executed
|
|
|
|
The default shell is the one currently in use. Refer to su(1) for more detail
|
|
on these options.
|