#!/bin/bash #================================================= # GENERIC STARTING #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers #================================================= # MANAGE FAILURE OF THE SCRIPT #================================================= # 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 admin_tiki=$YNH_APP_ARG_ADMIN is_public=$YNH_APP_ARG_IS_PUBLIC app=$YNH_APP_INSTANCE_NAME #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS #================================================= ynh_script_progression --message="Validating installation parameters..." --weight=2 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=admin --value=$admin_tiki ynh_app_setting_set --app=$app --key=overwrite_nginx --value=1 ynh_app_setting_set --app=$app --key=overwrite_phpfpm --value=1 #================================================= # STANDARD MODIFICATIONS #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression --message="Setting up source files..." --weight=4 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" mkdir -p $final_path/sessions mkdir -p $final_path/conf.d mkdir -p $final_path/storage/fgal #================================================= # CREATE DEDICATED USER #================================================= ynh_script_progression --message="Configuring system user..." --weight=3 # Create a dedicated system user ynh_system_user_create --username=$app #================================================= # PHP-FPM CONFIGURATION #================================================= ynh_script_progression --message="Configuring PHP-FPM..." --weight=2 # If the app is private, set the usage to low, otherwise to high. if [ $is_public -eq 0 ] then usage=low else usage=high fi # Create a dedicated PHP-FPM config ynh_add_fpm_config --usage=$usage --footprint=medium --package="$extra_php_dependencies" phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) #================================================= # SECURING FILES AND DIRECTORIES #================================================= # Set permissions to app files # Files have to be own by the user of wordpress. To allow upgrade from the app. chown -R $app: $final_path #================================================= # 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 ynh_mysql_execute_as_root --sql="ALTER DATABASE $db_name CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;" # Workaround bug ynh_replace_string --match_string="new GetStringsCommand," --replace_string="new InstallCommand," --target_file=$final_path/lib/core/Tiki/Command/ConsoleApplicationBuilder.php # Deploy database sudo -u $app php7.4 $final_path/console.php database:configure $db_name $db_pwd $db_name sudo -u $app php7.4 $final_path/console.php database:install # Undo Workaround bug ynh_replace_string --match_string="new InstallCommand," --replace_string="new GetStringsCommand," --target_file=$final_path/lib/core/Tiki/Command/ConsoleApplicationBuilder.php ynh_mysql_execute_as_root --sql="INSERT INTO tiki_preferences (name, value) VALUES ('auth_ldap_host','localhost');" --database=$db_name ynh_mysql_execute_as_root --sql="INSERT INTO tiki_preferences (name, value) VALUES ('auth_ldap_basedn','ou=users,dc=yunohost,dc=org');" --database=$db_name ynh_mysql_execute_as_root --sql="INSERT INTO tiki_preferences (name, value) VALUES ('auth_ldap_scope','base');" --database=$db_name ynh_mysql_execute_as_root --sql="INSERT INTO tiki_preferences (name, value) VALUES ('auth_method','ldap');" --database=$db_name ynh_mysql_execute_as_root --sql="INSERT INTO tiki_preferences (name, value) VALUES ('auth_ldap_emailattr','mail');" --database=$db_name ynh_mysql_execute_as_root --sql="UPDATE users_users set login='$admin_tiki' where userID = '1';" --database=$app #================================================= # NGINX CONFIGURATION #================================================= ynh_script_progression --message="Configuring NGINX web server..." --weight=3 # Create a dedicated NGINX config ynh_add_nginx_config #================================================= # GENERIC FINALISATION #================================================= #================================================= # SPECIFIC SETUP #================================================= # CONFIGURE TIKI #================================================= ynh_script_progression --message="Configuring Tiki..." sudo -u $app php7.4 $final_path/console.php installer:lock #================================================= # SETUP FAIL2BAN #================================================= ynh_script_progression --message="Configuring Fail2Ban..." --weight=7 # Create a dedicated Fail2Ban config ynh_add_fail2ban_config --logpath="/var/log/auth.log" --failregex="Authentication (attempt for unknown user|failure for) .* from " --max_retry=5 #================================================= # SETUP SSOWAT #================================================= ynh_script_progression --message="Configuring permissions..." --weight=1 # Make app public if necessary if [ $is_public -eq 1 ] then # Everyone can access the app. # The "main" permission is automatically created before the install script. ynh_permission_update --permission="main" --add="visitors" fi #================================================= # RELOAD NGINX #================================================= ynh_script_progression --message="Reloading NGINX web server..." --weight=3 ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Installation of $app completed" --last