#!/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 password=$YNH_APP_ARG_PASSWORD is_public=$YNH_APP_ARG_IS_PUBLIC app=$YNH_APP_INSTANCE_NAME #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= ynh_print_info "Validating installation parameters..." final_path=/var/www/$app test ! -e "$final_path" || ynh_die "This path already contains a folder" # Normalize the url path syntax path_url=$(ynh_normalize_url_path $path_url) # Register (book) web path ynh_webpath_register $app $domain $path_url #================================================= # STORE SETTINGS FROM MANIFEST #================================================= ynh_print_info "Storing installation settings..." ynh_app_setting_set $app domain $domain ynh_app_setting_set $app path $path_url ynh_app_setting_set $app password $password #================================================= # CREATE A MYSQL DATABASE #================================================= ynh_print_info "Creating a MySQL database..." db_name=$(ynh_sanitize_dbid $app) ynh_app_setting_set $app db_name $db_name ynh_mysql_setup_db $db_name $db_name #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_print_info "Setting up source files..." ynh_app_setting_set $app final_path $final_path # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source "$final_path" #================================================= # NGINX CONFIGURATION #================================================= ynh_print_info "Configuring nginx web server..." # Create a dedicated nginx config ynh_add_nginx_config #================================================= # CREATE DEDICATED USER #================================================= ynh_print_info "Configuring system user..." # Create a system user ynh_system_user_create $app #================================================= # PHP-FPM CONFIGURATION #================================================= ynh_print_info "Configuring php-fpm..." # Create a dedicated php-fpm config ynh_add_fpm_config #================================================= # SPECIFIC SETUP #================================================= # Add cron job #================================================= ynh_print_info "Configuring a cron task..." # Path where crontab will be installed cron_path="/etc/cron.d/$app" # Copy crontab from package to Yunohost cp -a ../conf/cheky.cron "$cron_path" # Secure crontab chown root: "$cron_path" chmod 644 "$cron_path" # Configure crontab ynh_replace_string "__USER__" "$app" "$cron_path" ynh_replace_string "__FINALPATH__" "$final_path" "$cron_path" #================================================= # SETUP APPLICATION WITH CURL #================================================= # Set right permissions for curl install chown -R $app: $final_path # Set the app as temporarily public for curl call ynh_script_progression --message="Configuring SSOwat..." # Making the app public for curl ynh_permission_update --permission="main" --add="visitors" # Reload Nginx systemctl reload nginx # Installation with curl ynh_print_info "Finalizing installation..." # Get database password db_pwd=$(ynh_app_setting_get $app mysqlpwd) ynh_local_curl "/index.php?mod=install" "password=$password" "confirmPassword=$password" "type=db" "db[host]=localhost" "db[user]=$db_name" "db[password]=$db_pwd" "db[dbname]=$db_name" # Remove the public access ynh_permission_update --permission="main" --remove="visitors" #================================================= # GENERIC FINALIZATION #================================================= # SECURE FILES AND DIRECTORIES #================================================= # Set permissions to app files chown -R root: $final_path # Folders that needs to be writable by cheky chown -R $app: $final_path/var # requirement in official documentation chown -R $app: $final_path/static/media/annonce # needed for "Mes annonces sauvegardées" tab #================================================= # SETUP SSOWAT #================================================= ynh_print_info "Configuring SSOwat..." # Make app public if necessary if [ $is_public -eq 1 ] then ynh_permission_update --permission="main" --add="visitors" fi #================================================= # RELOAD NGINX #================================================= ynh_print_info "Reloading nginx web server..." systemctl reload nginx #================================================= # END OF SCRIPT #================================================= ynh_print_info "Installation of $app completed"