From b7ba49faf334f99cbd300f7598a4d8f312aab6c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Lebleu?= Date: Sun, 15 May 2016 23:51:33 +0200 Subject: [PATCH] =?UTF-8?q?[enh]=20Ask=20to=20install=20CardDAV=20plugin?= =?UTF-8?q?=20with=20presets=20for=20Ba=C3=AFkal=20and=20ownCloud?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 15 ++- conf/carddav.config.inc.php | 41 +++++++ conf/rcmcarddav.config.inc.php | 209 --------------------------------- manifest.json | 9 ++ scripts/_common.sh | 32 +++++ scripts/install | 37 ++---- scripts/upgrade | 38 +++--- 7 files changed, 117 insertions(+), 264 deletions(-) create mode 100644 conf/carddav.config.inc.php delete mode 100644 conf/rcmcarddav.config.inc.php diff --git a/README.md b/README.md index b8c33c6..030ab05 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,12 @@ or from the Web administration: * Scroll to the bottom of the page and put `https://github.com/jeromelebleu/roundcube_ynh/tree/dev` under **Install custom app**. +## Upgrade + +You can upgrade to this package from the command line for testing purpose with: + + $ sudo yunohost app upgrade -u https://github.com/jeromelebleu/roundcube_ynh/tree/dev roundcube + ## Extend and tweaks ### Configuration @@ -75,14 +81,7 @@ steps as needed. You can also download the plugin and put it under the `plugins/` directory. In that case, do not forget to change ownerships to this folder to `www-data`. -## TODO - - * Ask for rcmcarddav installation and/or check if *Baikal* or *ownCloud* - is installed - * Move log file outside of the public folder or protect it at least - * ... - -## Links ## +## Links **Roundcube**: https://roundcube.net/ diff --git a/conf/carddav.config.inc.php b/conf/carddav.config.inc.php new file mode 100644 index 0000000..75bd9a4 --- /dev/null +++ b/conf/carddav.config.inc.php @@ -0,0 +1,41 @@ + 'Baïkal', +// 'username' => '%u', +// 'password' => '%p', +// 'url' => '{baikal_url}/card.php/addressbooks/%u/', +// +// // optional attributes +// 'active' => true, +// 'readonly' => false, +// 'refresh_time' => '00:05:00', +// +// 'fixed' => array('username', 'password'), +// 'hide' => false, +//); +//// END: baikal + +//// PRESET FOR: owncloud +//$prefs['ownCloud'] = array( +// // required attributes +// 'name' => 'ownCloud', +// 'username' => '%u', +// 'password' => '%p', +// 'url' => '{owncloud_url}/remote.php/dav/addressbooks/users/%u/default/', +// +// // optional attributes +// 'active' => true, +// 'readonly' => false, +// 'refresh_time' => '00:05:00', +// +// 'fixed' => array('username', 'password'), +// 'hide' => false, +//); +//// END: owncloud diff --git a/conf/rcmcarddav.config.inc.php b/conf/rcmcarddav.config.inc.php deleted file mode 100644 index d15db43..0000000 --- a/conf/rcmcarddav.config.inc.php +++ /dev/null @@ -1,209 +0,0 @@ -'] = array( - // required attributes - 'name' => '', - 'username' => '', - 'password' => '', - 'url' => '', - - // optional attributes - 'active' => , - 'readonly' => , - 'refresh_time' => '', - 'preemptive_auth' => <1 or 0>, - - // attributes that are fixed (i.e., not editable by the user) and - // auto-updated for this preset - 'fixed' => array( < 0 or more of the other attribute keys > ), - - // hide this preset from CalDAV preferences section so users can't even - // see it - 'hide' => , -); -*/ - -// All values in angle brackets have to be substituted. -// -// The meaning of the different parameters is as follows: -// -// : Unique preset name, must not be '_GLOBAL'. The presetname is -// not user visible and only used for an internal mapping between -// addressbooks created from a preset and the preset itself. You -// should never change this throughout its lifetime. -// -// The following parameters are REQUIRED and need to be specified for any preset. -// -// name: User-visible name of the addressbook. If the server provides -// an additional display name for the addressbooks found for the -// preset, it will be appended in brackets to this name, except -// if carddav_name_only is true (see below). -// -// username: CardDAV username to access the addressbook. Set this setting -// to '%u' to use the roundcube username. -// In case one uses an email address as username there is the -// additional option to choose '%l', which will only use the -// local part of the username (eg: user.name@example.com will -// become user.name). -// -// password: CardDAV password to access the addressbook. Set this setting -// to '%p' to use the roundcube password. The password will not -// be stored in the database when using %p. -// -// url: URL where to find the CardDAV addressbook(s). If the given URL -// refers directly to an addressbook, only this single -// addressbook will be added. If the URL points somewhere in the -// CardDAV space, but _not_ to the location of a particular -// addressbook, the server will be queried for the available -// addressbooks and all of them will be added. You can use %u -// within the URL as a placeholder for the CardDAV username. -// '%l' works the same way as it does for the username field. -// -// The following parameters are OPTIONAL and need to be specified only if the default -// value is not acceptable. -// -// active: If this parameter is false, the addressbook is not used by roundcube -// unless the user changes this setting. -// Default: true -// -// carddav_name_only: -// If this parameter is true, only the server provided displayname -// is used for addressbooks created from this preset, except if -// the server does not provide a display name. -// Default: false -// -// readonly: If this parameter is true, the addressbook will only be -// accessible in read-only mode, i.e., the user will not be able -// to add, modify or delete contacts in the addressbook. -// Default: false -// -// refresh_time: Time interval for that cached versions of the addressbook -// entries should be used, in hours. After this time interval has -// passed since the last pull from the server, it will be -// refreshed when the addressbook is accessed the next time. -// Default: 01:00:00 -// -// preemptive_auth: -// If this parameter is 1, the authentication headers will be sent -// automatically with every request, regardless of the server -// requesting them or not. -// This must be set for ownCloud to work correctly. -// Default: 0 -// -// fixed: Array of parameter keys that must not be changed by the user. -// Note that only fixed parameters will be automatically updated -// for existing addressbooks created from presets. Otherwise the -// user may already have changed the setting, and his change -// would be lost. You can add any of the above keys, but it the -// setting only affects parameters that can be changed via the -// settings pane (e.g., readonly cannot be changed by the user -// anyway). Still only parameters listed as fixed will -// automatically updated if the preset is changed. -// Default: empty, all settings modifiable by user -// -// !!! WARNING: Only add 'url' to the list of fixed addressbooks -// if it _directly_ points to an address book collection. -// Otherwise, the plugin will initially lookup the URLs for the -// collections on the server, and at the next login overwrite it -// with the fixed value stored here. Therefore, if you change the -// URL, you have two options: -// 1) If the new URL is a variation of the old one (e.g. hostname -// change), you can run an SQL UPDATE query directly in the -// database to adopt all addressbooks. -// 2) If the new URL is not easily derivable from the old one, -// change the key of the preset and change the URL. Addressbooks -// belonging to the old preset will be deleted upon the next -// login of the user and freshly created. -// -// hide: Whether this preset should be hidden from the CalDAV listing -// on the preferences page. - - -// How Preset Updates work -// -// Preset addressbooks are created for a user as she logs in. - -//// ** ADDRESSBOOK PRESETS - EXAMPLE: Two Addressbook Presets - -//// Preset 1: Personal -/* -$prefs['Personal'] = array( - // required attributes - 'name' => 'Personal', - // will be substituted for the roundcube username - 'username' => '%u', - // will be substituted for the roundcube password - 'password' => '%p', - // %u will be substituted for the CardDAV username - 'url' => 'https://ical.example.org/caldav.php/%u/Personal', - - 'active' => true, - 'readonly' => false, - 'refresh_time' => '02:00:00', - - 'fixed' => array( 'username' ), - 'hide' => false, -); -*/ - -//// Preset 2: Corporate -/* -$prefs['Work'] = array( - 'name' => 'Corporate', - 'username' => 'CorpUser', - 'password' => 'C0rpPasswo2d', - 'url' => 'https://ical.example.org/caldav.php/%u/Corporate', - - 'fixed' => array( 'name', 'username', 'password' ), - 'hide' => true, -); -*/ - -$prefs['baikal'] = array( - // required attributes - 'name' => 'CardDAV', - // will be substituted for the roundcube username - 'username' => '%u', - // will be substituted for the roundcube password - 'password' => '%p', - // %u will be substituted for the CardDAV username - 'url' => 'https://yuno_baikal_domainyuno_baikal_path/card.php/addressbooks/%u/default/', - - 'active' => true, - 'readonly' => false, - 'refresh_time' => '00:05:00', - - 'fixed' => array( 'username', 'password' ), - 'hide' => false, -); - diff --git a/manifest.json b/manifest.json index d550cb8..3bca80a 100644 --- a/manifest.json +++ b/manifest.json @@ -42,6 +42,15 @@ }, "example": "/webmail", "default": "/webmail" + }, + { + "name": "with_carddav", + "type": "boolean", + "ask": { + "en": "Install CardDAV synchronization plugin?", + "fr": "Installer le plugin de synchronisation CardDAV ?" + }, + "default": false } ] } diff --git a/scripts/_common.sh b/scripts/_common.sh index 22e129b..7e0feaf 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -88,3 +88,35 @@ init_composer() { exec_composer "$AS_USER" "$DESTDIR" install --no-dev \ || ynh_die "Unable to update Roundcube core dependencies" } + +# Install and configure CardDAV plugin for Roundcube +# usage: install_carddav DESTDIR [AS_USER] +install_carddav() { + local DESTDIR=$1 + local AS_USER=${2:-www-data} + + local carddav_config="${DESTDIR}/plugins/carddav/config.inc.php" + local carddav_tmp_config="${PKGDIR}/conf/carddav.config.inc.php" + + exec_composer "$AS_USER" "$DESTDIR" require \ + "roundcube/carddav dev-master" + + # Look for installed and supported CardDAV servers + for carddav_app in "owncloud" "baikal"; do + sudo yunohost app list --installed -f "$carddav_app" | grep -q id \ + || continue + + # Retrieve app settings and enable relevant preset + carddav_domain=$(ynh_app_setting_get "$carddav_app" domain) + carddav_path=$(ynh_app_setting_get "$carddav_app" path) + carddav_url="https://${carddav_domain}${carddav_path%/}" + sed -i "s#{${carddav_app}_url}#${carddav_url}#g" "$carddav_tmp_config" + sed -i \ +"/\/\/\/\/ PRESET FOR: ${carddav_app}/\ +,/\/\/\/\/ END: ${carddav_app}/s/^\/\///" "$carddav_tmp_config" + done + + # Copy plugin the configuration file + sudo cp "$carddav_tmp_config" "$carddav_config" + sudo chown "${AS_USER}:" "$carddav_config" +} diff --git a/scripts/install b/scripts/install index 35311f7..4eab3e4 100644 --- a/scripts/install +++ b/scripts/install @@ -9,6 +9,7 @@ app=$YNH_APP_INSTANCE_NAME # Retrieve arguments domain=$1 path=${2%/} +with_carddav=$3 # Load common variables . ./_common.sh @@ -40,8 +41,8 @@ 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 \ +ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass" +ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" \ < "${TMPDIR}/SQL/mysql.initial.sql" # Copy and set Roundcube configuration @@ -68,32 +69,17 @@ exec_composer www-data "$DESTDIR" require \ "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" -## Install rcmcarddav TODO: if baikal is detected -#sudo yunohost app list -f baikal --json | grep '"installed": true' -#if [ "$?" -eq 0 ]; then -# echo "Detected Baikal" -# -# caldavdomain=$(sudo yunohost app setting baikal domain) -# caldavpath=$(sudo yunohost app setting baikal path) -# caldavpath=${caldavpath%/} -# -# sed -i "s@yuno_baikal_domain@$caldavdomain@g" ../conf/rcmcarddav.config.inc.php -# sed -i "s@yuno_baikal_path@$caldavpath@g" ../conf/rcmcarddav.config.inc.php -# sudo cp ../conf/rcmcarddav.config.inc.php $final_path/plugins/carddav/config.inc.php -# -# sudo sed -i "s@yuno_enable_carddav@True@g" $final_path/config/main.inc.php -# -# mysql -u $dbuser -p$dbpass $dbname < ../sources/plugins/carddav/dbinit/mysql-drop.sql -# mysql -u $dbuser -p$dbpass $dbname < ../sources/plugins/carddav/dbinit/mysql.sql -#else -# mysql -u $dbuser -p$dbpass $dbname < ../sources/plugins/carddav/dbinit/mysql-drop.sql -# sudo sed -i "s@yuno_enable_carddav@False@g" $final_path/config/main.inc.php -#fi - # Copy and set nginx configuration nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf" sed -i "s@#PATH#@${path:-/}@g" ../conf/nginx.conf @@ -109,7 +95,8 @@ sudo chown root: $phpfpm_conf sudo chmod 644 $phpfpm_conf # Save app settings -ynh_app_setting_set $app mysqlpwd $dbpass +ynh_app_setting_set "$app" with_carddav "$with_carddav" +ynh_app_setting_set "$app" mysqlpwd "$dbpass" # Reload services sudo service php5-fpm restart || true diff --git a/scripts/upgrade b/scripts/upgrade index 3cfc609..135e669 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -21,6 +21,7 @@ domain=$(ynh_app_setting_get "$app" domain) path=$(ynh_app_setting_get "$app" path) path=${path%/} dbpass=$(ynh_app_setting_get "$app" mysqlpwd) +with_carddav=$(ynh_app_setting_get "$app" with_carddav) # Check destination directory DESTDIR="/var/www/$app" @@ -72,32 +73,25 @@ exec_composer www-data "$DESTDIR" require \ "sblaisot/automatic_addressbook" installed_plugins+=" 'contextmenu', 'automatic_addressbook'," +# 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 + # Update Roundcube configuration sudo sed -i "s#^\s*// installed plugins#&\n ${installed_plugins}#" \ "$rc_conf" -## Install rcmcarddav if baikal is detected -#sudo yunohost app list -f baikal --json | grep '"installed": true' -#if [ "$?" -eq 0 ]; then -# echo "Detected Baikal" -# -# caldavdomain=$(sudo yunohost app setting baikal domain) -# caldavpath=$(sudo yunohost app setting baikal path) -# caldavpath=${caldavpath%/} -# -# sed -i "s@yuno_baikal_domain@$caldavdomain@g" ../conf/rcmcarddav.config.inc.php -# sed -i "s@yuno_baikal_path@$caldavpath@g" ../conf/rcmcarddav.config.inc.php -# sudo cp ../conf/rcmcarddav.config.inc.php $final_path/plugins/carddav/config.inc.php -# -# sudo sed -i "s@yuno_enable_carddav@True@g" $final_path/config/main.inc.php -# -# mysql -u $db_user -p$db_pwd $db_user < ../sources/plugins/carddav/dbinit/mysql-drop.sql -# mysql -u $db_user -p$db_pwd $db_user < ../sources/plugins/carddav/dbinit/mysql.sql -#else -# mysql -u $db_user -p$db_pwd $db_user < ../sources/plugins/carddav/dbinit/mysql-drop.sql -# sudo sed -i "s@yuno_enable_carddav@False@g" $final_path/config/main.inc.php -#fi - # Copy and set nginx configuration nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf" sed -i "s@#PATH#@${path:-/}@g" ../conf/nginx.conf