#!/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_sftp=$YNH_APP_ARG_WITH_SFTP password=$YNH_APP_ARG_PASSWORD is_public=$YNH_APP_ARG_IS_PUBLIC with_mysql=$YNH_APP_ARG_WITH_MYSQL app=$YNH_APP_INSTANCE_NAME app_nb=$YNH_APP_INSTANCE_NUMBER #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE 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..." 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=is_public --value=$is_public ynh_app_setting_set --app=$app --key=with_mysql --value=$with_mysql ynh_app_setting_set --app=$app --key=with_sftp --value=$with_sftp ynh_app_setting_set --app=$app --key=final_path --value=$final_path ynh_app_setting_set --app=$app --key=overwrite_nginx --value=0 ynh_app_setting_set --app=$app --key=overwrite_phpfpm --value=1 ynh_app_setting_set --app=$app --key=admin_mail_html --value=1 #================================================= # STANDARD MODIFICATIONS #================================================= # CREATE A MYSQL DATABASE #================================================= if [ $with_mysql -eq 1 ] then ynh_script_progression --message="Creating a MySQL database..." --weight=2 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 fi #================================================= # NGINX CONFIGURATION #================================================= ynh_script_progression --message="Configuring nginx web server..." --weight=2 # Create a dedicated nginx config ynh_add_nginx_config #================================================= # CREATE DEDICATED USER #================================================= ynh_script_progression --message="Configuring system user..." ynh_system_user_create --username=$app --home_dir="$final_path" if [ $with_sftp -eq 1 ] then # Add the password to this user chpasswd <<< "${app}:${password}" ynh_app_setting_set --app=$app --key=password --value="$password" fi #================================================= # SPECIFIC SETUP #================================================= # CONFIGURE SSH #================================================= if [ $with_sftp -eq 1 ] then ynh_script_progression --message="Configuring ssh..." cp -R ../conf/ssh_regenconf_hook /usr/share/yunohost/hooks/conf_regen/90-ssh_$app ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file=/usr/share/yunohost/hooks/conf_regen/90-ssh_$app yunohost tools regen-conf ssh fi #================================================= # MODIFY A CONFIG FILE #================================================= mkdir -p "$final_path/www" if [ $with_sftp -eq 1 ] then ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file=../sources/www/index.html ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file=../sources/www/index.html # Copy files to the right place cp "../sources/www/index.html" "$final_path/www/index.html" else # Copy files to the right place cp "../sources/www/index_no_sftp.html" "$final_path/www/index.html" fi if [ $with_mysql -eq 1 ]; then # Store the database access echo -e "# MySQL Database name: ${db_name}\nuser: ${db_name}\npass: ${db_pwd}" > ../sources/db_access.txt # Copy files to the right place cp -r "../sources/db_access.txt" "$final_path/db_access.txt" fi #================================================= # PHP-FPM CONFIGURATION #================================================= ynh_script_progression --message="Configuring php-fpm..." --weight=2 # Create a dedicated php-fpm config ynh_add_fpm_config --usage=low --footprint=low #================================================= # GENERIC FINALIZATION #================================================= # SECURE FILES AND DIRECTORIES #================================================= chown -R $app: "$final_path" # Home directory of the user needs to be owned by root to allow # SFTP connections chown root: "$final_path" #================================================= # SETUP SSOWAT #================================================= ynh_script_progression --message="Configuring SSOwat..." # Make app public if necessary if [ $is_public -eq 1 ] then ynh_app_setting_set --app=$app --key=skipped_uris --value="/" fi #================================================= # RELOAD NGINX #================================================= ynh_script_progression --message="Reloading nginx web server..." ynh_systemd_action --service_name=nginx --action=reload #================================================= # SEND A README FOR THE ADMIN #================================================= # Get main domain and buid the url of the admin panel of the app. admin_panel="https://$(grep portal_domain /etc/ssowat/conf.json | cut -d'"' -f4)/yunohost/admin/#/apps/$app" if [ $with_mysql -eq 1 ] then sql_infos=" You've asked for a database, please find here the information about this SQL database. $(cat "$final_path/db_access.txt") " else sql_infos="" fi if [ $with_sftp -eq 1 ] then sftp_infos="You can connect to this repository by using sftp with the following credentials. Domain: $domain Port: $(grep "^Port" /etc/ssh/sshd_config | awk '{print $2}') User: $app Password: The one you set at installation." else sftp_infos="" fi echo "This app is simply a blank web app container. You have to put your own app inside. $sql_infos Please put your files into this directory: $final_path/www/ $sftp_infos You can configure this app easily by using the experimental __URL_TAG1__config-panel feature__URL_TAG2__$admin_panel/config-panel__URL_TAG3__. You can also find some specific actions for this app by using the experimental __URL_TAG1__action feature__URL_TAG2__$admin_panel/actions__URL_TAG3__. If you're facing an issue or want to improve this app, please open a new issue in this __URL_TAG1__project__URL_TAG2__https://github.com/YunoHost-Apps/my_webapp_ynh__URL_TAG3__." > mail_to_send ynh_send_readme_to_admin --app_message="mail_to_send" --recipients=root --type=install #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Installation of $app completed" --last