Bug 14985: Fix regression on patron search
[koha.git] / debian / scripts / koha-list
blob73ce0754e7dd882a1d6ef9be467d77c578990a6a
1 #!/bin/sh
3 # koha-list -- List all Koha instances.
4 # Copyright 2010 Catalyst IT, Ltd
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 set -e
22 # include helper functions
23 if [ -f "/usr/share/koha/bin/koha-functions.sh" ]; then
24 . "/usr/share/koha/bin/koha-functions.sh"
25 else
26 echo "Error: /usr/share/koha/bin/koha-functions.sh not present." 1>&2
27 exit 1
30 show_instances()
32 local show=$1
33 local show_email=$2
34 local show_sip=$3
36 for instance in $( get_instances ); do
37 case $show in
38 "all")
39 if instance_filter_email $instance $show_email && \
40 instance_filter_plack $instance $show_plack && \
41 instance_filter_sip $instance $show_sip; then
42 echo $instance
43 fi ;;
44 "enabled")
45 if is_enabled $instance; then
46 if instance_filter_email $instance $show_email && \
47 instance_filter_plack $instance $show_plack && \
48 instance_filter_sip $instance $show_sip; then
49 echo $instance
51 fi ;;
52 "disabled")
53 if ! is_enabled $instance; then
54 if instance_filter_email $instance $show_email && \
55 instance_filter_plack $instance $show_plack && \
56 instance_filter_sip $instance $show_sip; then
57 echo $instance
59 fi ;;
60 esac
61 done
65 instance_filter_sip()
67 local instancename=$1
68 local show_sip=$2;
70 case $show_sip in
71 "all")
72 return 0 ;;
73 "enabled")
74 if is_sip_enabled $instancename; then
75 return 0
76 fi ;;
77 "disabled")
78 if ! is_sip_enabled $instancename; then
79 return 0
80 fi ;;
81 esac
83 # Didn't match any criteria
84 return 1
87 instance_filter_plack()
89 local instancename=$1
90 local show_plack=$2;
92 case $show_plack in
93 "all")
94 return 0 ;;
95 "enabled")
96 if is_plack_enabled $instancename; then
97 return 0
98 fi ;;
99 "disabled")
100 if ! is_plack_enabled $instancename; then
101 return 0
102 fi ;;
103 esac
105 # Didn't match any criteria
106 return 1
109 instance_filter_email()
111 local instancename=$1
112 local show_email=$2;
114 case $show_email in
115 "all")
116 return 0 ;;
117 "enabled")
118 if is_email_enabled $instancename; then
119 return 0
120 fi ;;
121 "disabled")
122 if ! is_email_enabled $instancename; then
123 return 0
124 fi ;;
125 esac
127 # Didn't match any criteria
128 return 1
131 set_show()
133 local show_param=$1
135 if [ "$show" = "all" ]; then
136 show=$show_param
137 else
138 die "Error: --enabled and --disabled are mutually exclusive."
142 set_show_email()
144 local email_param=$1
146 if [ "$show_email" = "all" ]; then
147 show_email=$email_param
148 else
149 die "Error: --email and --noemail are mutually exclusive."
153 set_show_plack()
155 local plack_param=$1
157 if [ "$show_plack" = "all" ]; then
158 show_plack=$plack_param
159 else
160 die "Error: --plack and --noplack are mutually exclusive."
164 set_show_sip()
166 local sip_param=$1
168 if [ "$show_sip" = "all" ]; then
169 show_sip=$sip_param
170 else
171 die "Error: --sip and --nosip are mutually exclusive."
175 usage()
177 local scriptname=$0
179 cat <<EOH
180 Lists Koha instances, optionally only those that are enabled or have
181 email turned on.
183 Usage: $scriptname [--enabled|--disabled] [--email|--noemail] [--sip|--nosip] [-h]
184 Options:
185 --enabled Show enabled instances
186 --disabled Show disabled instances
187 --email Show instances with email enabled
188 --noemail Show instances with email disabled
189 --sip Show instances with SIP enabled
190 --nosip Show instances with SIP disabled
191 --plack Show instances with Plack enabled
192 --noplack Show instances with Plack disabled
193 --help | -h Show this help
195 The filtering options can be combined, and you probably want to do this
196 (except --email and --noemail, or --enabled and --disabled, that's just silly.)
200 show="all"
201 show_email="all"
202 show_sip="all"
203 show_plack="all"
205 args=$(getopt -l help,enabled,disabled,email,noemail,sip,nosip,plack,noplack -o h -n $0 -- "$@")
206 set -- $args
208 while [ ! -z "$1" ]
210 case "$1" in
211 -h|--help) usage; exit;;
212 --email) set_show_email "enabled" ;;
213 --noemail) set_show_email "disabled" ;;
214 --sip) set_show_sip "enabled" ;;
215 --nosip) set_show_sip "disabled" ;;
216 --plack) set_show_plack "enabled" ;;
217 --noplack) set_show_plack "disabled" ;;
218 --enabled) set_show "enabled" ;;
219 --disabled) set_show "disabled" ;;
220 *) break;;
221 esac
222 shift
223 done
225 show_instances $show $show_email $show_sip
227 exit 0