Bug 16733: Adjust other debian scripts using PERL5LIB
authorMarcel de Rooy <m.de.rooy@rijksmuseum.nl>
Wed, 15 Jun 2016 12:08:28 +0000 (14:08 +0200)
committerKatrin Fischer <katrin.fischer.83@web.de>
Tue, 16 May 2017 05:55:40 +0000 (07:55 +0200)
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: Katrin Fischer <katrin.fischer.83@web.de>

debian/scripts/koha-foreach
debian/scripts/koha-plack
debian/scripts/koha-shell
debian/scripts/koha-sitemap
debian/scripts/koha-start-sip
debian/scripts/koha-stop-sip
debian/scripts/koha-upgrade-schema
debian/templates/plack.psgi

index 7a3341d..5262cc5 100755 (executable)
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-
 set -e
 
+# Read configuration variable file if it is present
+[ -r /etc/default/koha-common ] && . /etc/default/koha-common
+
+# include helper functions
+if [ -f "/usr/share/koha/bin/koha-functions.sh" ]; then
+    . "/usr/share/koha/bin/koha-functions.sh"
+else
+    echo "Error: /usr/share/koha/bin/koha-functions.sh not present." 1>&2
+    exit 1
+fi
+
 listopts=""
 while [ ! -z "$1" ]
 do
@@ -39,11 +49,14 @@ done
             
 for name in $(koha-list $listopts)
 do
+    # Optionally use alternative paths for a dev install
+    adjust_paths_dev_install $name
+
     cmd=`echo "$@" | sed -e s/__instancename__/${name}/g`
     (
     exec 3>&1
     sudo -u "$name-koha" \
-    env PERL5LIB=/usr/share/koha/lib \
+    env PERL5LIB=$PERL5LIB \
         KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml" \
         ${cmd} 2>&1 >&3 | sed -e "s/^/$name: /" >&2 3>&-
     exec 3>&-
index 8e24db1..72e21f4 100755 (executable)
@@ -231,6 +231,22 @@ set_action()
     fi
 }
 
+adjust_paths()
+{
+    # Optionally use alternative paths for a dev install
+    adjust_paths_dev_install $1
+
+    # PERL5LIB has been read from etc/default, add lib/installer
+    # export some vars (for plack.psgi)
+    export KOHA_HOME
+    if [ "$DEV_INSTALL" = "" ]; then
+        export PERL5LIB=$PERL5LIB:$KOHA_HOME/lib/installer
+    else
+        export DEV_INSTALL
+        export PERL5LIB=$PERL5LIB:$KOHA_HOME/installer
+    fi
+}
+
 STARMAN=$(which starman)
 op=""
 quiet="no"
