#!/bin/bash
#
# Copyright 2015 Theke Solutions
# Copyright 2016 Koha-Suomi
# Copyright 2018 The National Library of Finland, University of Helsinki
#
# This file is part of Koha.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
set -e
. /lib/lsb/init-functions
# 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
usage()
{
local scriptname=$(basename $0)
cat < /dev/stderr
return 1
fi
local configdir=/etc/koha/sites/${instancename}/z3950
if [ -e ${configdir}/config.xml ]
then
[ "${quiet}" != "yes" ] && warn "Z39.50/SRU already enabled for $name"
return 1
fi
if [ ! -e ${configdir} ]
then
mkdir ${configdir}
fi
cp /etc/koha/z3950/* ${configdir}/
chown ${name}-koha:${name}-koha ${configdir}/*
chmod 600 ${configdir}/*
[ "${quiet}" != "yes" ] && warn "Z39.50/SRU enabled for $name - edit files in ${configdir} to configure"
return 0
}
disable_z3950()
{
local instancename=$1
if is_z3950_enabled $instancename; then
local configdir=/etc/koha/sites/${instancename}/z3950
mv ${configdir} ${configdir}.`date +%F_%T`
[ "${quiet}" != "yes" ] && warn "Z39.50/SRU disabled for ${instancename}"
return 0
else
[ "${quiet}" != "yes" ] && warn "Z39.50/SRU already disabled for ${instancename}"
return 1
fi
}
_check_and_fix_perms()
{
local instance=$1
local files="/var/log/koha/${instance}/z3950.log"
for file in ${files}
do
if [ ! -e "${file}" ]; then
touch ${file}
fi
chown "${instance}-koha":"${instance}-koha" ${file}
done
}
set_action()
{
if [ "$op" = "" ]; then
op=$1
else
die "Error: only one action can be specified."
fi
}
op=""
quiet="no"
debug_mode="no"
debugger_key=""
debugger_location="localhost:9000"
debugger_path=""
# Read command line parameters
while [ $# -gt 0 ]; do
case "$1" in
-h|--help)
usage ; exit 0 ;;
-q|--quiet)
quiet="yes"
shift ;;
--start)
set_action "start"
shift ;;
--stop)
set_action "stop"
shift ;;
--restart)
set_action "restart"
shift ;;
--enable)
set_action "enable"
shift ;;
--disable)
set_action "disable"
shift ;;
--debugger)
debug_mode="yes"
shift ;;
--debugger-key)
debugger_key="$2"
shift 2 ;;
--debugger-location)
debugger_location="$2"
shift 2 ;;
--debugger-path)
debugger_path="$2"
shift 2 ;;
-*)
die "Error: invalid option switch ($1)" ;;
*)
# We expect the remaining stuff are the instance names
break ;;
esac
done
if [ $# -gt 0 ]; then
# We have at least one instance name
for name in "$@"; do
if is_instance $name; then
adjust_paths_dev_install $name
export DEV_INSTALL
export KOHA_HOME
PERL5LIB=$PERL5LIB:$KOHA_HOME/installer:$KOHA_HOME/lib/installer
# If debug mode is enabled, add the debugger lib path
# to PERL5LIB if appropriate
if [ "$debug_mode" = "yes" ]; then
if [ "$debugger_path" != "" ]; then
PERL5LIB="${debugger_path}":$PERL5LIB
fi
export PERL5DB="BEGIN { require q(${debugger_path}/perl5db.pl) }"
export PERLDB_OPTS="RemotePort=${debugger_location} async=1 LogFile=/var/log/koha/${name}/z3950-debug.log"
export DBGP_IDEKEY=${debugger_key}
export PERL5OPT="-d"
fi
export PERL5LIB
case $op in
"start")
start_z3950 $name
;;
"stop")
stop_z3950 $name
;;
"restart")
restart_z3950 $name
;;
"enable")
enable_z3950 $name
;;
"disable")
disable_z3950 $name
;;
*)
usage
;;
esac
else
if [ "$quiet" = "no" ]; then
log_daemon_msg "Error: Invalid instance name $name"
log_end_msg 1
fi
fi
done
else
if [ "$quiet" = "no" ]; then
warn "Error: you must provide at least one instance name"
fi
fi
exit 0