1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/roundcube_ynh.git synced 2024-09-03 20:16:28 +02:00
roundcube_ynh/scripts/upgrade

120 lines
3.7 KiB
Bash

#!/bin/bash
# Exit on command errors and treat unset variables as an error
set -eu
# Get multi-instances specific variables
app=$YNH_APP_INSTANCE_NAME
# Load common variables and helpers
. ./_common.sh
# Set app specific variables
dbname=$app
dbuser=$app
# Source app helpers
. /usr/share/yunohost/helpers
# Retrieve app settings
domain=$(ynh_app_setting_get "$app" domain)
path=$(ynh_app_setting_get "$app" path)
path=${path%/}
dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
with_carddav=$(ynh_app_setting_get "$app" with_carddav)
# Check destination directory
DESTDIR="/var/www/$app"
[[ ! -d $DESTDIR ]] && ynh_die \
"The destination directory '$DESTDIR' does not exist.\
The app is not correctly installed, you should remove it first."
# FIXME: jessie-backports is needed for php-net-ldap3
grep -q -R 'jessie-backports' /etc/apt/sources.list{,.d} || {
echo "deb http://httpredir.debian.org/debian jessie-backports main" \
| sudo tee -a /etc/apt/sources.list.d/backports.list >/dev/null
}
# Install dependencies
ynh_package_install_from_equivs ../conf/${DEPS_PKG_NAME}.control \
|| ynh_die "Unable to install dependencies"
# Create tmp directory and install app inside
TMPDIR=$(ynh_mkdir_tmp)
extract_roundcube "$TMPDIR"
# Install the new Roundcube version
sudo php "${TMPDIR}/bin/installto.sh" "$DESTDIR" --force --accept \
|| ynh_die "Unable to update Roundcube installation"
rm -rf "$TMPDIR"
# Generate a new random DES key
deskey=$(ynh_string_random 24)
# Copy and set Roundcube configuration
rc_conf="${DESTDIR}/config/config.inc.php"
sed -i "s/#DESKEY#/${deskey}/g" ../conf/config.inc.php
sed -i "s/#DBUSER#/${dbuser}/g" ../conf/config.inc.php
sed -i "s/#DBPASS#/${dbpass}/g" ../conf/config.inc.php
sed -i "s/#DBNAME#/${dbname}/g" ../conf/config.inc.php
sudo cp ../conf/config.inc.php "$rc_conf"
# Fix installation directories and permissions
sudo mkdir -p "${DESTDIR}/logs" "${DESTDIR}/temp"
sudo chown -R www-data: "$DESTDIR"
# Check if dependencies need to be updated with composer
if [[ -f ${DESTDIR}/composer.json ]]; then
exec_composer www-data "$DESTDIR" update --no-dev
else
init_composer "$DESTDIR" www-data
fi
# Install some plugins manually
sudo rm -rf "${DESTDIR}/plugins/ldapAliasSync"
sudo cp -r ../sources/plugins/ldapAliasSync "${DESTDIR}/plugins"
sudo chown -R www-data: "${DESTDIR}/plugins/ldapAliasSync"
installed_plugins=" 'ldapAliasSync',"
# Update or install additional plugins
exec_composer www-data "$DESTDIR" require \
"johndoh/contextmenu dev-release-2.1" \
"sblaisot/automatic_addressbook"
installed_plugins+=" 'contextmenu', 'automatic_addressbook',"
# Guess with_carddav value if empty
if [[ -z "${with_carddav:-}" ]]; then
[[ -f "${DESTDIR}/plugins/carddav/config.inc.php" ]] \
&& with_carddav=1 \
|| with_carddav=0
ynh_app_setting_set "$app" with_carddav "$with_carddav"
fi
# Update or instal CardDAV plugin
if [[ $with_carddav -eq 1 ]]; then
install_carddav "$DESTDIR" \
&& installed_plugins+=" 'carddav'," \
|| echo "Unable to install CardDAV plugin" >&2
fi
# Update Roundcube configuration
sudo sed -i "s#^\s*// installed plugins#&\n ${installed_plugins}#" \
"$rc_conf"
# Copy and set nginx configuration
nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf"
sed -i "s@#PATH#@${path:-/}@g" ../conf/nginx.conf
sed -i "s@#DESTDIR#@${DESTDIR}/@g" ../conf/nginx.conf
sudo cp ../conf/nginx.conf "$nginx_conf"
# Copy and set php-fpm configuration
phpfpm_conf="/etc/php5/fpm/pool.d/${app}.conf"
sed -i "s@#POOLNAME#@${app}@g" ../conf/php-fpm.conf
sed -i "s@#DESTDIR#@${DESTDIR}/@g" ../conf/php-fpm.conf
sudo cp ../conf/php-fpm.conf "$phpfpm_conf"
sudo chown root: $phpfpm_conf
sudo chmod 644 $phpfpm_conf
# Reload services
sudo service php5-fpm restart || true
sudo service nginx reload || true