@@ -268,12 +284,6 @@ while [ $# -gt 0 ]; do
 
 done
 
-if [ -z $PERL5LIB ]; then
-    PERL5LIB="/usr/share/koha/lib"
-fi
-
-export PERL5LIB
-
 [ "${quiet}" != "yes" ] && check_env_and_warn
 
 if [ $# -gt 0 ]; then
@@ -282,6 +292,7 @@ if [ $# -gt 0 ]; then
 
         if is_instance $name; then
 
+            adjust_paths $name
             case $op in
                 "start")
                     start_plack $name
index b8d92f5..0d747da 100755 (executable)
@@ -41,6 +41,7 @@ if ( !-e "/etc/koha/sites/$instance" ) {
 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'};
@@ -49,7 +50,7 @@ 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}'" : '' );
 
 print "Command: '".join("' '",@su_args)."'\n" if $opts{verbose};
@@ -70,6 +71,21 @@ sub show_help {
     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
 
index c42ab34..89b07e5 100755 (executable)
@@ -108,9 +108,9 @@ generate_sitemap()
         fi
 
         if sudo -u "$instance-koha" -H \
-            env PERL5LIB=/usr/share/koha/lib \
+            env PERL5LIB=$PERL5LIB \
             KOHA_CONF="/etc/koha/sites/$instance/koha-conf.xml" \
-            /usr/share/koha/bin/cronjobs/sitemap.pl \
+            $KOHA_BINDIR/cronjobs/sitemap.pl \
                 --dir $sitemapdir ; then
             return 0
         else
@@ -171,6 +171,14 @@ while [ $# -gt 0 ]; do
 
 done
 
+# Optionally use alternative paths for a dev install
+adjust_paths_dev_install $1
+if [ "$DEV_INSTALL" = "" ]; then
+    KOHA_BINDIR=$KOHA_HOME/bin
+else
+    KOHA_BINDIR=$KOHA_HOME/misc
+fi
+
 if [ $# -gt 0 ]; then
     # We have at least one instance name
     for name in "$@"; do
index 98a0ed6..7f4f818 100755 (executable)
 
 set -e
 
+# Read configuration variable file if it is present
+[ -r /etc/default/koha-common ] && . /etc/default/koha-common
+
+# include helper functions
+if [ -f "/usr/share/koha/bin/koha-functions.sh" ]; then
+    . "/usr/share/koha/bin/koha-functions.sh"
+else
+    echo "Error: /usr/share/koha/bin/koha-functions.sh not present." 1>&2
+    exit 1
+fi
+
 for name in "$@"
 do
     if [ ! -e /etc/koha/sites/${name}/koha-conf.xml ] ;
@@ -29,9 +40,17 @@ do
     echo "Starting SIP server for $name"
     mkdir -p /var/run/koha/${name}
     chown "${name}-koha:${name}-koha" /var/run/koha/${name}
+
+    adjust_paths_dev_install $name
     export KOHA_CONF PERL5LIB
     KOHA_CONF=/etc/koha/sites/${name}/koha-conf.xml
-    PERL5LIB="/usr/share/koha/lib"
+    # PERL5LIB has been read already
+    if [ "$DEV_INSTALL" = "" ]; then
+        LIBDIR=$KOHA_HOME/lib
+    else
+        LIBDIR=$KOHA_HOME
+    fi
+
     daemon \
         --name="$name-koha-sip" \
         --errlog="/var/log/koha/$name/sip-error.log" \
@@ -44,6 +63,6 @@ do
         --user="$name-koha.$name-koha" \
         -- \
         perl \
-        "/usr/share/koha/lib/C4/SIP/SIPServer.pm" \
+        "$LIBDIR/C4/SIP/SIPServer.pm" \
         "/etc/koha/sites/${name}/SIPconfig.xml"
 done
index b0cbbe9..bfe7cd3 100755 (executable)
@@ -31,9 +31,6 @@ do
         continue;
     fi
     echo "Stopping SIP server for $name"
-    KOHA_CONF=/etc/koha/sites/${name}/koha-conf.xml
-    PERL5LIB=/usr/share/koha/lib
-    export KOHA_CONF PERL5LIB
     daemon \
         --name="$name-koha-sip" \
         --errlog="/var/log/koha/$name/sip-error.log" \
@@ -44,9 +41,5 @@ do
         --delay=30 \
         --pidfiles="/var/run/koha/${name}" \
         --user="$name-koha.$name-koha" \
-        --stop \
-        -- \
-        perl \
-        "/usr/share/koha/lib/C4/SIP/SIPServer.pm" \
-        "/etc/koha/sites/${name}/SIPconfig.xml"
+        --stop
 done
index e641c57..c1cc6cb 100755 (executable)
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-
 set -e
 
+# Read configuration variable file if it is present
+[ -r /etc/default/koha-common ] && . /etc/default/koha-common
+
+# include helper functions
+if [ -f "/usr/share/koha/bin/koha-functions.sh" ]; then
+    . "/usr/share/koha/bin/koha-functions.sh"
+else
+    echo "Error: /usr/share/koha/bin/koha-functions.sh not present." 1>&2
+    exit 1
+fi
+
+# Optionally use alternative paths for a dev install
+adjust_paths_dev_install $1
+if [ "$DEV_INSTALL" = "" ]; then
+    CGI_PATH=$KOHA_HOME/intranet/cgi-bin
+else
+    CGI_PATH=$KOHA_HOME
+fi
 
-update="/usr/share/koha/intranet/cgi-bin/installer/data/mysql/updatedatabase.pl"
 for name in "$@"
 do
     echo "Upgrading database schema for $name"
     KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml" \
-    PERL5LIB="/usr/share/koha/lib" \
-    "$update"
+    PERL5LIB=$PERL5LIB \
+    "$CGI_PATH/installer/data/mysql/updatedatabase.pl"
 done
-
index 235e56d..1ed4acb 100644 (file)
@@ -17,9 +17,6 @@
 
 use Modern::Perl;
 
-use lib("/usr/share/koha/lib");
-use lib("/usr/share/koha/lib/installer");
-
 use Plack::Builder;
 use Plack::App::CGIBin;
 use Plack::App::Directory;
@@ -53,12 +50,13 @@ use CGI qw(-utf8 ); # we will loose -utf8 under plack, otherwise
     };
 }
 
+my $home = $ENV{KOHA_HOME};
 my $intranet = Plack::App::CGIBin->new(
-    root => '/usr/share/koha/intranet/cgi-bin'
+    root => $ENV{DEV_INSTALL}? $home: "$home/intranet/cgi-bin"
 )->to_app;
 
 my $opac = Plack::App::CGIBin->new(
-    root => '/usr/share/koha/opac/cgi-bin/opac'
+    root => $ENV{DEV_INSTALL}? "$home/opac": "$home/opac/cgi-bin/opac"
 )->to_app;
 
 my $apiv1  = builder {