Bug 35492: Open holds tab by default on opac-user.pl after suspending a hold
[koha.git] / debian / scripts / koha-list
1 #!/bin/sh
2 #
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.
10
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.
15
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/>.
18
19
20 set -e
21
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
28 fi
29
30 show_instances()
31 {
32     for instance in $( get_instances ); do
33         case $show in
34           "all")
35               if filter_ok $instance; then
36                   echo $instance
37               fi ;;
38           "enabled")
39               if is_enabled $instance; then
40                   if filter_ok $instance; then
41                       echo $instance
42                   fi
43               fi ;;
44           "disabled")
45               if ! is_enabled $instance; then
46                   if filter_ok $instance; then
47                       echo $instance
48                   fi
49               fi ;;
50         esac
51     done
52 }
53
54 filter_ok()
55 {
56     local instance=$1
57
58     if instance_filter_email         $instance && \
59        instance_filter_elasticsearch $instance && \
60        instance_filter_letsencrypt   $instance && \
61        instance_filter_plack         $instance && \
62        instance_filter_z3950         $instance && \
63        instance_filter_sip           $instance; then
64         return 0;
65     else
66         return 1;
67     fi
68 }
69
70 instance_filter_sip()
71 {
72     local instance=$1
73
74     case $show_sip in
75         "all")
76             return 0 ;;
77         "enabled")
78             if is_sip_enabled $instance; then
79                 return 0
80             fi ;;
81         "disabled")
82             if ! is_sip_enabled $instance; then
83                 return 0
84             fi ;;
85     esac
86
87     # Didn't match any criteria
88     return 1
89 }
90
91 instance_filter_plack()
92 {
93     local instance=$1
94
95     case $show_plack in
96         "all")
97             return 0 ;;
98         "enabled")
99             if is_plack_enabled $instance; then
100                 return 0
101             fi ;;
102         "disabled")
103             if ! is_plack_enabled $instance; then
104                 return 0
105             fi ;;
106     esac
107
108     # Didn't match any criteria
109     return 1
110 }
111
112 instance_filter_letsencrypt()
113 {
114     local instance=$1
115
116     case $show_letsencrypt in
117         "all")
118             return 0 ;;
119         "enabled")
120             if is_letsencrypt_enabled $instance; then
121                 return 0
122             fi ;;
123         "disabled")
124             if ! is_letsencrypt_enabled $instance; then
125                 return 0
126             fi ;;
127     esac
128
129     # Didn't match any criteria
130     return 1
131 }
132
133 instance_filter_email()
134 {
135     local instance=$1
136
137     case $show_email in
138         "all")
139             return 0 ;;
140         "enabled")
141             if is_email_enabled $instance; then
142                 return 0
143             fi ;;
144         "disabled")
145             if ! is_email_enabled $instance; then
146                 return 0
147             fi ;;
148     esac
149
150     # Didn't match any criteria
151     return 1
152 }
153
154 instance_filter_z3950()
155 {
156     local instance=$1
157
158     case $show_z3950 in
159         "all")
160             return 0 ;;
161         "enabled")
162             if is_z3950_enabled $instance; then
163                 return 0
164             fi ;;
165         "disabled")
166             if ! is_z3950_enabled $instance; then
167                 return 0
168             fi ;;
169     esac
170
171     # Didn't match any criteria
172     return 1
173 }
174
175 instance_filter_elasticsearch()
176 {
177     local instance=$1
178
179     case $show_elasticsearch in
180         "all")
181             return 0 ;;
182         "enabled")
183             if is_elasticsearch_enabled $instance; then
184                 return 0
185             fi ;;
186         "disabled")
187             if ! is_elasticsearch_enabled $instance; then
188                 return 0
189             fi ;;
190     esac
191
192     # Didn't match any criteria
193     return 1
194 }
195
196 set_show()
197 {
198     local show_param=$1
199
200     if [ "$show" = "all" ]; then
201         show=$show_param
202     else
203         die "Error: --enabled and --disabled are mutually exclusive."
204     fi
205 }
206
207 set_show_elasticsearch()
208 {
209     local elasticsearch_param=$1
210
211     if [ "$show_elasticsearch" = "all" ]; then
212         show_elasticsearch=$elasticsearch_param
213     else
214         die "Error: --elasticsearch and --noelasticsearch are mutually exclusive."
215     fi
216 }
217
218 set_show_email()
219 {
220     local email_param=$1
221
222     if [ "$show_email" = "all" ]; then
223         show_email=$email_param
224     else
225         die "Error: --email and --noemail are mutually exclusive."
226     fi
227 }
228
229 set_show_letsencrypt()
230 {
231     local letsencrypt_param=$1
232
233     if [ "$show_letsencrypt" = "all" ]; then
234         show_letsencrypt=$letsencrypt_param
235     else
236         die "Error: --letsencrypt and --noletsencrypt are mutually exclusive."
237     fi
238 }
239
240 set_show_plack()
241 {
242     local plack_param=$1
243
244     if [ "$show_plack" = "all" ]; then
245         show_plack=$plack_param
246     else
247         die "Error: --plack and --noplack are mutually exclusive."
248     fi
249 }
250
251 set_show_sip()
252 {
253     local sip_param=$1
254
255     if [ "$show_sip" = "all" ]; then
256         show_sip=$sip_param
257     else
258         die "Error: --sip and --nosip are mutually exclusive."
259     fi
260 }
261
262 set_show_z3950()
263 {
264     local z3950_param=$1
265
266     if [ "$show_z3950" = "all" ]; then
267         show_z3950=$z3950_param
268     else
269         die "Error: --z3950 and --noz3950 are mutually exclusive."
270     fi
271 }
272
273 usage()
274 {
275     local scriptname=$0
276
277     cat <<EOH
278 Lists Koha instances, optionally only those that are enabled or have
279 email turned on.
280     
281 Usage: $scriptname [--enabled|--disabled] [--email|--noemail] [--sip|--nosip] [-h]
282 Options:
283     --enabled        Show enabled instances
284     --disabled       Show disabled instances
285     --elasticsearch  Show instances with Elasticsearch enabled
286     --noelasticsarch Show instances with Elasticsearch disabled
287     --email          Show instances with email enabled
288     --noemail        Show instances with email disabled
289     --sip            Show instances with SIP enabled
290     --nosip          Show instances with SIP disabled
291     --plack          Show instances with Plack enabled
292     --noplack        Show instances with Plack disabled
293     --letsencrypt    Show instances with letsencrypt enabled
294     --noletsencrypt  Show instances with letsencrypt disabled
295     --z3950          Show instances with Z39.50/SRU enabled
296     --noz3950        Show instances with Z39.50/SRU disabled
297     --help | -h      Show this help
298
299 The filtering options can be combined, and you probably want to do this
300 (except --email and --noemail, or --enabled and --disabled, that's just silly.)
301 EOH
302 }
303
304 show="all"
305 show_elasticsearch="all"
306 show_email="all"
307 show_sip="all"
308 show_plack="all"
309 show_letsencrypt="all"
310 show_z3950="all"
311
312 args=$(getopt -l help,enabled,disabled,elasticsearch,noelasticsearch,email,noemail,sip,nosip,plack,noplack,letsencrypt,noletsencrypt,z3950,noz3950 -o h -n $0 -- "$@")
313 set -- $args
314
315 while [ ! -z "$1" ]
316 do
317     case "$1" in
318         -h|--help) usage; exit;;
319           --email) set_show_email "enabled" ;;
320         --noemail) set_show_email "disabled" ;;
321             --sip) set_show_sip "enabled" ;;
322           --nosip) set_show_sip "disabled" ;;
323           --plack) set_show_plack "enabled" ;;
324         --noplack) set_show_plack "disabled" ;;
325     --letsencrypt) set_show_letsencrypt "enabled" ;;
326   --noletsencrypt) set_show_letsencrypt "disabled" ;;
327           --z3950) set_show_z3950 "enabled" ;;
328         --noz3950) set_show_z3950 "disabled" ;;
329   --elasticsearch) set_show_elasticsearch "enabled" ;;
330 --noelasticsearch) set_show_elasticsearch "disabled" ;;
331         --enabled) set_show "enabled" ;;
332        --disabled) set_show "disabled" ;;
333                 *) break;;
334     esac
335     shift
336 done
337
338 show_instances
339
340 exit 0