Bug 18704 - File types limit in tools/export.pl is causing issues with csv files...
[koha.git] / debian / scripts / koha-list
blob0dd72e1a947a01dc348ffe030d693124f94a270b
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_letsencrypt $instance $show_letsencrypt && \
41 instance_filter_plack $instance $show_plack && \
42 instance_filter_sip $instance $show_sip; then
43 echo $instance
44 fi ;;
45 "enabled")
46 if is_enabled $instance; then
47 if instance_filter_email $instance $show_email && \
48 instance_filter_letsencrypt $instance $show_letsencrypt && \
49 instance_filter_plack $instance $show_plack && \
50 instance_filter_sip $instance $show_sip; then
51 echo $instance
53 fi ;;
54 "disabled")
55 if ! is_enabled $instance; then
56 if instance_filter_email $instance $show_email && \
57 instance_filter_letsencrypt $instance $show_letsencrypt && \
58 instance_filter_plack $instance $show_plack && \
59 instance_filter_sip $instance $show_sip; then
60 echo $instance
62 fi ;;
63 esac
64 done
68 instance_filter_sip()
70 local instancename=$1
71 local show_sip=$2;
73 case $show_sip in
74 "all")
75 return 0 ;;
76 "enabled")
77 if is_sip_enabled $instancename; then
78 return 0
79 fi ;;
80 "disabled")
81 if ! is_sip_enabled $instancename; then
82 return 0
83 fi ;;
84 esac
86 # Didn't match any criteria
87 return 1
90 instance_filter_plack()
92 local instancename=$1
93 local show_plack=$2;
95 case $show_plack in
96 "all")
97 return 0 ;;
98 "enabled")
99 if is_plack_enabled $instancename; then
100 return 0
101 fi ;;
102 "disabled")
103 if ! is_plack_enabled $instancename; then
104 return 0
105 fi ;;
106 esac
108 # Didn't match any criteria
109 return 1
112 instance_filter_letsencrypt()
114 local instancename=$1
115 local show_letsencrypt=$2;
117 case $show_letsencrypt in
118 "all")
119 return 0 ;;
120 "enabled")
121 if is_letsencrypt_enabled $instancename; then
122 return 0
123 fi ;;
124 "disabled")
125 if ! is_letsencrypt_enabled $instancename; then
126 return 0
127 fi ;;
128 esac
130 # Didn't match any criteria
131 return 1
134 instance_filter_email()
136 local instancename=$1
137 local show_email=$2;
139 case $show_email in
140 "all")
141 return 0 ;;
142 "enabled")
143 if is_email_enabled $instancename; then
144 return 0
145 fi ;;
146 "disabled")
147 if ! is_email_enabled $instancename; then
148 return 0
149 fi ;;
150 esac
152 # Didn't match any criteria
153 return 1
156 set_show()
158 local show_param=$1
160 if [ "$show" = "all" ]; then
161 show=$show_param
162 else
163 die "Error: --enabled and --disabled are mutually exclusive."
167 set_show_email()
169 local email_param=$1
171 if [ "$show_email" = "all" ]; then
172 show_email=$email_param
173 else
174 die "Error: --email and --noemail are mutually exclusive."
178 set_show_letsencrypt()
180 local letsencrypt_param=$1
182 if [ "$show_letsencrypt" = "all" ]; then
183 show_letsencrypt=$letsencrypt_param
184 else
185 die "Error: --letsencrypt and --noletsencrypt are mutually exclusive."
189 set_show_plack()
191 local plack_param=$1
193 if [ "$show_plack" = "all" ]; then
194 show_plack=$plack_param
195 else
196 die "Error: --plack and --noplack are mutually exclusive."
200 set_show_sip()
202 local sip_param=$1
204 if [ "$show_sip" = "all" ]; then
205 show_sip=$sip_param
206 else
207 die "Error: --sip and --nosip are mutually exclusive."
211 usage()
213 local scriptname=$0
215 cat <<EOH
216 Lists Koha instances, optionally only those that are enabled or have
217 email turned on.
219 Usage: $scriptname [--enabled|--disabled] [--email|--noemail] [--sip|--nosip] [-h]
220 Options:
221 --enabled Show enabled instances
222 --disabled Show disabled instances
223 --email Show instances with email enabled
224 --noemail Show instances with email disabled
225 --sip Show instances with SIP enabled
226 --nosip Show instances with SIP disabled
227 --plack Show instances with Plack enabled
228 --noplack Show instances with Plack disabled
229 --letsencrypt Show instances with letsencrypt enabled
230 --noletsencrypt Show instances with letsencrypt disabled
231 --help | -h Show this help
233 The filtering options can be combined, and you probably want to do this
234 (except --email and --noemail, or --enabled and --disabled, that's just silly.)
238 show="all"
239 show_email="all"
240 show_sip="all"
241 show_plack="all"
242 show_letsencrypt="all"
244 args=$(getopt -l help,enabled,disabled,email,noemail,sip,nosip,plack,noplack,letsencrypt,noletsencrypt -o h -n $0 -- "$@")
245 set -- $args
247 while [ ! -z "$1" ]
249 case "$1" in
250 -h|--help) usage; exit;;
251 --email) set_show_email "enabled" ;;
252 --noemail) set_show_email "disabled" ;;
253 --sip) set_show_sip "enabled" ;;
254 --nosip) set_show_sip "disabled" ;;
255 --plack) set_show_plack "enabled" ;;
256 --noplack) set_show_plack "disabled" ;;
257 --letsencrypt) set_show_letsencrypt "enabled" ;;
258 --noletsencrypt) set_show_letsencrypt "disabled" ;;
259 --enabled) set_show "enabled" ;;
260 --disabled) set_show "disabled" ;;
261 *) break;;
262 esac
263 shift
264 done
266 show_instances $show $show_email $show_sip
268 exit 0