#!/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 . set -e die() { echo "$@" 1>&2 exit 1 } is_enabled() { local instancename=$1 if grep '^[[:space:]]*Include /etc/koha/apache-shared-disable.conf' \ "/etc/apache2/sites-available/$instancename" > /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 } 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 <