View | Details | Raw Unified | Return to bug 8878
Collapse All | Expand All

(-)a/debian/docs/koha-shell.xml (+112 lines)
Line 0 Link Here
1
<article xmlns='http://docbook.org/ns/docbook'>
2
    <title>koha-shell</title>
3
    <info>
4
        <productname>Koha</productname> is the first free software library automation package.
5
        <author>
6
            <personname>
7
                <firstname>Robin</firstname>
8
                <surname>Sheat</surname>
9
            </personname>
10
            <affiliation>
11
                <orgname>Catalyst IT</orgname>
12
                <uri>http://www.catalyst.net.nz</uri>
13
            </affiliation>
14
            <contrib>Author</contrib>
15
        </author>
16
    </info>
17
18
    <refentry xml:id="koha-shell">
19
20
        <refmeta>
21
            <refentrytitle>koha-shell</refentrytitle>
22
            <manvolnum>8</manvolnum>
23
        </refmeta>
24
25
        <refnamediv>
26
            <refname>koha-shell</refname>
27
            <refpurpose>Gives you a shell with the user and environment set to make it easy to do koha operations.</refpurpose>
28
            <refclass>UNIX/Linux</refclass>
29
        </refnamediv>
30
31
        <refsynopsisdiv>
32
            <cmdsynopsis>
33
                <command>koha-shell</command>
34
                <arg><option>--command|-c</option> COMMAND</arg>
35
                <arg><option>--help|-h</option></arg>
36
                <arg><option>--login|-l</option></arg>
37
                <arg><option>--preserve-environment|-p|-m</option></arg>
38
                <arg><option>--shell|-s</option> SHELL</arg>
39
                <arg><option>--verbose|-v</option></arg>
40
                <arg choice="req" rep="norepeat"><replaceable>instancename</replaceable></arg>
41
            </cmdsynopsis>
42
        </refsynopsisdiv>
43
44
        <refsect1><title>Options</title>
45
            <variablelist> 
46
                <varlistentry>
47
                    <term><option>--command</option></term>
48
                    <listitem>
49
                        <para>Run the specified command rather than launching a shell.</para>
50
                    </listitem>
51
                </varlistentry>
52
                <varlistentry>
53
                    <term><option>--help</option></term>
54
                    <listitem>
55
                        <para>Show a usage synopsis.</para>
56
                    </listitem>
57
                </varlistentry>
58
                <varlistentry>
59
                    <term><option>--login</option></term>
60
                    <listitem>
61
                        <para>Make the shell a login shell.</para>
62
                    </listitem>
63
                </varlistentry>
64
                <varlistentry>
65
                    <term><option>--preserve-environment</option></term>
66
                    <listitem>
67
                        <para>Preserve the current environment (note that if you run it through 'sudo', this may not work as you'd expect.)</para>
68
                    </listitem>
69
                </varlistentry>
70
                <varlistentry>
71
                    <term><option>--shell</option></term>
72
                    <listitem>
73
                        <para>Run the specified shell. The default is the shell of the current environment, followed by /bin/sh.</para>
74
                    </listitem>
75
                </varlistentry>
76
                <varlistentry>
77
                    <term><option>--verbose</option></term>
78
                    <listitem>
79
                        <para>Show the command that is going to be run.</para>
80
                    </listitem>
81
                </varlistentry>
82
            </variablelist>
83
        </refsect1>
84
85
        <refsect1><title>Description</title>
86
            <para>This launches a shell with the user and required environment variables set in such a way that running any Koha commands will
87
                work correctly. With the use of '-c', it can be used to easily run commands in the correct environment.</para>
88
            <para>It behaves mostly as a wrapper for <command>su(1)</command>, so a deeper discussion of the options can be found in there.</para>
89
        </refsect1>
90
91
        <refsect1>
92
            <title>Examples</title>
93
            <para>
94
                To get a shell:
95
            </para>
96
            <para><command>$ sudo koha-shell library</command></para>
97
            <para>
98
                To run a command:
99
            </para>
100
            <para><command>$ sudo koha-shell -c "/usr/share/koha/bin/migration_tools/bulkmarcimport.pl -b -file data.marc" library</command></para>
101
        </refsect1>
102
103
        <refsect1><title>See also</title>
104
            <simplelist type="inline">
105
                <member><command>koha-foreach(8)</command></member>
106
                <member><command>su(1)</command></member>
107
            </simplelist>
108
        </refsect1>
109
110
    </refentry>
111
112
</article>
(-)a/debian/koha-common.install (+1 lines)
Lines 24-29 debian/scripts/koha-reset-passwd usr/sbin Link Here
24
debian/scripts/koha-restart-zebra           usr/sbin
24
debian/scripts/koha-restart-zebra           usr/sbin
25
debian/scripts/koha-restore                 usr/sbin
25
debian/scripts/koha-restore                 usr/sbin
26
debian/scripts/koha-run-backups             usr/sbin
26
debian/scripts/koha-run-backups             usr/sbin
27
debian/scripts/koha-shell                   usr/sbin
27
debian/scripts/koha-start-zebra             usr/sbin
28
debian/scripts/koha-start-zebra             usr/sbin
28
debian/scripts/koha-stop-zebra              usr/sbin
29
debian/scripts/koha-stop-zebra              usr/sbin
29
debian/scripts/koha-upgrade-schema          usr/sbin
30
debian/scripts/koha-upgrade-schema          usr/sbin
(-)a/debian/scripts/koha-shell (-1 / +88 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
# koha-shell -- put you in a shell with a koha environment set up
3
# Copyright 2012  Catalyst IT, Ltd
4
#
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.
9
#
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.
14
#
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/>.
17
18
use Getopt::Long;
19
use Modern::Perl;
20
21
Getopt::Long::Configure("bundling");
22
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" );
26
27
if ( !$res || $opts{help} ) {
28
    show_help( !$res );
29
    exit( !$res );
30
}
31
32
if ( !@ARGV ) {
33
    show_help( 1, "An instance name must be supplied." );
34
    exit(1);
35
}
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);
40
}
41
my $shell = $opts{shell} || $ENV{SHELL} || '/bin/sh';
42
43
# Now we're set up, build the 'su' command
44
my @su_args;
45
push @su_args, '/bin/su';
46
push @su_args, '--preserve-environment' if $opts{'preserve-environment'};
47
push @su_args, '--login' if $opts{login};
48
push @su_args, '--command',
49
    "env "
50
  . "KOHA_CONF=/etc/koha/sites/$instance/koha-conf.xml "
51
  . "PERL5LIB=/usr/share/koha/lib $shell"
52
  . ( $opts{command} ? " -c '$opts{command}'" : '' );
53
push @su_args, "$instance-koha";
54
55
print "Command: '".join("' '",@su_args)."'\n" if $opts{verbose};
56
system(@su_args);
57
if ( $? == -1 ) {
58
    print STDERR "failed to execute: $!\n";
59
}
60
elsif ( $? & 127 ) {
61
    printf STDERR "child died with signal %d, %s coredump\n",
62
      ( $? & 127 ), ( $? & 128 ) ? 'with' : 'without';
63
}
64
65
sub show_help {
66
    my ( $err, $msg ) = @_;
67
68
    my $fh = $err ? *STDERR : *STDOUT;
69
    say $fh "Error: " . $msg if $msg;
70
    print $fh $_ while <DATA>;
71
}
72
73
__DATA__
74
koha-shell -- gives you a shell with your Koha environment set up
75
76
Usage: koha-shell [options] [instance name]
77
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
86
87
The default shell is the one currently in use. Refer to su(1) for more detail
88
on these options.

Return to bug 8878