#!/bin/bash #================================================= # GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers # Install parameters are automatically saved as settings # # Settings are automatically loaded as bash variables # in every app script context, therefore typically these will exist: # - $domain # - $path # - $language # ... etc # # Resources defined in the manifest are provisioned prior to this script # and corresponding settings are also available, such as: # - $install_dir # - $port # - $db_name # ... # # $app is the app id (i.e. 'example' for first install, # or 'example__2', '__3', ... for multi-instance installs) # #================================================= # APP "BUILD" (DEPLOYING SOURCES, VENV, COMPILING ETC) #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression --message="Setting up source files..." --weight=1 # Download, check integrity, uncompress and patch the source ynh_setup_source --dest_dir="$install_dir" # Let's copy the webapp in the public directory cp -R $install_dir/app/dist/* $install_dir/public/ ynh_script_progression --message="Pulling in external libraries with Composer..." pushd $install_dir/api /usr/bin/php$phpversion bin/composer install popd chown -R $app:www-data "$install_dir" #================================================= # SYSTEM CONFIGURATION #================================================= ynh_script_progression --message="Adding system configurations related to $app..." --weight=1 ### `ynh_add_fpm_config` is used to set up a PHP config. ### You can remove it if your app doesn't use PHP. ### `ynh_add_fpm_config` will use the files conf/php-fpm.conf ### If you're not using these lines: ### - You can remove these files in conf/. ### - Remove the section "BACKUP THE PHP-FPM CONFIGURATION" in the backup script ### - Remove also the section "REMOVE PHP-FPM CONFIGURATION" in the remove script ### - As well as the section "RESTORE THE PHP-FPM CONFIGURATION" in the restore script ### with the reload at the end of the script. ### - And the section "PHP-FPM CONFIGURATION" in the upgrade script # Create a dedicated PHP-FPM config using the conf/php-fpm.conf or conf/extra_php-fpm.conf ynh_add_fpm_config # Create a dedicated NGINX config using the conf/nginx.conf template ynh_add_nginx_config ### `ynh_use_logrotate` is used to configure a logrotate configuration for the logs of this app. ### Use this helper only if there is effectively a log file for this app. ### If you're not using this helper: ### - Remove the section "BACKUP LOGROTATE" in the backup script ### - Remove also the section "REMOVE LOGROTATE CONFIGURATION" in the remove script ### - As well as the section "RESTORE THE LOGROTATE CONFIGURATION" in the restore script ### - And the section "SETUP LOGROTATE" in the upgrade script # Use logrotate to manage application logfile(s) # ynh_use_logrotate # Create a dedicated Fail2Ban config ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failregex="Regex to match into the log for a failed login" #================================================= # APP INITIAL CONFIGURATION #================================================= # ADD A CONFIGURATION #================================================= # ynh_script_progression --message="Adding a configuration file..." --weight=1 ### You can add specific configuration files. ### ### Typically, put your template conf file in ../conf/your_config_file ### The template may contain strings such as __FOO__ or __FOO_BAR__, ### which will automatically be replaced by the values of $foo and $foo_bar ### ### ynh_add_config will also keep track of the config file's checksum, ### which later during upgrade may allow to automatically backup the config file ### if it's found that the file was manually modified ### ### Check the documentation of `ynh_add_config` for more info. # ynh_add_config --template="some_config_file" --destination="$install_dir/some_config_file" # FIXME: this should be handled by the core in the future # You may need to use chmod 600 instead of 400, # for example if the app is expected to be able to modify its own config # chmod 400 "$install_dir/some_config_file" # chown $app:$app "$install_dir/some_config_file" ### For more complex cases where you want to replace stuff using regexes, ### you shoud rely on ynh_replace_string (which is basically a wrapper for sed) ### When doing so, you also need to manually call ynh_store_file_checksum ### ### ynh_replace_string --match_string="match_string" --replace_string="replace_string" --target_file="$install_dir/some_config_file" ### ynh_store_file_checksum --file="$install_dir/some_config_file" # DATABASE ynh_script_progression --message="Initialiazing the database..." --weight=1 /usr/bin/php$phpversion $install_dir/api/bin/console zusam:init usermail@example.com my_group_name my_password chown -R $app:www-data $install_dir #================================================= # GENERIC FINALIZATION #================================================= ynh_add_config --template="../conf/cronjob" --destination="/etc/cron.d/$app" chown root: "/etc/cron.d/$app" chmod 644 "/etc/cron.d/$app" #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Installation of $app completed" --last