From f638f5aa1bbc7c28b960c1863cbe8c863d2f4181 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 23 Apr 2013 10:14:37 -0300 Subject: [PATCH] Bug 10094 - koha-list should have a --disabled option switch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch adds that (--disabled) option switch, Also revisits some of the code and docs. To test: - Apply the patch and create new packages (you might just drop the koha-list command somewhere) - Create several instances (koha-create) - Randomly set some as disabled, others enabled and enable email on some. - Test all possible option switches combinations Expected results: - koha-list should abort with a proper message if mutually exclusive options selected (--email vs. --noemail, --enabled vs. --disabled) - koha-list should show the exact instances you asked for Regards To+ P.S.: I wanted to add the --disabled option switch for the tab-completion work I'm doing, but as of bug 4876 I thought it would be ok to revisit the script to make it robust and clear. Sponsored-by: Universidad Nacional de Córdoba --- debian/docs/koha-list.xml | 10 ++- debian/scripts/koha-list | 148 ++++++++++++++++++++++++++++++++++++++------- 2 files changed, 133 insertions(+), 25 deletions(-) diff --git a/debian/docs/koha-list.xml b/debian/docs/koha-list.xml index c67096d..b58847e 100644 --- a/debian/docs/koha-list.xml +++ b/debian/docs/koha-list.xml @@ -23,12 +23,12 @@ - koha-list + koha-list | | Options - The filtering options can be combined, and you probably want to do this (except --email and --noemail, that's just silly.) + 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.) @@ -37,6 +37,12 @@ + + + Only show instances that are disabled. + + + Only show instances that have email enabled. diff --git a/debian/scripts/koha-list b/debian/scripts/koha-list index 1e19f1a..2dbf115 100755 --- a/debian/scripts/koha-list +++ b/debian/scripts/koha-list @@ -1,6 +1,6 @@ #!/bin/sh # -# koha-instances -- List all Koha instances. +# koha-list -- List all Koha instances. # Copyright 2010 Catalyst IT, Ltd # # This program is free software: you can redistribute it and/or modify @@ -19,9 +19,18 @@ set -e -is_enabled() { +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/$name" > /dev/null + "/etc/apache2/sites-available/$instancename" > /dev/null then return 1 else @@ -29,46 +38,139 @@ is_enabled() { fi } -help() { +is_created() +{ + local instancename=$1 + + if find /etc/koha/sites -mindepth 1 -maxdepth 1 \ + -type d -printf '%f\n'\ + | grep -q $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 +} + +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 + + for instance in $( get_instances ); do + case $show in + "all") + show_instance_filter_email $instance $show_email;; + "enabled") + if is_enabled $instance; then + show_instance_filter_email $instance $show_email + fi ;; + "disabled") + if ! is_enabled $instance; then + show_instance_filter_email $instance $show_email + fi ;; + esac + done +} + +show_instance_filter_email() +{ + local instancename=$1 + local show_email=$2; + + case $show_email in + "all") + echo $instancename ;; + "enabled") + if is_email_enabled $instancename; then + echo $instancename + fi ;; + "disabled") + if ! is_email_enabled $instancename; then + echo $instancename + fi ;; + esac +} + +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 +} + +usage() +{ + local scriptname=$0 + echo <