#!/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_sftp=$YNH_APP_ARG_WITH_SFTP #REMOVEME? password=$YNH_APP_ARG_PASSWORD #REMOVEME? is_public=$YNH_APP_ARG_IS_PUBLIC #REMOVEME? phpversion=$YNH_APP_ARG_PHPVERSION #REMOVEME? with_mysql=$YNH_APP_ARG_WITH_MYSQL #REMOVEME? app=$YNH_APP_INSTANCE_NAME app_nb=$YNH_APP_INSTANCE_NUMBER #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= #REMOVEME? ynh_script_progression --message="Validating installation parameters..." --weight=2 #REMOVEME? install_dir=/var/www/$app #REMOVEME? test ! -e "$install_dir" || ynh_die --message="This path already contains a folder" [ $with_sftp -eq 0 ] || [ "$password" != "" ] || ynh_die --message="You need to set a password to enable SFTP" # 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..." #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_mysql --value=$with_mysql ynh_app_setting_set --app=$app --key=with_sftp --value=$with_sftp #REMOVEME? ynh_app_setting_set --app=$app --key=password --value="$password" #REMOVEME? ynh_app_setting_set --app=$app --key=install_dir --value=$install_dir ynh_app_setting_set --app=$app --key=phpversion --value=$phpversion #REMOVEME? ynh_app_setting_set --app=$app --key=admin_mail_html --value=1 #================================================= # STANDARD MODIFICATIONS #================================================= # INSTALL DEPENDENCIES #================================================= if [ $phpversion != "none" ] then #REMOVEME? ynh_script_progression --message="Installing dependencies..." --weight=2 #REMOVEME? ynh_install_app_dependencies "php${phpversion}-fpm" fi #================================================= # CREATE A MYSQL DATABASE #================================================= if [ $with_mysql -eq 1 ] then #REMOVEME? ynh_script_progression --message="Creating a MySQL database..." --weight=2 #REMOVEME? ynh_install_app_dependencies "php${phpversion}-mysql" db_name=$(ynh_sanitize_dbid --db_name=$app) #REMOVEME? ynh_app_setting_set --app=$app --key=db_name --value=$db_name #REMOVEME? 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 # Prepare nginx.conf if [ $phpversion != "none" ] then cp ../conf/nginx{_with_php,}.conf YNH_PHP_VERSION="$phpversion" else cp ../conf/nginx{_no_php,}.conf fi # Create a dedicated NGINX config ynh_add_nginx_config #================================================= # CREATE DEDICATED USER #================================================= #REMOVEME? ynh_script_progression --message="Configuring system user..." if [ $with_sftp -eq 1 ] then groups="sftp.app" else groups="" fi #REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir" --groups="$groups" if [ $with_sftp -eq 1 ] then # Add the password to this user chpasswd <<< "${app}:${password}" fi #================================================= # SPECIFIC SETUP #================================================= # MODIFY A CONFIG FILE #================================================= mkdir -p "$install_dir/www" if [ $with_sftp -eq 1 ] then ynh_add_config --template="../sources/www/index.html" --destination="$install_dir/www/index.html" else # Copy files to the right place cp "../sources/www/index_no_sftp.html" "$install_dir/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" "$install_dir/db_access.txt" fi chown -R $app:www-data "$install_dir" # Home directory of the user needs to be owned by root to allow # SFTP connections chown root:root "$install_dir" setfacl -m g:$app:r-x "$install_dir" setfacl -m g:www-data:r-x "$install_dir" chmod 750 "$install_dir" #================================================= # PHP-FPM CONFIGURATION #================================================= if [ $phpversion != "none" ] then ynh_script_progression --message="Configuring PHP-FPM..." --weight=2 fpm_footprint="low" fpm_free_footprint=0 fpm_usage="low" 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 # Create a dedicatedPHP-FPM config ynh_add_fpm_config --usage=$fpm_usage --footprint=$fpm_footprint --phpversion=$phpversion else # This is needed for the config panel to work even though PHP is not actually used ynh_app_setting_set --app=$app --key=fpm_footprint --value=low ynh_app_setting_set --app=$app --key=fpm_usage --value=low ynh_app_setting_set --app=$app --key=fpm_free_footprint --value=0 fi #================================================= # GENERIC FINALIZATION #================================================= # SETUP SSOWAT #================================================= #REMOVEME? ynh_script_progression --message="Configuring permissions..." # Make app public if necessary #REMOVEME? if [ $is_public -eq 1 ] then #REMOVEME? ynh_permission_update --permission="main" --add="visitors" fi #================================================= # RELOAD NGINX #================================================= #REMOVEME? ynh_script_progression --message="Reloading NGINX web server..." #REMOVEME? 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 "$install_dir/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: $install_dir/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