Bug 16423: [QA Follow-up] Remove $opac
[koha.git] / debian / scripts / koha-functions.sh
blob1c309fc4d1c6e95b221ece73e3ebfc5337cbb50a
1 #!/bin/sh
3 # koha-functions.sh -- shared library of helper functions for koha-* scripts
4 # Copyright 2014 - Tomas Cohen Arazi
5 # Universidad Nacional de Cordoba
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 die()
23 echo "$@" 1>&2
24 exit 1
27 warn()
29 echo "$@" 1>&2
32 get_apache_config_for()
34 local site=$1
35 local sitefile="/etc/apache2/sites-available/$site"
37 if is_instance $site; then
38 if [ -f "$sitefile.conf" ]; then
39 echo "$sitefile.conf"
40 elif [ -f "$sitefile" ]; then
41 echo "$sitefile"
46 get_opacdomain_for()
48 local site=$1
50 if [ -e /etc/koha/koha-sites.conf ]; then
51 . /etc/koha/koha-sites.conf
52 else
53 echo "Error: /etc/koha/koha-sites.conf not present." 1>&2
54 exit 1
56 local opacdomain="$OPACPREFIX$site$OPACSUFFIX$DOMAIN"
57 echo "$opacdomain"
60 get_intradomain_for()
62 local site=$1
64 if [ -e /etc/koha/koha-sites.conf ]; then
65 . /etc/koha/koha-sites.conf
66 else
67 echo "Error: /etc/koha/koha-sites.conf not present." 1>&2
68 exit 1
70 local intradomain="$INTRAPREFIX$site$INTRASUFFIX$DOMAIN"
71 echo "$intradomain"
74 letsencrypt_get_opacdomain_for()
76 local site=$1
78 if [ -e /var/lib/koha/$site/letsencrypt.enabled ]; then
79 . /var/lib/koha/$site/letsencrypt.enabled
80 else
81 local opacdomain=$(get_opacdomain_for $site)
83 echo "$opacdomain"
86 is_enabled()
88 local site=$1
89 local instancefile=$(get_apache_config_for $site)
91 if [ "$instancefile" = "" ]; then
92 return 1
95 if grep -q '^[[:space:]]*Include /etc/koha/apache-shared-disable.conf' \
96 "$instancefile" ; then
97 return 1
98 else
99 return 0
103 is_instance()
105 local instancename=$1
107 if find /etc/koha/sites -mindepth 1 -maxdepth 1 \
108 -type d -printf '%f\n'\
109 | grep -q -x "$instancename" ; then
110 return 0
111 else
112 return 1
116 is_email_enabled()
118 local instancename=$1
120 if [ -e /var/lib/koha/$instancename/email.enabled ]; then
121 return 0
122 else
123 return 1
127 is_letsencrypt_enabled()
129 local instancename=$1
131 if [ -e /var/lib/koha/$instancename/letsencrypt.enabled ]; then
132 return 0
133 else
134 return 1
138 is_sip_enabled()
140 local instancename=$1
142 if [ -e /etc/koha/sites/$instancename/SIPconfig.xml ]; then
143 return 0
144 else
145 return 1
149 is_zebra_running()
151 local instancename=$1
153 if daemon --name="$instancename-koha-zebra" \
154 --pidfiles="/var/run/koha/$instancename/" \
155 --user="$instancename-koha.$instancename-koha" \
156 --running ; then
157 return 0
158 else
159 return 1
163 is_indexer_running()
165 local instancename=$1
167 if daemon --name="$instancename-koha-indexer" \
168 --pidfiles="/var/run/koha/$instancename/" \
169 --user="$instancename-koha.$instancename-koha" \
170 --running ; then
171 return 0
172 else
173 return 1
177 is_plack_enabled()
179 local site=$1
180 local instancefile=$(get_apache_config_for $site)
182 if [ "$instancefile" = "" ]; then
183 return 1
186 if grep -q '^[[:space:]]*Include /etc/koha/apache-shared-opac-plack.conf' \
187 "$instancefile" && \
188 grep -q '^[[:space:]]*Include /etc/koha/apache-shared-intranet-plack.conf' \
189 "$instancefile" ; then
190 return 0
191 else
192 return 1
196 is_plack_running()
198 local instancename=$1
200 if start-stop-daemon --pidfile "/var/run/koha/${instancename}/plack.pid" \
201 --status ; then
202 return 0
203 else
204 return 1
208 get_instances()
210 find /etc/koha/sites -mindepth 1 -maxdepth 1\
211 -type d -printf '%f\n' | sort
214 get_loglevels()
216 local instancename=$1
217 local retval=$(xmlstarlet sel -t -v 'yazgfs/config/zebra_loglevels' /etc/koha/sites/$instancename/koha-conf.xml)
218 if [ "$retval" != "" ]; then
219 echo "$retval"
220 else
221 echo "none,fatal,warn"