#!/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 ynh_abort_if_errors #================================================= # RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= domain=$YNH_APP_ARG_DOMAIN path_url=$YNH_APP_ARG_PATH with_carddav=$YNH_APP_ARG_WITH_CARDDAV with_enigma=$YNH_APP_ARG_WITH_ENIGMA app=$YNH_APP_INSTANCE_NAME #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= ynh_script_progression --message="Validating installation parameters..." final_path=/var/www/$app test ! -e "$final_path" || ynh_die --message="This path already contains a folder" # Register (book) web path ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url #================================================= # STORE SETTINGS FROM MANIFEST #================================================= ynh_script_progression --message="Storing installation settings..." --weight=2 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 #================================================= # STANDARD MODIFICATIONS #================================================= # INSTALL DEPENDENCIES #================================================= ynh_script_progression --message="Installing dependencies..."5 ynh_install_app_dependencies "$pkg_dependencies" #================================================= # CREATE A MYSQL DATABASE #================================================= ynh_script_progression --message="Creating a MySQL database..." 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 #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression --message="Setting up source files..." --weight=7 ynh_app_setting_set --app=$app --key=final_path --value=$final_path # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$final_path" #================================================= # NGINX CONFIGURATION #================================================= ynh_script_progression --message="Configuring nginx web server..." # Create a dedicated nginx config ynh_add_nginx_config #================================================= # CREATE DEDICATED USER #================================================= ynh_script_progression --message="Configuring system user..." --weight=3 # Create a system user ynh_system_user_create --username=$app #================================================= # PHP-FPM CONFIGURATION #================================================= ynh_script_progression --message="Configuring php-fpm..." --weight=2 # Create a dedicated php-fpm config ynh_add_fpm_config #================================================= # SPECIFIC SETUP #================================================= # INSTALL AND INITIALIZE COMPOSER #================================================= ynh_script_progression --message="Installing roundcube with composer..." --weight=30 # Install composer.json cp "$final_path/composer.json-dist" "$final_path/composer.json" # Install composer ynh_install_composer #================================================= # INITIALIZE DATABASE #================================================= ynh_script_progression --message="Initializing database..." --weight=3 ynh_mysql_connect_as --user="$db_name" --password="$db_pwd" --database="$db_name" \ < "$final_path/SQL/mysql.initial.sql" #================================================= # CONFIGURE ROUNDCUBE #================================================= ynh_script_progression --message="Configuring roundcube..." rc_conf="$final_path/config/config.inc.php" cp ../conf/config.inc.php "$rc_conf" 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" 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" #================================================= # INSTALL ADDITIONAL PLUGINS #================================================= ynh_script_progression --message="Installing additional plugins..." --weight=60 # Create logs and temp directories mkdir -p "$final_path/"{logs,temp} # 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'," # Install CardDAV plugin if [ $with_carddav -eq 1 ] then ynh_composer_exec --commands="require roundcube/carddav $carddav_version" carddav_tmp_config="../conf/carddav.config.inc.php" # Look for installed and supported CardDAV servers for carddav_app in "owncloud" "nextcloud" "baikal" do carddav_app_id=$(yunohost app list --installed -f $carddav_app \ --output-as json | grep -Po '"id":[ ]?"\K.*?(?=")' | head -1) if [ -n "$carddav_app_id" ] then # 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}_url}" --replace_string="$carddav_url" --target_file="$carddav_tmp_config" ynh_replace_string --match_string="/* PRESET FOR: $carddav_app" --replace_string="" --target_file="$carddav_tmp_config" ynh_replace_string --match_string="END: $carddav_app */" --replace_string="" --target_file="$carddav_tmp_config" fi done # Copy the plugin configuration file cp "$carddav_tmp_config" ""$final_path/plugins/carddav/config.inc.php"" installed_plugins+=" 'carddav'," fi # Install Enigma plugin if [ $with_enigma -eq 1 ] then 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" \ && installed_plugins+=" 'enigma'," \ || ynh_print_warn --message="Unable to install Enigma plugin" 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="$rc_conf" # Update javascript dependencies (cd "$final_path" /usr/bin/php -q ./bin/install-jsdeps.sh) # Store the config file checksum into the app settings ynh_store_file_checksum --file="$rc_conf" #================================================= # GENERIC FINALIZATION #================================================= # SECURE FILES AND DIRECTORIES #================================================= # Set permissions to app files chown -R root: "$final_path" mkdir -p "$final_path/plugins/enigma/home" chown -R $app: "$final_path/"{temp,logs,plugins/enigma/home} #================================================= # RELOAD NGINX #================================================= ynh_script_progression --message="Reloading nginx web server..." --weight=2 ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Installation of $app completed" --last