Koha/debian/koha-common.postinst
Robin Sheat 2c5f927689 Bug 11404: (follow-up) only ask user if there are instances needing upgrading
There's no point asking the user if they want their Apache Koha
configuration updated if there's no configuration needing updated.

This also fixes a case where the updating would have failed when running
on Apache 2.4.

Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
I agree with adding that checks, and the conditions rewrite seems cleaner
than my first approach. So, I sign it.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
2014-05-19 21:51:33 +00:00

133 lines
4 KiB
Bash

#!/bin/sh
set -e
# Default to "yes"
AUTOMATIC_TRANSLATIONS_UPDATE="yes"
. /usr/share/debconf/confmodule
# Read configuration variable file if it is present
CONFIG=/etc/koha/koha-common.conf
if [ -r $CONFIG ]; then
. $CONFIG
fi
conf=/etc/mysql/koha-common.cnf
if [ ! -e "$conf" ] && [ ! -L "$conf" ]
then
ln -s debian.cnf "$conf"
fi
#DEBHELPER#
koha-upgrade-schema $(koha-list)
# Generate a config file if one doesn't exist already
if [ ! -e $CONFIG ]; then
cat <<EOF > $CONFIG
## Automatic template translation update
#
# This variable controls whether template translations should
# be updated automatically on koha-common package upgrades.
# Options: 'yes' (default)
# 'no'
# Note: if you choose 'no' then you will have to issue
# $ koha-translate --update <lang_code>
#
AUTOMATIC_TRANSLATIONS_UPDATE="yes"
EOF
fi
# Substitute the values from debconf into the file.
db_get koha-common/automatically-update-translations
UPDATE="$RET"
if [ "$UPDATE" = "false" ]; then
UPDATE="no"
else
UPDATE="yes"
fi
# In case they were removed/commented out, we add it in.
grep -Eq '^ *AUTOMATIC_TRANSLATIONS_UPDATE=' $CONFIG || \
echo "AUTOMATIC_TRANSLATIONS_UPDATE=" >> $CONFIG
sed -e "s/^ *AUTOMATIC_TRANSLATIONS_UPDATE=.*/AUTOMATIC_TRANSLATIONS_UPDATE=\"$UPDATE\"/" < $CONFIG > $CONFIG.tmp
mv -f $CONFIG.tmp $CONFIG
if [ "$AUTOMATIC_TRANSLATIONS_UPDATE" = "yes" ]; then
for lang in $(koha-translate --list | grep -v -x "en"); do
if koha-translate --update $lang; then
echo "Updated the $lang translations."
else
cat <<EOF >&2
ERROR: an error was found when updating '$lang' translations. Please manually
run 'koha-translate --update $lang'. Run man koha-translate for more options.
EOF
fi
done
else
# no auto-update, check update needed and warn if needed
if koha-translate --list | grep -v -q -x "en"; then
# translations installed, update needed
cat <<EOF >&2
Warning: template translations are not set to be automatically updated.
Please manually run 'koha-translate --update lang_code' to update them.
You can run 'koha-translate --list' to get a list of the installed translations codes.
EOF
fi
fi
# Check if we need to rename the Apache vhost files
RENAME_APACHE_FILES="no"
for vhost in $(koha-list); do
if [ -f "/etc/apache2/sites-available/$vhost" ] && \
[ ! -f "/etc/apache2/sites-available/$vhost.conf" ]; then
RENAME_APACHE_FILES="yes"
break # at least one, trigger renaming
fi
done
if [ "$RENAME_APACHE_FILES" = "yes" ]; then
# If the user agreed we now rename their Apache files
db_get koha-common/rename-apache-vhost-files
if [ "$RET" = "false" ]; then
# We're not renaming the files, just print a warning
cat <<EOF >&2
Warning: you have chosen not to migrate your Apache virtual hosts files to the
Apache 2.4 naming schema. You can do it manually by running this for each
Koha instance:
$ sudo a2dissite instance
$ sudo mv /etc/apache2/sites-available/instance \
/etc/apache2/sites-available/instance.conf
$ sudo a2ensite instance
EOF
else
# We have to rename the Apache files
for site in $(koha-list); do
ENABLE_VHOST="yes"
if [ -f "/etc/apache2/sites-available/$site" ] && \
[ ! -f "/etc/apache2/sites-available/$site.conf" ]; then
if [ ! -f "/etc/apache2/sites-enabled/$site" ]; then
ENABLE_VHOST="no"
fi
a2dissite $site > /dev/null 2>&1 || true
rm -f "/etc/apache2/sites-enabled/$site"
# Rename the vhost definition files
mv "/etc/apache2/sites-available/$site" \
"/etc/apache2/sites-available/$site.conf"
if [ "$ENABLE_VHOST" = "yes" ]; then
if ! a2ensite $site > /dev/null 2>&1; then
echo "Warning: problem enabling $site in Apache" >&2
fi
fi
fi
done
fi
fi
db_stop
exit 0