diff --git a/scripts/_common.sh b/scripts/_common.sh index 6d12583..eefe918 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -16,32 +16,17 @@ carddav_version=5.0.1 # DEFINE ALL COMMON FONCTIONS #================================================= -install_roundcube_with_plugins() { - - #================================================= - # INSTALL AND INITIALIZE COMPOSER - #================================================= - ynh_script_progression --message="Installing Roundcube with Composer..." --weight=30 - - # Install composer.json +install_composer() { cp "$install_dir/composer.json-dist" "$install_dir/composer.json" - - # Install composer ynh_install_composer +} - #================================================= - # CONFIGURE ROUNDCUBE - #================================================= - ynh_script_progression --message="Configuring Roundcube..." --weight=2 - +configure_roundcube() { deskey=$(ynh_string_random --length=24) ynh_add_config --template="../conf/config.inc.php" --destination="$install_dir/config/config.inc.php" +} - #================================================= - # INSTALL ADDITIONAL PLUGINS - #================================================= - ynh_script_progression --message="Installing additional plugins..." --weight=60 - +install_ldap_addressbook_contextmenu_plugins() { # Create logs and temp directories mkdir -p "$install_dir/"{logs,temp} @@ -61,48 +46,44 @@ install_roundcube_with_plugins() { ynh_add_config --template="../conf/enigma.config.inc.php" --destination="$install_dir/plugins/enigma/config.inc.php" mkdir -p "$install_dir/plugins/enigma/home" chown -R $app:www-data "$install_dir/plugins/enigma/home" +} - # Install CardDAV plugin - if [ $with_carddav -eq 1 ] - then - ynh_composer_exec --commands="require roundcube/carddav $carddav_version --with-all-dependencies" +install_carddav_plugin(){ + ynh_composer_exec --commands="require roundcube/carddav $carddav_version --with-all-dependencies" - carddav_tmp_config="../conf/carddav.config.inc.php" - carddav_server=0 + carddav_tmp_config="../conf/carddav.config.inc.php" + carddav_server=0 - # Copy the plugin configuration file - cp $install_dir/plugins/carddav/config.inc.php{.dist,} + # Copy the plugin configuration file + cp $install_dir/plugins/carddav/config.inc.php{.dist,} - # Look for installed and supported CardDAV servers - for carddav_app in "nextcloud" "baikal" + # Look for installed and supported CardDAV servers + for carddav_app in "nextcloud" "baikal" + 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_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" >> $install_dir/plugins/carddav/config.inc.php - # Retrieve app settings and enable relevant preset - carddav_domain=$(ynh_app_setting_get --app=$carddav_app_id --key=domain) - carddav_path=$(ynh_app_setting_get --app=$carddav_app_id --key=path) - carddav_url="https://${carddav_domain}${carddav_path%/}" - ynh_replace_string --match_string="{${carddav_app}_id}" --replace_string="$carddav_app_id" --target_file="$install_dir/plugins/carddav/config.inc.php" - ynh_replace_string --match_string="{${carddav_app}_url}" --replace_string="$carddav_url" --target_file="$install_dir/plugins/carddav/config.inc.php" - done + carddav_server=1 + # Append preset configuration to the config file + cat "../conf/${carddav_app}.inc.php" >> $install_dir/plugins/carddav/config.inc.php + # Retrieve app settings and enable relevant preset + carddav_domain=$(ynh_app_setting_get --app=$carddav_app_id --key=domain) + carddav_path=$(ynh_app_setting_get --app=$carddav_app_id --key=path) + carddav_url="https://${carddav_domain}${carddav_path%/}" + ynh_replace_string --match_string="{${carddav_app}_id}" --replace_string="$carddav_app_id" --target_file="$install_dir/plugins/carddav/config.inc.php" + ynh_replace_string --match_string="{${carddav_app}_url}" --replace_string="$carddav_url" --target_file="$install_dir/plugins/carddav/config.inc.php" done + 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 + # Do not actualy add the cardDAV plugin if there's no cardDAV server available... + if [ $carddav_server -eq 1 ] + then + installed_plugins+=" 'carddav'," fi - #================================================= - # UPDATE ROUNDCUBE CONFIGURATION - #================================================= - ynh_script_progression --message="Updating Roundcube configuration..." --weight=3 +} +enable_plugins_in_config() { ynh_replace_string --match_string="^\s*// installed plugins" --replace_string="&\n $installed_plugins" --target_file="$install_dir/config/config.inc.php" # Store the config file checksum into the app settings @@ -110,10 +91,10 @@ install_roundcube_with_plugins() { chmod 400 "$install_dir/config/config.inc.php" chown $app:$app "$install_dir/config/config.inc.php" - - # Update javascript dependencies - (cd "$install_dir" - /usr/bin/php$phpversion -q ./bin/install-jsdeps.sh -v ?) - +} + +update_javascript_deps() { + (cd "$install_dir" + /usr/bin/php$phpversion -q ./bin/install-jsdeps.sh -v ?) } diff --git a/scripts/install b/scripts/install index e555d2f..4ca8152 100644 --- a/scripts/install +++ b/scripts/install @@ -58,6 +58,25 @@ ynh_mysql_connect_as --user="$db_user" --password="$db_pwd" --database="$db_name #================================================= # INSTALL DEPENDENCIES AND PLUGINS #================================================= -install_roundcube_with_plugins +ynh_script_progression --message="Installing Roundcube with Composer..." --weight=30 +install_composer + +ynh_script_progression --message="Configuring Roundcube..." --weight=2 +configure_roundcube + +ynh_script_progression --message="Installing ldap, automatic addressbook and contextmenu plugins..." --weight=60 +install_ldap_addressbook_contextmenu_plugins + +if [ $with_carddav -eq 1 ] +then + ynh_script_progression --message="Installing carddav plugin..." --weight=30 + install_carddav_plugin +fi + +ynh_script_progression --message="Install javascript dependencies..." --weight=10 +update_javascript_deps + +ynh_script_progression --message="Updating Roundcube configuration..." --weight=3 +enable_plugins_in_config ynh_script_progression --message="Installation of $app completed" --last diff --git a/scripts/upgrade b/scripts/upgrade index 1882d2c..c4fb6f8 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -82,10 +82,28 @@ ynh_add_nginx_config #================================================= # CONFIGURE ROUNDCUBE #================================================= -install_roundcube_with_plugins - +ynh_script_progression --message="Installing Roundcube with Composer..." --weight=30 +install_composer ynh_composer_exec --commands="update --no-dev" +ynh_script_progression --message="Configuring Roundcube..." --weight=2 +configure_roundcube + +ynh_script_progression --message="Installing ldap, automatic addressbook and contextmenu plugins..." --weight=60 +install_ldap_addressbook_contextmenu_plugins + +if [ $with_carddav -eq 1 ] +then + ynh_script_progression --message="Installing carddav plugin..." --weight=30 + install_carddav_plugin +fi + +ynh_script_progression --message="Install javascript dependencies..." --weight=10 +update_javascript_deps + +ynh_script_progression --message="Updating Roundcube configuration..." --weight=3 +enable_plugins_in_config + # Migrate roundcube database pushd "$install_dir" COMPOSER_ALLOW_SUPERUSER=1 ynh_exec_warn "php$phpversion" ./bin/update.sh --version=$oldversion -y