|
Lines 1-6
Link Here
|
| 1 |
#!/bin/sh |
1 |
#!/bin/sh |
| 2 |
# |
2 |
# |
| 3 |
# koha-instances -- List all Koha instances. |
3 |
# koha-list -- List all Koha instances. |
| 4 |
# Copyright 2010 Catalyst IT, Ltd |
4 |
# Copyright 2010 Catalyst IT, Ltd |
| 5 |
# |
5 |
# |
| 6 |
# This program is free software: you can redistribute it and/or modify |
6 |
# This program is free software: you can redistribute it and/or modify |
|
Lines 19-27
Link Here
|
| 19 |
|
19 |
|
| 20 |
set -e |
20 |
set -e |
| 21 |
|
21 |
|
| 22 |
is_enabled() { |
22 |
die() |
|
|
23 |
{ |
| 24 |
echo "$@" 1>&2 |
| 25 |
exit 1 |
| 26 |
} |
| 27 |
|
| 28 |
is_enabled() |
| 29 |
{ |
| 30 |
local instancename=$1 |
| 31 |
|
| 23 |
if grep '^[[:space:]]*Include /etc/koha/apache-shared-disable.conf' \ |
32 |
if grep '^[[:space:]]*Include /etc/koha/apache-shared-disable.conf' \ |
| 24 |
"/etc/apache2/sites-available/$name" > /dev/null |
33 |
"/etc/apache2/sites-available/$instancename" > /dev/null |
| 25 |
then |
34 |
then |
| 26 |
return 1 |
35 |
return 1 |
| 27 |
else |
36 |
else |
|
Lines 29-74
is_enabled() {
Link Here
|
| 29 |
fi |
38 |
fi |
| 30 |
} |
39 |
} |
| 31 |
|
40 |
|
| 32 |
help() { |
41 |
is_email_enabled() |
|
|
42 |
{ |
| 43 |
local instancename=$1 |
| 44 |
|
| 45 |
if [ -e /var/lib/koha/$instancename/email.enabled ]; then |
| 46 |
return 0 |
| 47 |
else |
| 48 |
return 1 |
| 49 |
fi |
| 50 |
} |
| 51 |
|
| 52 |
get_instances() |
| 53 |
{ |
| 54 |
find /etc/koha/sites -mindepth 1 -maxdepth 1\ |
| 55 |
-type d -printf '%f\n' | sort |
| 56 |
} |
| 57 |
|
| 58 |
show_instances() |
| 59 |
{ |
| 60 |
local show=$1 |
| 61 |
local show_email=$2 |
| 62 |
|
| 63 |
for instance in $( get_instances ); do |
| 64 |
case $show in |
| 65 |
"all") |
| 66 |
show_instance_filter_email $instance $show_email;; |
| 67 |
"enabled") |
| 68 |
if is_enabled $instance; then |
| 69 |
show_instance_filter_email $instance $show_email |
| 70 |
fi ;; |
| 71 |
"disabled") |
| 72 |
if ! is_enabled $instance; then |
| 73 |
show_instance_filter_email $instance $show_email |
| 74 |
fi ;; |
| 75 |
esac |
| 76 |
done |
| 77 |
} |
| 78 |
|
| 79 |
show_instance_filter_email() |
| 80 |
{ |
| 81 |
local instancename=$1 |
| 82 |
local show_email=$2; |
| 83 |
|
| 84 |
case $show_email in |
| 85 |
"all") |
| 86 |
echo $instancename ;; |
| 87 |
"enabled") |
| 88 |
if is_email_enabled $instancename; then |
| 89 |
echo $instancename |
| 90 |
fi ;; |
| 91 |
"disabled") |
| 92 |
if ! is_email_enabled $instancename; then |
| 93 |
echo $instancename |
| 94 |
fi ;; |
| 95 |
esac |
| 96 |
} |
| 97 |
|
| 98 |
set_show() |
| 99 |
{ |
| 100 |
local show_param=$1 |
| 101 |
|
| 102 |
if [ "$show" = "all" ]; then |
| 103 |
show=$show_param |
| 104 |
else |
| 105 |
die "Error: --enabled and --disabled are mutually exclusive." |
| 106 |
fi |
| 107 |
} |
| 108 |
|
| 109 |
set_show_email() |
| 110 |
{ |
| 111 |
local email_param=$1 |
| 112 |
|
| 113 |
if [ "$show_email" = "all" ]; then |
| 114 |
show_email=$email_param |
| 115 |
else |
| 116 |
die "Error: --email and --noemail are mutually exclusive." |
| 117 |
fi |
| 118 |
} |
| 119 |
|
| 120 |
usage() |
| 121 |
{ |
| 122 |
local scriptname=$0 |
| 123 |
|
| 33 |
echo <<eoh |
124 |
echo <<eoh |
| 34 |
Lists Koha instances, optionally only those that are enabled or have |
125 |
Lists Koha instances, optionally only those that are enabled or have |
| 35 |
email turned on. |
126 |
email turned on. |
| 36 |
|
127 |
|
| 37 |
Usage: $0 [--enabled] [--email] [-h] |
128 |
Usage: $scriptname [--enabled|--disabled] [--email|--noemail] [-h] |
| 38 |
Options: |
129 |
Options: |
| 39 |
--enabled only show instances that are enabled |
130 |
--enabled only show instances that are enabled |
|
|
131 |
--disabled only show instances that are disabled |
| 40 |
--email only show instances that have email enabled |
132 |
--email only show instances that have email enabled |
| 41 |
--noemail only show instances that do not have email enabled |
133 |
--noemail only show instances that do not have email enabled |
| 42 |
-h this help |
134 |
-h this help |
| 43 |
|
135 |
|
| 44 |
The filtering options can be combined, and you probably want to do this |
136 |
The filtering options can be combined, and you probably want to do this |
| 45 |
(except --email and --noemail, that's just silly.) |
137 |
(except --email and --noemail, or --enabled and --disabled, that's just silly.) |
| 46 |
eoh |
138 |
eoh |
| 47 |
} |
139 |
} |
| 48 |
|
140 |
|
| 49 |
enabled=no |
141 |
show="all" |
| 50 |
email=no |
142 |
show_email="all" |
| 51 |
noemail=no |
143 |
|
| 52 |
args=$(getopt -l enabled,email,noemail -o h -n $0 -- "$@") |
144 |
args=$(getopt -l enabled,disabled,email,noemail -o h -n $0 -- "$@") |
| 53 |
set -- $args |
145 |
set -- $args |
|
|
146 |
|
| 54 |
while [ ! -z "$1" ] |
147 |
while [ ! -z "$1" ] |
| 55 |
do |
148 |
do |
| 56 |
case "$1" in |
149 |
case "$1" in |
| 57 |
-h) help; exit;; |
150 |
-h) usage; exit;; |
| 58 |
--email) email=yes;; |
151 |
--email) set_show_email "enabled" ;; |
| 59 |
--enabled) enabled=yes;; |
152 |
--noemail) set_show_email "disabled" ;; |
| 60 |
--noemail) noemail=yes;; |
153 |
--enabled) set_show "enabled" ;; |
|
|
154 |
--disabled) set_show "disabled" ;; |
| 61 |
*) break;; |
155 |
*) break;; |
| 62 |
esac |
156 |
esac |
| 63 |
shift |
157 |
shift |
| 64 |
done |
158 |
done |
| 65 |
|
159 |
|
| 66 |
find /etc/koha/sites -mindepth 1 -maxdepth 1 -type d -printf '%f\n' | |
160 |
show_instances $show $show_email |
| 67 |
sort | |
161 |
|
| 68 |
while read name |
162 |
exit 0 |
| 69 |
do |
|
|
| 70 |
[ "$enabled" = yes ] && ! is_enabled "$name" && continue |
| 71 |
[ "$email" = yes ] && [ ! -e /var/lib/koha/$name/email.enabled ] && continue |
| 72 |
[ "$noemail" = yes ] && [ -e /var/lib/koha/$name/email.enabled ] && continue |
| 73 |
echo "$name" |
| 74 |
done |
| 75 |
- |
|
|