Bug 12869 - update the version in build-git-snapshot
[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     local show=$1
33     local show_email=$2
34     local show_sip=$3
35
36     for instance in $( get_instances ); do
37         case $show in
38           "all")
39               if instance_filter_email $instance $show_email && \
40                  instance_filter_sip $instance $show_sip; then
41                     echo $instance
42               fi ;;
43           "enabled")
44               if is_enabled $instance; then
45                   if instance_filter_email $instance $show_email && \
46                      instance_filter_sip $instance $show_sip; then
47                       echo $instance
48                   fi
49               fi ;;
50           "disabled")
51               if ! is_enabled $instance; then
52                   if instance_filter_email $instance $show_email && \
53                      instance_filter_sip $instance $show_sip; then
54                       echo $instance
55                   fi
56               fi ;;
57         esac
58     done
59 }
60
61
62 instance_filter_sip()
63 {
64     local instancename=$1
65     local show_sip=$2;
66
67     case $show_sip in
68         "all")
69             return 0 ;;
70         "enabled")
71             if is_sip_enabled $instancename; then
72                 return 0
73             fi ;;
74         "disabled")
75             if ! is_sip_enabled $instancename; then
76                 return 0
77             fi ;;
78     esac
79
80     # Didn't match any criteria
81     return 1
82 }
83
84 instance_filter_email()
85 {
86     local instancename=$1
87     local show_email=$2;
88
89     case $show_email in
90         "all")
91             return 0 ;;
92         "enabled")
93             if is_email_enabled $instancename; then
94                 return 0
95             fi ;;
96         "disabled")
97             if ! is_email_enabled $instancename; then
98                 return 0
99             fi ;;
100     esac
101
102     # Didn't match any criteria
103     return 1
104 }
105
106 set_show()
107 {
108     local show_param=$1
109
110     if [ "$show" = "all" ]; then
111         show=$show_param
112     else
113         die "Error: --enabled and --disabled are mutually exclusive."
114     fi
115 }
116
117 set_show_email()
118 {
119     local email_param=$1
120
121     if [ "$show_email" = "all" ]; then
122         show_email=$email_param
123     else
124         die "Error: --email and --noemail are mutually exclusive."
125     fi
126 }
127
128 set_show_sip()
129 {
130     local sip_param=$1
131
132     if [ "$show_sip" = "all" ]; then
133         show_sip=$sip_param
134     else
135         die "Error: --sip and --nosip are mutually exclusive."
136     fi
137 }
138
139 usage()
140 {
141     local scriptname=$0
142
143     cat <<EOH
144 Lists Koha instances, optionally only those that are enabled or have
145 email turned on.
146     
147 Usage: $scriptname [--enabled|--disabled] [--email|--noemail] [--sip|--nosip] [-h]
148 Options:
149     --enabled       Only show instances that are enabled
150     --disabled      Only show instances that are disabled
151     --email         Only show instances that have email enabled
152     --noemail       Only show instances that do not have email enabled
153     --sip           Only show instances that have SIP enabled
154     --nosip         Only show instances that do not have SIP enabled
155     --help | -h     Show this help
156
157 The filtering options can be combined, and you probably want to do this
158 (except --email and --noemail, or --enabled and --disabled, that's just silly.)
159 EOH
160 }
161
162 show="all"
163 show_email="all"
164 show_sip="all"
165
166 args=$(getopt -l help,enabled,disabled,email,noemail,sip,nosip -o h -n $0 -- "$@")
167 set -- $args
168
169 while [ ! -z "$1" ]
170 do
171     case "$1" in
172   -h|--help) usage; exit;;
173     --email) set_show_email "enabled" ;;
174   --noemail) set_show_email "disabled" ;;
175       --sip) set_show_sip "enabled" ;;
176     --nosip) set_show_sip "disabled" ;;
177   --enabled) set_show "enabled" ;;
178  --disabled) set_show "disabled" ;;
179           *) break;;
180     esac
181     shift
182 done
183
184 show_instances $show $show_email $show_sip
185
186 exit 0