set -e
+# 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=$0
EOF
}
-die() {
- echo "$@" 1>&2
- exit 1
-}
-
# UPPER CASE VARIABLES - from configfile or default value
# lower case variables - generated within this script
generate_config_file() {
set -e
-
-die()
-{
- echo "$@" 1>&2
+# 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
-}
-
-warn()
-{
- echo "$@" 1>&2
-}
-
-is_enabled()
-{
- local instancename=$1
- local instancefile="/etc/apache2/sites-available/$instancename.conf"
-
- if ! is_instance $instancename; then
- return 1
- fi
-
- if grep -q '^[[:space:]]*Include /etc/koha/apache-shared-disable.conf' \
- "$instancefile" ; then
- return 1
- else
- return 0
- fi
-}
+fi
-is_instance()
+disable_instance()
{
- local instancename=$1
+ local site=$1
+ local instancefile=$(get_apache_config_for $site)
- if find /etc/koha/sites -mindepth 1 -maxdepth 1 \
- -type d -printf '%f\n'\
- | grep -q -x $instancename ; then
- return 0
- else
- return 1
+ if [ "$instancefile" = ""]; then
+ return 2
fi
-}
-
-disable_instance()
-{
- local instancename=$1
- local instancefile="/etc/apache2/sites-available/$instancename.conf"
if is_enabled $instancename; then
sed -i 's:^\s*#\(\s*Include /etc/koha/apache-shared-disable.conf\)$:\1:' \
for name in "$@"
do
if is_instance $name ; then
- if disable_instance $name; then
+ RET=$(disable_instance $name)
+ if [ "$RET" = 0 ]; then
restart_apache="yes"
+ elif [ "$RET" = 2 ]; then
+ warn "Error: Apache configuration file not present for instance $name."
else
- warn "Instance $name already disabled."
+ warn "Warning: instance $name already disabled."
fi
else
warn "Unknown instance $name."
set -e
+# 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
# Make sure the files we create are not accessible by anyone else.
umask 0077
-
-die() {
- echo "$@" 1>&2
- exit 1
-}
-
-
# Parse command line.
[ "$#" = 1 ] || die "Usage: $0 instancename"
name="$1"
set -e
-die()
-{
- echo "$@" 1>&2
+# 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
-}
-
-warn()
-{
- echo "$@" 1>&2
-}
-
-is_instance()
-{
- local instancename=$1
-
- if find /etc/koha/sites -mindepth 1 -maxdepth 1 \
- -type d -printf '%f\n'\
- | grep -q -x $instancename ; then
- return 0
- else
- return 1
- fi
-}
-
-is_email_enabled()
-{
- local instancename=$1
-
- if [ -e /var/lib/koha/$instancename/email.enabled ]; then
- return 0
- else
- return 1
- fi
-}
+fi
disable_email()
{
set -e
-die()
-{
- echo "$@" 1>&2
+# 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
-}
-
-warn()
-{
- echo "$@" 1>&2
-}
-
-is_instance()
-{
- local instancename=$1
-
- if find /etc/koha/sites -mindepth 1 -maxdepth 1 \
- -type d -printf '%f\n'\
- | grep -q -x $instancename ; then
- return 0
- else
- return 1
- fi
-}
-
-is_email_enabled()
-{
- local instancename=$1
-
- if [ -e /var/lib/koha/$instancename/email.enabled ]; then
- return 0
- else
- return 1
- fi
-}
+fi
enable_email()
{
set -e
-
-die()
-{
- echo "$@" 1>&2
+# 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
-}
-
-warn()
-{
- echo "$@" 1>&2
-}
-
-is_enabled()
-{
- local instancename=$1
- local instancefile="/etc/apache2/sites-available/$instancename.conf"
-
- if ! is_instance $instancename; then
- return 1
- fi
-
- if grep -q '^[[:space:]]*Include /etc/koha/apache-shared-disable.conf' \
- "$instancefile" ; then
- return 1
- else
- return 0
- fi
-}
-
-is_instance()
-{
- local instancename=$1
-
- if find /etc/koha/sites -mindepth 1 -maxdepth 1 \
- -type d -printf '%f\n'\
- | grep -q -x $instancename ; then
- return 0
- else
- return 1
- fi
-}
+fi
enable_instance()
{
--- /dev/null
+#!/bin/sh
+#
+# koha-functions.sh -- shared library of helper functions for koha-* scripts
+# Copyright 2014 - Tomas Cohen Arazi
+# Universidad Nacional de Cordoba
+#
+# 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 <http://www.gnu.org/licenses/>.
+
+
+die()
+{
+ echo "$@" 1>&2
+ exit 1
+}
+
+warn()
+{
+ echo "$@" 1>&2
+}
+
+get_apache_config_for()
+{
+ local site=$1
+ local sitefile="/etc/apache2/sites-available/$site"
+
+ if is_instance $site; then
+ if [ -f "$sitefile.conf" ]; then
+ echo "$sitefile.conf"
+ elif [ -f "$sitefile" ]; then
+ echo "$sitefile"
+ fi
+ fi
+}
+
+is_enabled()
+{
+ local site=$1
+ local instancefile=$(get_apache_config_for $site)
+
+ if [ "$instancefile" = "" ]; then
+ return 1
+ fi
+
+ if grep -q '^[[:space:]]*Include /etc/koha/apache-shared-disable.conf' \
+ "$instancefile" ; then
+ return 1
+ else
+ return 0
+ fi
+}
+
+is_instance()
+{
+ local instancename=$1
+
+ if find /etc/koha/sites -mindepth 1 -maxdepth 1 \
+ -type d -printf '%f\n'\
+ | grep -q -x "$instancename" ; then
+ return 0
+ else
+ return 1
+ fi
+}
+
+is_email_enabled()
+{
+ local instancename=$1
+
+ if [ -e /var/lib/koha/$instancename/email.enabled ]; then
+ return 0
+ else
+ return 1
+ fi
+}
+
+is_sip_enabled()
+{
+ local instancename=$1
+
+ if [ -e /etc/koha/sites/$instancename/SIPconfig.xml ]; then
+ return 0
+ else
+ return 1
+ fi
+}
+
+is_zebra_running()
+{
+ local instancename=$1
+
+ if daemon --name="$instancename-koha-zebra" \
+ --user="$instancename-koha.$instancename-koha" \
+ --running ; then
+ return 0
+ else
+ return 1
+ fi
+}
+
+get_instances()
+{
+ find /etc/koha/sites -mindepth 1 -maxdepth 1\
+ -type d -printf '%f\n' | sort
+}
set -e
-die()
-{
- echo "$@" 1>&2
+# 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
-}
-
-is_enabled()
-{
- local instancename=$1
- local instancefile="/etc/apache2/sites-available/$instancename.conf"
-
- if grep '^[[:space:]]*Include /etc/koha/apache-shared-disable.conf' \
- "$instancefile" > /dev/null
- then
- return 1
- else
- return 0
- fi
-}
-
-is_email_enabled()
-{
- local instancename=$1
-
- if [ -e /var/lib/koha/$instancename/email.enabled ]; then
- return 0
- else
- return 1
- fi
-}
-
-is_sip_enabled()
-{
- local instancename=$1
-
- if [ -e /etc/koha/sites/$instancename/SIPconfig.xml ]; then
- return 0
- else
- return 1
- fi
-}
-
-get_instances()
-{
- find /etc/koha/sites -mindepth 1 -maxdepth 1\
- -type d -printf '%f\n' | sort
-}
+fi
show_instances()
{
umask 0077
-die() {
- echo "$@" 1>&2
+# 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
[ "$#" = 1 ] || die "Usage: $0 instancename"
name="$1"
umask 0077
-die() {
- echo "$@" 1>&2
+# 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
# Parse command line.
if [ $# -lt 1 ]; then
set -e
-die()
-{
- echo "$@" 1>&2
+# 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
-}
-
-warn()
-{
- echo "$@" 1>&2
-}
-
-is_instance()
-{
- local instancename=$1
-
- if find /etc/koha/sites -mindepth 1 -maxdepth 1 \
- -type d -printf '%f\n'\
- | grep -q -x $instancename ; then
- return 0
- else
- return 1
- fi
-}
+fi
toggle_biblios_only()
{
set -e
+# 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
+
args=$(getopt -l keep-mysql -o k -n $0 -- "$@")
eval set -- $args
while [ ! -z "$1" ]
SITECONFDIR="/etc/koha/sites"
# There has to be a better way of excluding '.' from find. But this works.
-INSTANCES=`cd $SITECONFDIR && find . -type d -printf " %f" |sed s/\ .\ //`
+INSTANCES=$(get_instances)
if [ -z $NAMES ] ; then
echo "Please specify a Koha instance name. Your choices are:"
# If the daemon is not running already, we don't want to fail this loop. So bin the result code if this fails.
koha-stop-zebra $name || /bin/true
- instancefile="$name.conf"
+ instancefile=$(get_apache_config_for $name)
- [ -f "/etc/apache2/sites-available/$instancefile" ] && \
- rm "/etc/apache2/sites-available/$instancefile"
+ [ -f "$instancefile" ] && \
+ rm "$instancefile"
[ -f "/etc/koha/sites/$name/koha-conf.xml" ] && \
rm "/etc/koha/sites/$name/koha-conf.xml"
[ -f "/etc/koha/sites/$name/zebra-biblios.cfg" ] && \
set -e
-
-die() {
- echo "$@" 1>&2
+# 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
pwdigest() {
echo -n "$1" |
set -e
-die()
-{
- echo "$@" 1>&2
+# 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
-}
-
-warn()
-{
- echo "$@" 1>&2
-}
-
-is_enabled()
-{
- local instancename=$1
- local instancefile="/etc/apache2/sites-available/$instancename.conf"
-
- if ! is_instance $instancename; then
- return 1
- fi
-
- if grep -q '^[[:space:]]*Include /etc/koha/apache-shared-disable.conf' \
- "$instancefile" ; then
- return 1
- else
- return 0
- fi
-}
-
-is_instance()
-{
- local instancename=$1
-
- if find /etc/koha/sites -mindepth 1 -maxdepth 1 \
- -type d -printf '%f\n'\
- | grep -q -x $instancename ; then
- return 0
- else
- return 1
- fi
-}
-
-is_zebra_running()
-{
- local instancename=$1
-
- if daemon --name="$instancename-koha-zebra" \
- --user="$instancename-koha.$instancename-koha" \
- --running ; then
- return 0
- else
- return 1
- fi
-}
+fi
restart_zebra_instance()
{
set -e
-
-die() {
- echo "$@" 1>&2
+# 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
# Parse command line.
[ "$#" = 2 ] || die "Usage: $0 sqldump configdump"
set -e
-die()
-{
- echo "$@" 1>&2
+# 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
-}
-
-warn()
-{
- echo "$@" 1>&2
-}
-
-is_enabled()
-{
- local instancename=$1
- local instancefile="/etc/apache2/sites-available/$instancename.conf"
-
- if ! is_instance $instancename; then
- return 1
- fi
-
- if grep -q '^[[:space:]]*Include /etc/koha/apache-shared-disable.conf' \
- "$instancefile" ; then
- return 1
- else
- return 0
- fi
-}
-
-is_instance()
-{
- local instancename=$1
-
- if find /etc/koha/sites -mindepth 1 -maxdepth 1 \
- -type d -printf '%f\n'\
- | grep -q -x $instancename ; then
- return 0
- else
- return 1
- fi
-}
-
-is_zebra_running()
-{
- local instancename=$1
-
- if daemon --name="$instancename-koha-zebra" \
- --user="$instancename-koha.$instancename-koha" \
- --running ; then
- return 0
- else
- return 1
- fi
-}
+fi
start_zebra_instance()
{
local instancename=$1
- if is_enabled $instancename; then
- echo "Starting Zebra server for $instancename"
- touch "/var/log/koha/$instancename/zebra-error.log" \
- "/var/log/koha/$instancename/zebra.log" \
- "/var/log/koha/$instancename/zebra-output.log"
- chown "$instancename-koha:$instancename-koha" \
- "/var/log/koha/$instancename/zebra-error.log" \
- "/var/log/koha/$instancename/zebra.log" \
- "/var/log/koha/$instancename/zebra-output.log"
- daemon \
- --name="$instancename-koha-zebra" \
- --errlog="/var/log/koha/$instancename/zebra-error.log" \
- --stdout="/var/log/koha/$instancename/zebra.log" \
- --output="/var/log/koha/$instancename/zebra-output.log" \
- --verbose=1 \
- --respawn \
- --delay=30 \
- --user="$instancename-koha.$instancename-koha" \
- -- \
- zebrasrv \
- -v none,fatal,warn \
- -f "/etc/koha/sites/$instancename/koha-conf.xml" && \
- return 0
- else
+ echo "Starting Zebra server for $instancename"
+ touch "/var/log/koha/$instancename/zebra-error.log" \
+ "/var/log/koha/$instancename/zebra.log" \
+ "/var/log/koha/$instancename/zebra-output.log"
+ chown "$instancename-koha:$instancename-koha" \
+ "/var/log/koha/$instancename/zebra-error.log" \
+ "/var/log/koha/$instancename/zebra.log" \
+ "/var/log/koha/$instancename/zebra-output.log"
+ daemon \
+ --name="$instancename-koha-zebra" \
+ --errlog="/var/log/koha/$instancename/zebra-error.log" \
+ --stdout="/var/log/koha/$instancename/zebra.log" \
+ --output="/var/log/koha/$instancename/zebra-output.log" \
+ --verbose=1 \
+ --respawn \
+ --delay=30 \
+ --user="$instancename-koha.$instancename-koha" \
+ -- \
+ zebrasrv \
+ -v none,fatal,warn \
+ -f "/etc/koha/sites/$instancename/koha-conf.xml" && \
+ return 0 || \
return 1
- fi
}
usage()
set -e
-die()
-{
- echo "$@" 1>&2
+# 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
-}
-
-warn()
-{
- echo "$@" 1>&2
-}
-
-is_enabled()
-{
- local instancename=$1
- local instancefile="/etc/apache2/sites-available/$instancename.conf"
-
- if ! is_instance $instancename; then
- return 1
- fi
-
- if grep -q '^[[:space:]]*Include /etc/koha/apache-shared-disable.conf' \
- "$instancefile" ; then
- return 1
- else
- return 0
- fi
-}
-
-is_instance()
-{
- local instancename=$1
-
- if find /etc/koha/sites -mindepth 1 -maxdepth 1 \
- -type d -printf '%f\n'\
- | grep -q -x $instancename ; then
- return 0
- else
- return 1
- fi
-}
-
-is_zebra_running()
-{
- local instancename=$1
-
- if daemon --name="$instancename-koha-zebra" \
- --user="$instancename-koha.$instancename-koha" \
- --running ; then
- return 0
- else
- return 1
- fi
-}
+fi
stop_zebra_instance()
{
local instancename=$1
- if is_zebra_running $instancename; then
- echo "Stopping Zebra server for $instancename"
- daemon \
- --name="$instancename-koha-zebra" \
- --errlog="/var/log/koha/$instancename/zebra-error.log" \
- --stdout="/var/log/koha/$instancename/zebra.log" \
- --output="/var/log/koha/$instancename/zebra-output.log" \
- --verbose=1 \
- --respawn \
- --delay=30 \
- --user="$instancename-koha.$instancename-koha" \
- --stop \
- -- \
- zebrasrv \
- -v none,fatal,warn \
- -f "/etc/koha/sites/$instancename/koha-conf.xml" && \
- return 0
- else
+ echo "Stopping Zebra server for $instancename"
+ daemon \
+ --name="$instancename-koha-zebra" \
+ --errlog="/var/log/koha/$instancename/zebra-error.log" \
+ --stdout="/var/log/koha/$instancename/zebra.log" \
+ --output="/var/log/koha/$instancename/zebra-output.log" \
+ --verbose=1 \
+ --respawn \
+ --delay=30 \
+ --user="$instancename-koha.$instancename-koha" \
+ --stop \
+ -- \
+ zebrasrv \
+ -v none,fatal,warn \
+ -f "/etc/koha/sites/$instancename/koha-conf.xml" && \
+ return 0 || \
return 1
- fi
}
usage()
set -e
+# 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)
EOF
}
-die()
-{
- echo "$@" 1>&2
- exit 1
-}
-
list()
{
all=$1