From 08ece513cd202a8d4bd26002b5e72746f971adeb Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Wed, 15 Jun 2016 14:08:28 +0200 Subject: [PATCH] Bug 16733: Adjust other debian scripts using PERL5LIB 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 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 Most scripts tested on Wheezy (although it would not matter much). Plack script tested on Jessie. Signed-off-by: Owen Leonard Signed-off-by: Jonathan Druart Signed-off-by: Kyle M Hall --- debian/scripts/koha-foreach | 17 +++++++++++++++-- debian/scripts/koha-plack | 23 +++++++++++++++++------ debian/scripts/koha-shell | 18 +++++++++++++++++- debian/scripts/koha-sitemap | 12 ++++++++++-- debian/scripts/koha-start-sip | 23 +++++++++++++++++++++-- debian/scripts/koha-stop-sip | 9 +-------- debian/scripts/koha-upgrade-schema | 25 ++++++++++++++++++++----- debian/templates/plack.psgi | 8 +++----- 8 files changed, 104 insertions(+), 31 deletions(-) diff --git a/debian/scripts/koha-foreach b/debian/scripts/koha-foreach index 7a3341d111..5262cc5218 100755 --- a/debian/scripts/koha-foreach +++ b/debian/scripts/koha-foreach @@ -15,9 +15,19 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . - 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>&- diff --git a/debian/scripts/koha-plack b/debian/scripts/koha-plack index ed0f42103d..9d0a6c5949 100755 --- a/debian/scripts/koha-plack +++ b/debian/scripts/koha-plack @@ -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 diff --git a/debian/scripts/koha-shell b/debian/scripts/koha-shell index b8d92f556d..0d747da8b0 100755 --- a/debian/scripts/koha-shell +++ b/debian/scripts/koha-shell @@ -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 ; } +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 diff --git a/debian/scripts/koha-sitemap b/debian/scripts/koha-sitemap index c42ab345a6..89b07e5e81 100755 --- a/debian/scripts/koha-sitemap +++ b/debian/scripts/koha-sitemap @@ -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 diff --git a/debian/scripts/koha-start-sip b/debian/scripts/koha-start-sip index 98a0ed612b..7f4f8182bd 100755 --- a/debian/scripts/koha-start-sip +++ b/debian/scripts/koha-start-sip @@ -18,6 +18,17 @@ 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 diff --git a/debian/scripts/koha-stop-sip b/debian/scripts/koha-stop-sip index b0cbbe9614..bfe7cd31c6 100755 --- a/debian/scripts/koha-stop-sip +++ b/debian/scripts/koha-stop-sip @@ -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 diff --git a/debian/scripts/koha-upgrade-schema b/debian/scripts/koha-upgrade-schema index e641c579b5..c1cc6cb989 100755 --- a/debian/scripts/koha-upgrade-schema +++ b/debian/scripts/koha-upgrade-schema @@ -16,16 +16,31 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . - 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 - diff --git a/debian/templates/plack.psgi b/debian/templates/plack.psgi index 235e56d844..1ed4acb93e 100644 --- a/debian/templates/plack.psgi +++ b/debian/templates/plack.psgi @@ -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 { -- 2.39.5