2016-03-28 22:14:19 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2016-05-15 17:26:39 +02:00
|
|
|
# Exit on command errors and treat unset variables as an error
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
# Get multi-instances specific variables
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
2016-03-28 22:14:19 +02:00
|
|
|
|
|
|
|
# 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
|
2016-05-15 17:26:39 +02:00
|
|
|
domain=$(ynh_app_setting_get "$app" domain)
|
|
|
|
path=$(ynh_app_setting_get "$app" path)
|
2016-05-01 16:41:29 +02:00
|
|
|
path=${path%/}
|
2016-05-15 17:26:39 +02:00
|
|
|
dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
|
2016-05-15 23:51:33 +02:00
|
|
|
with_carddav=$(ynh_app_setting_get "$app" with_carddav)
|
2016-03-28 22:14:19 +02:00
|
|
|
|
|
|
|
# Check destination directory
|
|
|
|
DESTDIR="/var/www/$app"
|
2016-05-15 17:26:39 +02:00
|
|
|
[[ ! -d $DESTDIR ]] && ynh_die \
|
2016-03-28 22:14:19 +02:00
|
|
|
"The destination directory '$DESTDIR' does not exist.\
|
|
|
|
The app is not correctly installed, you should remove it first."
|
|
|
|
|
|
|
|
# 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 \
|
2016-05-15 17:26:39 +02:00
|
|
|
|| ynh_die "Unable to update Roundcube installation"
|
2016-03-28 22:14:19 +02:00
|
|
|
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
|
|
|
|
# TODO: update new Roundcube dependencies versions
|
|
|
|
exec_composer www-data "$DESTDIR" update --no-dev
|
|
|
|
else
|
2016-03-30 16:01:05 +02:00
|
|
|
init_composer "$DESTDIR" www-data
|
2016-03-28 22:14:19 +02:00
|
|
|
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"
|
2016-03-30 14:38:37 +02:00
|
|
|
installed_plugins=" 'ldapAliasSync',"
|
2016-03-28 22:14:19 +02:00
|
|
|
|
|
|
|
# Update or install additional plugins
|
2016-05-01 12:11:44 +02:00
|
|
|
exec_composer www-data "$DESTDIR" require \
|
|
|
|
"johndoh/contextmenu dev-release-2.1" \
|
|
|
|
"sblaisot/automatic_addressbook"
|
2016-03-30 14:38:37 +02:00
|
|
|
installed_plugins+=" 'contextmenu', 'automatic_addressbook',"
|
|
|
|
|
2016-05-15 23:51:33 +02:00
|
|
|
# Guess with_carddav value if empty
|
|
|
|
if [[ -z "${with_carddav:-}" ]]; then
|
|
|
|
[[ -d "${DESTDIR}/plugins/carddav" ]] \
|
|
|
|
&& 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
|
|
|
|
|
2016-03-30 14:38:37 +02:00
|
|
|
# Update Roundcube configuration
|
2016-04-27 14:38:35 +02:00
|
|
|
sudo sed -i "s#^\s*// installed plugins#&\n ${installed_plugins}#" \
|
2016-05-15 17:26:39 +02:00
|
|
|
"$rc_conf"
|
2016-03-28 22:14:19 +02:00
|
|
|
|
|
|
|
# Copy and set nginx configuration
|
|
|
|
nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf"
|
2016-04-27 14:38:35 +02:00
|
|
|
sed -i "s@#PATH#@${path:-/}@g" ../conf/nginx.conf
|
2016-03-28 22:14:19 +02:00
|
|
|
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
|