Bug 26922: Regression tests
[koha.git] / debian / koha-common.postinst
blobf5ee256f16643a13a8dbca8d7dcaf9637d845ad7
1 #!/bin/sh
3 set -e
5 # Default to "yes"
6 AUTOMATIC_TRANSLATIONS_UPDATE="yes"
8 . /usr/share/debconf/confmodule
10 # Read configuration variable file if it is present
11 CONFIG=/etc/koha/koha-common.conf
12 if [ -r $CONFIG ]; then
13 . $CONFIG
16 conf=/etc/mysql/koha-common.cnf
17 if [ ! -e "$conf" ] && [ ! -L "$conf" ]
18 then
19 ln -s debian.cnf "$conf"
22 #DEBHELPER#
24 koha-upgrade-schema $(koha-list)
26 # Generate a config file if one doesn't exist already
27 if [ ! -e $CONFIG ]; then
28 cat <<EOF > $CONFIG
29 ## Automatic template translation update
31 # This variable controls whether template translations should
32 # be updated automatically on koha-common package upgrades.
33 # Options: 'yes' (default)
34 # 'no'
35 # Note: if you choose 'no' then you will have to issue
36 # $ koha-translate --update <lang_code>
38 AUTOMATIC_TRANSLATIONS_UPDATE="yes"
39 EOF
42 # Substitute the values from debconf into the file.
43 db_get koha-common/automatically-update-translations
44 UPDATE="$RET"
45 if [ "$UPDATE" = "false" ]; then
46 UPDATE="no"
47 else
48 UPDATE="yes"
50 # In case they were removed/commented out, we add it in.
51 grep -Eq '^ *AUTOMATIC_TRANSLATIONS_UPDATE=' $CONFIG || \
52 echo "AUTOMATIC_TRANSLATIONS_UPDATE=" >> $CONFIG
54 sed -e "s/^ *AUTOMATIC_TRANSLATIONS_UPDATE=.*/AUTOMATIC_TRANSLATIONS_UPDATE=\"$UPDATE\"/" < $CONFIG > $CONFIG.tmp
55 mv -f $CONFIG.tmp $CONFIG
57 if [ "$AUTOMATIC_TRANSLATIONS_UPDATE" = "yes" ]; then
58 for lang in $(koha-translate --list | grep -v -x "en"); do
59 if koha-translate --update $lang; then
60 echo "Updated the $lang translations."
61 else
62 cat <<EOF >&2
63 ERROR: an error was found when updating '$lang' translations. Please manually
64 run 'koha-translate --update $lang'. Run man koha-translate for more options.
65 EOF
67 done
68 else
69 # no auto-update, check update needed and warn if needed
70 if koha-translate --list | grep -v -q -x "en"; then
71 # translations installed, update needed
72 cat <<EOF >&2
73 Warning: template translations are not set to be automatically updated.
74 Please manually run 'koha-translate --update lang_code' to update them.
76 You can run 'koha-translate --list' to get a list of the installed translations codes.
77 EOF
81 # Check if we need to rename the Apache vhost files
82 RENAME_APACHE_FILES="no"
83 for vhost in $(koha-list); do
84 if [ -f "/etc/apache2/sites-available/$vhost" ] && \
85 [ ! -f "/etc/apache2/sites-available/$vhost.conf" ]; then
86 RENAME_APACHE_FILES="yes"
87 break # at least one, trigger renaming
89 done
91 if [ "$RENAME_APACHE_FILES" = "yes" ]; then
92 # If the user agreed we now rename their Apache files
93 db_get koha-common/rename-apache-vhost-files
94 if [ "$RET" = "false" ]; then
95 # We're not renaming the files, just print a warning
96 cat <<EOF >&2
97 Warning: you have chosen not to migrate your Apache virtual hosts files to the
98 Apache 2.4 naming schema. You can do it manually by running this for each
99 Koha instance:
101 $ sudo a2dissite instance
102 $ sudo mv /etc/apache2/sites-available/instance \
103 /etc/apache2/sites-available/instance.conf
104 $ sudo a2ensite instance
106 else
107 # We have to rename the Apache files
108 for site in $(koha-list); do
109 ENABLE_VHOST="yes"
110 if [ -f "/etc/apache2/sites-available/$site" ] && \
111 [ ! -f "/etc/apache2/sites-available/$site.conf" ]; then
112 if [ ! -f "/etc/apache2/sites-enabled/$site" ]; then
113 ENABLE_VHOST="no"
115 a2dissite $site > /dev/null 2>&1 || true
116 rm -f "/etc/apache2/sites-enabled/$site"
117 # Rename the vhost definition files
118 mv "/etc/apache2/sites-available/$site" \
119 "/etc/apache2/sites-available/$site.conf"
121 if [ "$ENABLE_VHOST" = "yes" ]; then
122 if ! {
123 a2ensite "$site" > /dev/null 2>&1 ||
124 a2ensite "${site}.conf" > /dev/null 2>&1
125 }; then
126 echo "Warning: problem enabling $site in Apache" >&2
130 done
134 log4perl_component()
136 local config=$1
137 local component=$2
139 if grep -q "log4perl.logger.$component" $config; then
140 return 0
141 else
142 return 1
146 # Take care of the instance's log4perl.conf file
147 for site in $(koha-list); do
148 log4perl_config="/etc/koha/sites/$site/log4perl.conf"
149 if ! log4perl_component $log4perl_config "z3950"; then
150 cat <<EOF >> $log4perl_config
151 log4perl.logger.z3950 = WARN, Z3950
152 log4perl.appender.Z3950=Log::Log4perl::Appender::File
153 log4perl.appender.Z3950.filename=/var/log/koha/$site/z3950-error.log
154 log4perl.appender.Z3950.mode=append
155 log4perl.appender.Z3950.layout=PatternLayout
156 log4perl.appender.Z3950.layout.ConversionPattern=[%d] [%p] %m %l %n
157 log4perl.appender.Z3950.utf8=1
162 if ! log4perl_component $log4perl_config "api"; then
163 cat <<EOF >> $log4perl_config
164 log4perl.logger.api = WARN, API
165 log4perl.appender.API=Log::Log4perl::Appender::File
166 log4perl.appender.API.filename=/var/log/koha/$site/api-error.log
167 log4perl.appender.API.mode=append
168 log4perl.appender.API.layout=PatternLayout
169 log4perl.appender.API.layout.ConversionPattern=[%d] [%p] %m %l %n
170 log4perl.appender.API.utf8=1
174 done
176 for site in $(koha-list); do
177 log4perl_config="/etc/koha/sites/$site/log4perl.conf"
178 if ! log4perl_component $log4perl_config "sip"; then
179 cat <<EOF >> $log4perl_config
180 log4perl.logger.sip = DEBUG, SIP
181 log4perl.appender.SIP=Log::Log4perl::Appender::File
182 log4perl.appender.SIP.filename=/var/log/koha/$site/sip.log
183 log4perl.appender.SIP.mode=append
184 log4perl.appender.SIP.layout=PatternLayout
185 log4perl.appender.SIP.layout.ConversionPattern=[%d] [%p] %m %l %n
186 log4perl.appender.SIP.utf8=1
190 done
192 for site in $(koha-list); do
193 log4perl_config="/etc/koha/sites/$site/log4perl.conf"
194 if ! log4perl_component $log4perl_config "plack-opac"; then
195 cat <<EOF >> $log4perl_config
196 log4perl.logger.plack-opac = WARN, PLACKOPAC
197 log4perl.appender.PLACKOPAC=Log::Log4perl::Appender::File
198 log4perl.appender.PLACKOPAC.filename=/var/log/koha/$site/plack-opac-error.log
199 log4perl.appender.PLACKOPAC.mode=append
200 log4perl.appender.PLACKOPAC.layout=PatternLayout
201 log4perl.appender.PLACKOPAC.layout.ConversionPattern=[%d] [%p] %m
202 log4perl.appender.PLACKOPAC.utf8=1
206 done
208 for site in $(koha-list); do
209 log4perl_config="/etc/koha/sites/$site/log4perl.conf"
210 if ! log4perl_component $log4perl_config "plack-api"; then
211 cat <<EOF >> $log4perl_config
212 log4perl.logger.plack-api = WARN, PLACKAPI
213 log4perl.appender.PLACKAPI=Log::Log4perl::Appender::File
214 log4perl.appender.PLACKAPI.filename=/var/log/koha/$site/plack-api-error.log
215 log4perl.appender.PLACKAPI.mode=append
216 log4perl.appender.PLACKAPI.layout=PatternLayout
217 log4perl.appender.PLACKAPI.layout.ConversionPattern=[%d] [%p] %m
218 log4perl.appender.PLACKAPI.utf8=1
222 done
224 for site in $(koha-list); do
225 log4perl_config="/etc/koha/sites/$site/log4perl.conf"
226 if ! log4perl_component $log4perl_config "plack-intranet"; then
227 cat <<EOF >> $log4perl_config
228 log4perl.logger.plack-intranet = WARN, PLACKINTRANET
229 log4perl.appender.PLACKINTRANET=Log::Log4perl::Appender::File
230 log4perl.appender.PLACKINTRANET.filename=/var/log/koha/$site/plack-intranet-error.log
231 log4perl.appender.PLACKINTRANET.mode=append
232 log4perl.appender.PLACKINTRANET.layout=PatternLayout
233 log4perl.appender.PLACKINTRANET.layout.ConversionPattern=[%d] [%p] %m
234 log4perl.appender.PLACKINTRANET.utf8=1
238 done
240 for site in $(koha-list); do
241 kohaconfig="/etc/koha/sites/$site/koha-conf.xml"
242 logdir="$( xmlstarlet sel -t -v 'yazgfs/config/logdir' $kohaconfig )"
243 if [ "$logdir" != "" ] && [ "$logdir" != "0" ]; then
244 chown -R $site-koha:$site-koha $logdir
245 else
246 chown -R $site-koha:$site-koha /var/log/koha/$site
248 done
250 # Bug 14106 - fix the modulePath of existing koha instances so that it'll
251 # continue to work. This will only patch the files if the exact original string
252 # that we're fixing them from is there, so we just run it every time. Maybe
253 # in many years time we can get rid of this, when no one will be running
254 # Koha < 3.20.
255 for zfile in $( find /etc/koha/sites -name zebra-authorities-dom.cfg -or -name zebra-biblios-dom.cfg ); do
256 perl -p -i -e 's{^modulePath: /usr/lib/idzebra-2.0/modules$}{modulePath: /usr/lib/idzebra-2.0/modules:/usr/lib/x86_64-linux-gnu/idzebra-2.0/modules:/usr/lib/i386-linux-gnu/idzebra-2.0/modules:/usr/lib/aarch64-linux-gnu/idzebra-2.0/modules:/usr/lib/arm-linux-gnueabi/idzebra-2.0/modules:/usr/lib/arm-linux-gnueabihf/idzebra-2.0/modules:/usr/lib/mips-linux-gnu/idzebra-2.0/modules:/usr/lib/mipsel-linux-gnu/idzebra-2.0/modules:/usr/lib/powerpc-linux-gnu/idzebra-2.0/modules:/usr/lib/powerpc64le-linux-gnu/idzebra-2.0/modules:/usr/lib/s390x-linux-gnu/idzebra-2.0/modules}' $zfile
257 done
259 db_stop
261 rabbitmq-plugins enable rabbitmq_stomp
262 service rabbitmq-server restart
264 # Bug 18250: Correct startup order of koha-common and memcached
265 # Since the init script has been updated, we can force the order in rc.d
266 # by disabling and enabling again.
267 update-rc.d koha-common disable
268 update-rc.d koha-common enable
270 exit 0