#!/bin/bash #================================================= # GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers #================================================= # MANAGE SCRIPT FAILURE #================================================= # Exit if an error occurs during the execution of the script #REMOVEME? ynh_abort_if_errors #================================================= # RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= #REMOVEME? domain=$YNH_APP_ARG_DOMAIN #REMOVEME? path=$YNH_APP_ARG_PATH #REMOVEME? with_carddav=$YNH_APP_ARG_WITH_CARDDAV #REMOVEME? language=$YNH_APP_ARG_LANGUAGE #REMOVEME? app=$YNH_APP_INSTANCE_NAME fpm_footprint="low" fpm_free_footprint=0 fpm_usage="low" #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= #REMOVEME? ynh_script_progression --message="Validating installation parameters..." --weight=1 #REMOVEME? install_dir=/var/www/$app #REMOVEME? test ! -e "$install_dir" || ynh_die --message="This path already contains a folder" # Register (book) web path #REMOVEME? ynh_webpath_register --app=$app --domain=$domain --path=$path #================================================= # STORE SETTINGS FROM MANIFEST #================================================= #REMOVEME? ynh_script_progression --message="Storing installation settings..." --weight=2 #REMOVEME? ynh_app_setting_set --app=$app --key=domain --value=$domain #REMOVEME? ynh_app_setting_set --app=$app --key=path --value=$path ynh_app_setting_set --app=$app --key=with_carddav --value=$with_carddav ynh_app_setting_set --app=$app --key=language --value=$language ynh_app_setting_set --app=$app --key=fpm_footprint --value=$fpm_footprint ynh_app_setting_set --app=$app --key=fpm_free_footprint --value=$fpm_free_footprint ynh_app_setting_set --app=$app --key=fpm_usage --value=$fpm_usage #================================================= # STANDARD MODIFICATIONS #================================================= # CREATE A MYSQL DATABASE #================================================= #REMOVEME? ynh_script_progression --message="Creating a MySQL database..." --weight=2 #REMOVEME? db_name=$(ynh_sanitize_dbid --db_name=$app) #REMOVEME? db_user=$db_name #REMOVEME? ynh_app_setting_set --app=$app --key=db_name --value=$db_name #REMOVEME? ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name #================================================= # INSTALL DEPENDENCIES #================================================= #REMOVEME? ynh_script_progression --message="Installing dependencies..." --weight=1 #REMOVEME? ynh_install_app_dependencies $pkg_dependencies #================================================= # CREATE DEDICATED USER #================================================= #REMOVEME? ynh_script_progression --message="Configuring system user..." --weight=3 # Create a system user #REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression --message="Setting up source files..." --weight=7 #REMOVEME? ynh_app_setting_set --app=$app --key=install_dir --value=$install_dir # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$install_dir" chmod 750 "$install_dir" chmod -R o-rwx "$install_dir" chown -R $app:www-data "$install_dir" #================================================= # NGINX CONFIGURATION #================================================= ynh_script_progression --message="Configuring NGINX web server..." --weight=2 # Create a dedicated NGINX config ynh_add_nginx_config #================================================= # PHP-FPM CONFIGURATION #================================================= ynh_script_progression --message="Configuring PHP-FPM..." --weight=2 # Create a dedicated php-fpm config ynh_add_fpm_config --usage=$fpm_usage --footprint=$fpm_footprint #REMOVEME? phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) #================================================= # SPECIFIC SETUP #================================================= # INSTALL AND INITIALIZE COMPOSER #================================================= ynh_script_progression --message="Installing Roundcube with Composer..." --weight=30 # Install composer.json cp "$install_dir/composer.json-dist" "$install_dir/composer.json" # Install composer ynh_install_composer #================================================= # INITIALIZE DATABASE #================================================= ynh_script_progression --message="Initializing database..." --weight=3 ynh_mysql_connect_as --user="$db_user" --password="$db_pwd" --database="$db_name" \ < "$install_dir/SQL/mysql.initial.sql" #================================================= # CONFIGURE ROUNDCUBE #================================================= ynh_script_progression --message="Configuring Roundcube..." --weight=2 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 # Create logs and temp directories mkdir -p "$install_dir/"{logs,temp} # Install net_LDAP ynh_composer_exec --commands="require kolab/net_ldap3" # Install contextmenu and automatic_addressbook plugins # https://plugins.roundcube.net/packages/sblaisot/automatic_addressbook # https://plugins.roundcube.net/packages/johndoh/contextmenu ynh_composer_exec --commands="require \ johndoh/contextmenu $contextmenu_version \ sblaisot/automatic_addressbook $automatic_addressbook_version" installed_plugins+=" 'contextmenu', 'automatic_addressbook'," 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" 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,} # 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_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 #REMOVEME? carddav_domain=$(ynh_app_setting_get --app=$carddav_app_id --key=domain) #REMOVEME? 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 fi #================================================= # UPDATE ROUNDCUBE CONFIGURATION #================================================= ynh_script_progression --message="Updating Roundcube configuration..." --weight=3 ynh_replace_string --match_string="^\s*// installed plugins" --replace_string="&\n $installed_plugins" --target_file="$install_dir/config/config.inc.php" # Update javascript dependencies (cd "$install_dir" /usr/bin/php$phpversion -q ./bin/install-jsdeps.sh -v ?) # Store the config file checksum into the app settings ynh_store_file_checksum --file="$install_dir/config/config.inc.php" chmod 400 "$install_dir/config/config.inc.php" chown $app:$app "$install_dir/config/config.inc.php" #================================================= # GENERIC FINALIZATION #================================================= # RELOAD NGINX #================================================= #REMOVEME? ynh_script_progression --message="Reloading NGINX web server..." --weight=2 #REMOVEME? ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Installation of $app completed" --last