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, '/bin/su';
-push @su_args, '--preserve-environment' if $opts{'preserve-environment'};
+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, '--command',
+push @su_args, "-u", "$instance-koha";
+push @su_args,
"env "
. "KOHA_CONF=/etc/koha/sites/$instance/koha-conf.xml "
- . "PERL5LIB=/usr/share/koha/lib $shell"
+ . "PERL5LIB=$perl5lib $shell"
. ( $opts{command} ? " -c '$opts{command}'" : '' );
-push @su_args, "$instance-koha";
print "Command: '".join("' '",@su_args)."'\n" if $opts{verbose};
-system(@su_args);
+system("@su_args");
if ( $? == -1 ) {
print STDERR "failed to execute: $!\n";
}
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;
+ if ( $dev_install ) {
+ # pick PERL5LIB from the intranetdir entry
+ $result = `xmlstarlet sel -t -v "yazgfs/config/intranetdir" /etc/koha/sites/$instance/koha-conf.xml`;
+ }
+ return $result;
+}
+
__DATA__
koha-shell -- gives you a shell with your Koha environment set up