Koha/debian/scripts/koha-list
Tomas Cohen Arazi 92c7653071 Bug 11404: koha-functions.sh introduced for reuse
As asked by Robin, a bash lib of functions is introduced with the common
functions to be reused. Most of the scripts are modified (reduced) to
include this file and the repeated functions cleaned.

No noticeable change in behaviour should be noticed.

As I've been todl in #debian-mentors, it is used that files for inclusion
should be installed at the apps directory (i.e. /usr/share/koha/) so this
patch makes the install script put the file in the bin/ directory.

All koha-* scripts assume the file is there already (and fail otherwise).

Sponsored-by: Universidad Nacional de Cordoba
Signed-off-by: Robin Sheat <robin@catalyst.net.nz>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
2014-05-19 21:49:06 +00:00

186 lines
4.6 KiB
Bash
Executable file

#!/bin/sh
#
# koha-list -- List all Koha instances.
# Copyright 2010 Catalyst IT, Ltd
#
# 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/>.
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
show_instances()
{
local show=$1
local show_email=$2
local show_sip=$3
for instance in $( get_instances ); do
case $show in
"all")
if instance_filter_email $instance $show_email && \
instance_filter_sip $instance $show_sip; then
echo $instance
fi ;;
"enabled")
if is_enabled $instance; then
if instance_filter_email $instance $show_email && \
instance_filter_sip $instance $show_sip; then
echo $instance
fi
fi ;;
"disabled")
if ! is_enabled $instance; then
if instance_filter_email $instance $show_email && \
instance_filter_sip $instance $show_sip; then
echo $instance
fi
fi ;;
esac
done
}
instance_filter_sip()
{
local instancename=$1
local show_sip=$2;
case $show_sip in
"all")
return 0 ;;
"enabled")
if is_sip_enabled $instancename; then
return 0
fi ;;
"disabled")
if ! is_sip_enabled $instancename; then
return 0
fi ;;
esac
# Didn't match any criteria
return 1
}
instance_filter_email()
{
local instancename=$1
local show_email=$2;
case $show_email in
"all")
return 0 ;;
"enabled")
if is_email_enabled $instancename; then
return 0
fi ;;
"disabled")
if ! is_email_enabled $instancename; then
return 0
fi ;;
esac
# Didn't match any criteria
return 1
}
set_show()
{
local show_param=$1
if [ "$show" = "all" ]; then
show=$show_param
else
die "Error: --enabled and --disabled are mutually exclusive."
fi
}
set_show_email()
{
local email_param=$1
if [ "$show_email" = "all" ]; then
show_email=$email_param
else
die "Error: --email and --noemail are mutually exclusive."
fi
}
set_show_sip()
{
local sip_param=$1
if [ "$show_sip" = "all" ]; then
show_sip=$sip_param
else
die "Error: --sip and --nosip are mutually exclusive."
fi
}
usage()
{
local scriptname=$0
cat <<EOH
Lists Koha instances, optionally only those that are enabled or have
email turned on.
Usage: $scriptname [--enabled|--disabled] [--email|--noemail] [--sip|--nosip] [-h]
Options:
--enabled Only show instances that are enabled
--disabled Only show instances that are disabled
--email Only show instances that have email enabled
--noemail Only show instances that do not have email enabled
--sip Only show instances that have SIP enabled
--nosip Only show instances that do not have SIP enabled
--help | -h Show this help
The filtering options can be combined, and you probably want to do this
(except --email and --noemail, or --enabled and --disabled, that's just silly.)
EOH
}
show="all"
show_email="all"
show_sip="all"
args=$(getopt -l help,enabled,disabled,email,noemail,sip,nosip -o h -n $0 -- "$@")
set -- $args
while [ ! -z "$1" ]
do
case "$1" in
-h|--help) usage; exit;;
--email) set_show_email "enabled" ;;
--noemail) set_show_email "disabled" ;;
--sip) set_show_sip "enabled" ;;
--nosip) set_show_sip "disabled" ;;
--enabled) set_show "enabled" ;;
--disabled) set_show "disabled" ;;
*) break;;
esac
shift
done
show_instances $show $show_email $show_sip
exit 0