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

239 lines
9 KiB
Text
Raw Normal View History

#!/bin/bash
2017-08-26 03:24:41 +02:00
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2019-03-03 18:12:41 +01:00
source _common.sh
2017-06-02 17:15:57 +02:00
source /usr/share/yunohost/helpers
2017-08-26 03:24:41 +02:00
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
2017-06-18 17:09:53 +02:00
2017-06-02 17:15:57 +02:00
domain=$YNH_APP_ARG_DOMAIN
2017-08-26 03:24:41 +02:00
path_url=$YNH_APP_ARG_PATH
2017-06-02 17:15:57 +02:00
with_carddav=$YNH_APP_ARG_WITH_CARDDAV
2017-07-03 17:40:09 +02:00
with_enigma=$YNH_APP_ARG_WITH_ENIGMA
language=$YNH_APP_ARG_LANGUAGE
2017-06-02 17:15:57 +02:00
2017-08-26 03:24:41 +02:00
app=$YNH_APP_INSTANCE_NAME
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
ynh_script_progression --message="Validating installation parameters..." --weight=1
2017-08-26 03:24:41 +02:00
final_path=/var/www/$app
2019-05-18 18:42:54 +02:00
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
2019-03-03 18:12:41 +01:00
2017-08-26 03:24:41 +02:00
# Register (book) web path
2019-05-18 18:42:54 +02:00
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
2017-08-26 03:24:41 +02:00
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
2019-05-18 18:42:54 +02:00
ynh_script_progression --message="Storing installation settings..." --weight=2
2019-05-18 18:42:54 +02:00
ynh_app_setting_set --app=$app --key=domain --value=$domain
ynh_app_setting_set --app=$app --key=path --value=$path_url
ynh_app_setting_set --app=$app --key=with_carddav --value=$with_carddav
ynh_app_setting_set --app=$app --key=with_enigma --value=$with_enigma
ynh_app_setting_set --app=$app --key=language --value=$language
2017-08-26 03:24:41 +02:00
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# CREATE A MYSQL DATABASE
#=================================================
2019-05-18 18:42:54 +02:00
ynh_script_progression --message="Creating a MySQL database..."
2017-08-26 03:24:41 +02:00
2019-05-18 18:42:54 +02:00
db_name=$(ynh_sanitize_dbid --db_name=$app)
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
ynh_mysql_setup_db --db_user=$db_name --db_name=$db_name
2017-08-26 03:24:41 +02:00
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
2019-05-18 18:42:54 +02:00
ynh_script_progression --message="Setting up source files..." --weight=7
2017-08-26 03:24:41 +02:00
2019-05-18 18:42:54 +02:00
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
2017-08-26 03:24:41 +02:00
# Download, check integrity, uncompress and patch the source from app.src
2019-05-18 18:42:54 +02:00
ynh_setup_source --dest_dir="$final_path"
2017-08-26 03:24:41 +02:00
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring NGINX web server..." --weight=2
2017-08-26 03:24:41 +02:00
# Create a dedicated NGINX config
2017-08-26 03:24:41 +02:00
ynh_add_nginx_config
#=================================================
# CREATE DEDICATED USER
#=================================================
2019-05-18 18:42:54 +02:00
ynh_script_progression --message="Configuring system user..." --weight=3
2017-08-26 03:24:41 +02:00
# Create a system user
2019-05-18 18:42:54 +02:00
ynh_system_user_create --username=$app
2017-08-26 03:24:41 +02:00
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring PHP-FPM..." --weight=2
2017-08-26 03:24:41 +02:00
# Create a dedicated PHP-FPM config
ynh_add_fpm_config --package="$extra_php_dependencies"
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
2017-08-26 03:24:41 +02:00
#=================================================
# SPECIFIC SETUP
#=================================================
# INSTALL AND INITIALIZE COMPOSER
#=================================================
ynh_script_progression --message="Installing Roundcube with Composer..." --weight=30
2017-08-26 03:24:41 +02:00
2019-03-03 18:12:41 +01:00
# Install composer.json
cp "$final_path/composer.json-dist" "$final_path/composer.json"
# Install composer
ynh_install_composer
2017-08-26 03:24:41 +02:00
#=================================================
# INITIALIZE DATABASE
#=================================================
2019-05-18 18:42:54 +02:00
ynh_script_progression --message="Initializing database..." --weight=3
2019-05-18 18:42:54 +02:00
ynh_mysql_connect_as --user="$db_name" --password="$db_pwd" --database="$db_name" \
2019-03-03 18:12:41 +01:00
< "$final_path/SQL/mysql.initial.sql"
2017-08-26 03:24:41 +02:00
#=================================================
# CONFIGURE ROUNDCUBE
#=================================================
ynh_script_progression --message="Configuring $app..."
2019-03-03 18:13:57 +01:00
2019-03-03 18:12:41 +01:00
rc_conf="$final_path/config/config.inc.php"
2017-08-26 03:24:41 +02:00
cp ../conf/config.inc.php "$rc_conf"
2017-08-26 03:24:41 +02:00
2019-05-18 18:42:54 +02:00
ynh_replace_string --match_string="__DESKEY__" --replace_string="$(ynh_string_random --length=24)" --target_file="$rc_conf"
ynh_replace_string --match_string="__DBUSER__" --replace_string="$db_name" --target_file="$rc_conf"
2019-05-18 18:42:54 +02:00
ynh_replace_string --match_string="__DBPASS__" --replace_string="$db_pwd" --target_file="$rc_conf"
ynh_replace_string --match_string="__DBNAME__" --replace_string="$db_name" --target_file="$rc_conf"
ynh_replace_string --match_string="__LANGUAGE__" --replace_string="$language" --target_file="$rc_conf"
2017-08-26 03:24:41 +02:00
#=================================================
# INSTALL ADDITIONAL PLUGINS
#=================================================
2019-05-18 18:42:54 +02:00
ynh_script_progression --message="Installing additional plugins..." --weight=60
2017-08-26 03:24:41 +02:00
# Create logs and temp directories
2019-03-03 18:12:41 +01:00
mkdir -p "$final_path/"{logs,temp}
2017-08-26 03:24:41 +02:00
# Install net_LDAP
ynh_composer_exec --commands="require kolab/net_ldap3"
2017-08-26 03:24:41 +02:00
# Install contextmenu and automatic_addressbook plugins
# https://plugins.roundcube.net/packages/sblaisot/automatic_addressbook
# https://plugins.roundcube.net/packages/johndoh/contextmenu
2019-03-03 18:12:41 +01:00
ynh_composer_exec --commands="require \
johndoh/contextmenu $contextmenu_version \
sblaisot/automatic_addressbook $automatic_addressbook_version"
installed_plugins+=" 'contextmenu', 'automatic_addressbook',"
# Install CardDAV plugin
2019-03-03 18:12:41 +01:00
if [ $with_carddav -eq 1 ]
then
ynh_composer_exec --commands="require roundcube/carddav $carddav_version"
carddav_tmp_config="../conf/carddav.config.inc.php"
carddav_server=0
2019-03-03 18:12:41 +01:00
# Copy the plugin configuration file
cp $final_path/plugins/carddav/config.inc.php{.dist,}
2019-03-03 18:12:41 +01:00
# Look for installed and supported CardDAV servers
for carddav_app in "nextcloud" "baikal"
2019-03-03 18:12:41 +01:00
do
carddav_app_ids=$(yunohost app list | grep "id: $carddav_app" | grep -Po 'id: \K(.*)' || echo "")
for carddav_app_id in $carddav_app_ids
do
carddav_server=1
# Append preset configuration to the config file
cat "../conf/${carddav_app}.inc.php" >> $final_path/plugins/carddav/config.inc.php
2019-03-03 18:12:41 +01:00
# Retrieve app settings and enable relevant preset
2019-05-18 18:42:54 +02:00
carddav_domain=$(ynh_app_setting_get --app=$carddav_app_id --key=domain)
carddav_path=$(ynh_app_setting_get --app=$carddav_app_id --key=path)
2019-03-03 18:12:41 +01:00
carddav_url="https://${carddav_domain}${carddav_path%/}"
ynh_replace_string --match_string="{${carddav_app}_id}" --replace_string="$carddav_app_id" --target_file="$final_path/plugins/carddav/config.inc.php"
ynh_replace_string --match_string="{${carddav_app}_url}" --replace_string="$carddav_url" --target_file="$final_path/plugins/carddav/config.inc.php"
done
2019-03-03 18:12:41 +01:00
done
# Do not actualy add the carddav plugin if there's no carddav server available...
if [ $carddav_server -eq 1 ]
then
installed_plugins+=" 'carddav',"
fi
fi
2017-07-03 15:05:22 +02:00
# Install Enigma plugin
2019-03-03 18:12:41 +01:00
if [ $with_enigma -eq 1 ]
then
2019-07-16 06:38:23 +02:00
enigma_tmp_config="../conf/enigma.config.inc.php"
ynh_replace_string --match_string="__DIR__" --replace_string="$final_path/plugins/enigma/home" --target_file="$enigma_tmp_config"
cp "$enigma_tmp_config" "$final_path/plugins/enigma/config.inc.php" \
2019-03-03 18:12:41 +01:00
&& installed_plugins+=" 'enigma'," \
2019-05-18 18:42:54 +02:00
|| ynh_print_warn --message="Unable to install Enigma plugin"
2017-07-03 15:05:22 +02:00
fi
2017-08-26 03:24:41 +02:00
#=================================================
# UPDATE ROUNDCUBE CONFIGURATION
#=================================================
ynh_script_progression --message="Updating Roundcube configuration..." --weight=3
2017-08-26 03:24:41 +02:00
2019-05-18 18:42:54 +02:00
ynh_replace_string --match_string="^\s*// installed plugins" --replace_string="&\n $installed_plugins" --target_file="$rc_conf"
2017-06-02 17:15:57 +02:00
2017-07-03 13:12:59 +02:00
# Update javascript dependencies
2019-03-03 18:12:41 +01:00
(cd "$final_path"
2017-08-26 03:24:41 +02:00
/usr/bin/php -q ./bin/install-jsdeps.sh)
2017-07-03 13:12:59 +02:00
2017-08-26 03:24:41 +02:00
# Store the config file checksum into the app settings
2019-05-18 18:42:54 +02:00
ynh_store_file_checksum --file="$rc_conf"
2017-08-26 03:24:41 +02:00
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
2017-06-02 17:15:57 +02:00
2017-08-26 03:24:41 +02:00
# Set permissions to app files
chown -R root: "$final_path"
mkdir -p "$final_path/plugins/enigma/home"
2019-03-03 18:12:41 +01:00
chown -R $app: "$final_path/"{temp,logs,plugins/enigma/home}
2017-08-26 03:24:41 +02:00
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..." --weight=2
2019-05-18 18:42:54 +02:00
ynh_systemd_action --service_name=nginx --action=reload
2019-03-03 18:13:57 +01:00
#=================================================
# END OF SCRIPT
#=================================================
2019-05-18 18:42:54 +02:00
ynh_script_progression --message="Installation of $app completed" --last