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
|
|
|
|
|
|
|
# Retrieve arguments
|
|
|
|
domain=$1
|
|
|
|
path=${2%/}
|
2016-05-15 23:51:33 +02:00
|
|
|
with_carddav=$3
|
2016-03-28 22:14:19 +02:00
|
|
|
|
|
|
|
# Load common variables
|
|
|
|
. ./_common.sh
|
|
|
|
|
|
|
|
# Set app specific variables
|
|
|
|
dbname=$app
|
|
|
|
dbuser=$app
|
|
|
|
|
|
|
|
# Source app helpers
|
|
|
|
. /usr/share/yunohost/helpers
|
|
|
|
|
2016-05-15 17:26:39 +02:00
|
|
|
# Check domain/path availability
|
|
|
|
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|
|
|
|
|| exit 1
|
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' already exists.\
|
|
|
|
You should safely delete it before installing this app."
|
|
|
|
|
2016-05-17 13:15:38 +02:00
|
|
|
# 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"
|
|
|
|
|
2016-03-28 22:14:19 +02:00
|
|
|
# Create tmp directory and install app inside
|
|
|
|
TMPDIR=$(ynh_mkdir_tmp)
|
|
|
|
extract_roundcube "$TMPDIR"
|
|
|
|
init_composer "$TMPDIR"
|
|
|
|
|
|
|
|
# Generate random DES key & password
|
|
|
|
deskey=$(ynh_string_random 24)
|
|
|
|
dbpass=$(ynh_string_random)
|
|
|
|
|
|
|
|
# Initialize database
|
2016-05-15 23:51:33 +02:00
|
|
|
ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
|
|
|
|
ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" \
|
2016-03-28 22:14:19 +02:00
|
|
|
< "${TMPDIR}/SQL/mysql.initial.sql"
|
|
|
|
|
|
|
|
# Copy and set Roundcube configuration
|
|
|
|
rc_conf="${TMPDIR}/config/config.inc.php"
|
|
|
|
cp ../conf/config.inc.php "$rc_conf"
|
|
|
|
sed -i "s/#DESKEY#/${deskey}/g" "$rc_conf"
|
|
|
|
sed -i "s/#DBUSER#/${dbuser}/g" "$rc_conf"
|
|
|
|
sed -i "s/#DBPASS#/${dbpass}/g" "$rc_conf"
|
|
|
|
sed -i "s/#DBNAME#/${dbname}/g" "$rc_conf"
|
|
|
|
|
|
|
|
# Install files and set permissions
|
|
|
|
sudo mv "$TMPDIR" "$DESTDIR"
|
|
|
|
sudo mkdir -p "${DESTDIR}/logs" "${DESTDIR}/temp"
|
|
|
|
sudo chown -R www-data: "$DESTDIR"
|
|
|
|
|
|
|
|
# Install some plugins manually
|
|
|
|
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
|
|
|
|
|
|
|
# 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
|
|
|
# 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
|
|
|
"${DESTDIR}/config/config.inc.php"
|
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
|
|
|
|
|
|
|
|
# Save app settings
|
2016-05-15 23:51:33 +02:00
|
|
|
ynh_app_setting_set "$app" with_carddav "$with_carddav"
|
|
|
|
ynh_app_setting_set "$app" mysqlpwd "$dbpass"
|
2016-03-28 22:14:19 +02:00
|
|
|
|
|
|
|
# Reload services
|
|
|
|
sudo service php5-fpm restart || true
|
|
|
|
sudo service nginx reload || true
|