Bug 10622: add --sip and --nosip switches to koha-list

Just added those switches.

Sponsored-by: Universidad Nacional de Cordoba
Signed-off-by: Magnus Enger <magnus@enger.priv.no>

I applied the patch on my local dev install, and then copied the
patched koha-list script to a couple of servers with actual
instances running off the packages, to test the script.
- It seems that the -h switch did not work before this patch, now
  both -h and --help works nicely
- --sip and --nosip work as expected, also in combination with
  --email and --noemail

The patch does not add --sip and --nosip to the man page for
koha-list, but I will do a followup for that.

Signed-off-by: Robin Sheat <robin@catalyst.net.nz>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
This commit is contained in:
Tomás Cohen Arazi 2013-07-22 11:30:27 -03:00 committed by Galen Charlton
parent 213fbdc5b4
commit 9f6e739ce0

View file

@ -49,6 +49,17 @@ is_email_enabled()
fi fi
} }
is_sip_enabled()
{
local instancename=$1
if [ -e /etc/koha/sites/$instancename/SIPconfig.xml ]; then
return 0
else
return 1
fi
}
get_instances() get_instances()
{ {
find /etc/koha/sites -mindepth 1 -maxdepth 1\ find /etc/koha/sites -mindepth 1 -maxdepth 1\
@ -59,40 +70,76 @@ show_instances()
{ {
local show=$1 local show=$1
local show_email=$2 local show_email=$2
local show_sip=$3
for instance in $( get_instances ); do for instance in $( get_instances ); do
case $show in case $show in
"all") "all")
show_instance_filter_email $instance $show_email;; if instance_filter_email $instance $show_email && \
instance_filter_sip $instance $show_sip; then
echo $instance
fi ;;
"enabled") "enabled")
if is_enabled $instance; then if is_enabled $instance; then
show_instance_filter_email $instance $show_email if instance_filter_email $instance $show_email && \
instance_filter_sip $instance $show_sip; then
echo $instance
fi
fi ;; fi ;;
"disabled") "disabled")
if ! is_enabled $instance; then if ! is_enabled $instance; then
show_instance_filter_email $instance $show_email if instance_filter_email $instance $show_email && \
instance_filter_sip $instance $show_sip; then
echo $instance
fi
fi ;; fi ;;
esac esac
done done
} }
show_instance_filter_email()
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 instancename=$1
local show_email=$2; local show_email=$2;
case $show_email in case $show_email in
"all") "all")
echo $instancename ;; return 0 ;;
"enabled") "enabled")
if is_email_enabled $instancename; then if is_email_enabled $instancename; then
echo $instancename return 0
fi ;; fi ;;
"disabled") "disabled")
if ! is_email_enabled $instancename; then if ! is_email_enabled $instancename; then
echo $instancename return 0
fi ;; fi ;;
esac esac
# Didn't match any criteria
return 1
} }
set_show() set_show()
@ -117,39 +164,55 @@ set_show_email()
fi 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() usage()
{ {
local scriptname=$0 local scriptname=$0
echo <<eoh cat <<EOH
Lists Koha instances, optionally only those that are enabled or have Lists Koha instances, optionally only those that are enabled or have
email turned on. email turned on.
Usage: $scriptname [--enabled|--disabled] [--email|--noemail] [-h] Usage: $scriptname [--enabled|--disabled] [--email|--noemail] [--sip|--nosip] [-h]
Options: Options:
--enabled only show instances that are enabled --enabled Only show instances that are enabled
--disabled only show instances that are disabled --disabled Only show instances that are disabled
--email only show instances that have email enabled --email Only show instances that have email enabled
--noemail only show instances that do not have email enabled --noemail Only show instances that do not have email enabled
-h this help --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 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.) (except --email and --noemail, or --enabled and --disabled, that's just silly.)
eoh EOH
} }
show="all" show="all"
show_email="all" show_email="all"
show_sip="all"
args=$(getopt -l enabled,disabled,email,noemail -o h -n $0 -- "$@") args=$(getopt -l help,enabled,disabled,email,noemail,sip,nosip -o h -n $0 -- "$@")
set -- $args set -- $args
while [ ! -z "$1" ] while [ ! -z "$1" ]
do do
case "$1" in case "$1" in
-h) usage; exit;; -h|--help) usage; exit;;
--email) set_show_email "enabled" ;; --email) set_show_email "enabled" ;;
--noemail) set_show_email "disabled" ;; --noemail) set_show_email "disabled" ;;
--sip) set_show_sip "enabled" ;;
--nosip) set_show_sip "disabled" ;;
--enabled) set_show "enabled" ;; --enabled) set_show "enabled" ;;
--disabled) set_show "disabled" ;; --disabled) set_show "disabled" ;;
*) break;; *) break;;
@ -157,6 +220,6 @@ do
shift shift
done done
show_instances $show $show_email show_instances $show $show_email $show_sip
exit 0 exit 0