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/install

104 lines
2.9 KiB
Text
Raw Normal View History

#!/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
# Retrieve arguments
domain=$1
path=${2%/}
with_carddav=$3
# Load common variables
. ./_common.sh
# Set app specific variables
dbname=$app
dbuser=$app
# Source app helpers
. /usr/share/yunohost/helpers
# Check domain/path availability
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|| exit 1
# Check destination directory
DESTDIR="/var/www/$app"
[[ -d $DESTDIR ]] && ynh_die \
"The destination directory '$DESTDIR' already exists.\
You should safely delete it before installing this app."
# 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
ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" \
< "${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"
installed_plugins=" 'ldapAliasSync',"
# Install additional plugins
exec_composer www-data "$DESTDIR" require \
"johndoh/contextmenu dev-release-2.1" \
"sblaisot/automatic_addressbook"
installed_plugins+=" 'contextmenu', 'automatic_addressbook',"
# 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}#" \
"${DESTDIR}/config/config.inc.php"
# 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
# Save app settings
ynh_app_setting_set "$app" with_carddav "$with_carddav"
ynh_app_setting_set "$app" mysqlpwd "$dbpass"
# Reload services
sudo service php5-fpm restart || true
sudo service nginx reload || true