Bug 13501: Fix behavior of 'Delete subfield' button on select2 controls
[koha.git] / debian / scripts / koha-shell
blobb8d92f556d62bd4c8c1f6f4bc8fcbe5d3a61c3b5
1 #!/usr/bin/perl
2 # koha-shell -- put you in a shell with a koha environment set up
3 # Copyright 2012 Catalyst IT, Ltd
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 use Getopt::Long;
19 use Modern::Perl;
21 Getopt::Long::Configure("bundling");
23 my %opts;
24 my $res = GetOptions( \%opts, "command|c=s", "help|h", "login|l", "shell|s=s",
25 "preserve-environment|p|m", "verbose|v" );
27 if ( !$res || $opts{help} ) {
28 show_help( !$res );
29 exit( !$res );
32 if ( !@ARGV ) {
33 show_help( 1, "An instance name must be supplied." );
34 exit(1);
36 my $instance = shift @ARGV;
37 if ( !-e "/etc/koha/sites/$instance" ) {
38 show_help( 1, "The instance doesn't exist: $instance" );
39 exit(1);
41 my $shell = $opts{shell} || $ENV{SHELL} || '/bin/sh';
43 # Now we're set up, build the 'su' command
44 my @su_args;
45 push @su_args, '/usr/bin/sudo';
46 push @su_args, '--preserve-env' if $opts{'preserve-environment'};
47 push @su_args, '--login' if $opts{login};
48 push @su_args, "-u", "$instance-koha";
49 push @su_args,
50 "env "
51 . "KOHA_CONF=/etc/koha/sites/$instance/koha-conf.xml "
52 . "PERL5LIB=/usr/share/koha/lib $shell"
53 . ( $opts{command} ? " -c '$opts{command}'" : '' );
55 print "Command: '".join("' '",@su_args)."'\n" if $opts{verbose};
56 system("@su_args");
57 if ( $? == -1 ) {
58 print STDERR "failed to execute: $!\n";
60 elsif ( $? & 127 ) {
61 printf STDERR "child died with signal %d, %s coredump\n",
62 ( $? & 127 ), ( $? & 128 ) ? 'with' : 'without';
65 sub show_help {
66 my ( $err, $msg ) = @_;
68 my $fh = $err ? *STDERR : *STDOUT;
69 say $fh "Error: " . $msg if $msg;
70 print $fh $_ while <DATA>;
73 __DATA__
74 koha-shell -- gives you a shell with your Koha environment set up
76 Usage: koha-shell [options] [instance name]
78 Options:
79 -c, --command COMMAND pass COMMAND to the invoked shell
80 -h, --help show this help and quit
81 -l, --login make the shell a login shell
82 -m, -p,
83 --preserve-environment do not reset environment variables
84 -s, --shell SHELL use SHELL instead of the one from your environment
85 -v, --verbose output the full command that will be executed
87 The default shell is the one currently in use. Refer to su(1) for more detail
88 on these options.