#!/bin/bash ### App file generated with YoloGen, the Yunohost app generator, version {{ data['GENERATOR_VERSION'] }}. {% if data.generator_mode == 'tutorial' -%} # This is the tutorial version of the app. # It contains extra commands to explain what should be done in case you want to adjust some part of the script. # Once you are done, you may remove them. {% endif %} #================================================= # GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers {% if data.generator_mode == 'tutorial' -%} # 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) # {% endif %} #================================================= # INSTALL DEPENDENCIES #================================================= {% if data.main_technology == "nodejs" -%} ynh_script_progression --message="Installing NodeJS..." --weight=10 # Install Nodejs ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version ynh_use_nodejs {% endif %} #================================================= # APP "BUILD" (DEPLOYING SOURCES, VENV, COMPILING ETC) #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression --message="Setting up source files..." {% if data.generator_mode == 'tutorial' -%} ### `ynh_setup_source` is used to install an app from a zip or tar.gz file, ### downloaded from an upstream source, as defined in the manifest.toml {% endif %} ynh_setup_source --dest_dir="$install_dir" {% if data.generator_mode == 'tutorial' -%} # $install_dir will automatically be initialized with some decent # permission by default ... however, you may need to recursively reapply # ownership to all files such as after the ynh_setup_source step {% endif %} chown -R $app:www-data "$install_dir" #================================================= # SYSTEM CONFIGURATION #================================================= ynh_script_progression --message="Adding system configurations related to $app..." {% if data.main_technology == "php" -%} # Create a dedicated PHP-FPM config # conf/extra_php-fpm.conf will be appended to the auto-generated config, which will go in /etc/php/X.Y/fpm/pool.d/ ynh_add_fpm_config {% endif %} # Create a dedicated NGINX config using the conf/nginx.conf template ynh_add_nginx_config {% if data.main_technology not in ["php", "none"] -%} {% if data.generator_mode == 'tutorial' -%} ### `ynh_systemd_config` is used to configure a systemd script for an app, using the conf/systemd.service template {% endif %} # Create a dedicated systemd config ynh_add_systemd_config {% if data.generator_mode == 'tutorial' -%} ### `yunohost service add` integrates a service in YunoHost. It then gets ### displayed in the admin interface and through the others `yunohost service` commands. {% endif %} yunohost service add $app --log="/var/log/$app/$app.log" {% if data.generator_mode == 'tutorial' -%} ### Additional options starting with 3.8: ### ### --needs_exposed_ports "$port" a list of ports that needs to be publicly exposed ### which will then be checked by YunoHost's diagnosis system ### (N.B. DO NOT USE THIS is the port is only internal!!!) ### ### --test_status "some command" a custom command to check the status of the service ### (only relevant if 'systemctl status' doesn't do a good job) ### ### --test_conf "some command" some command similar to "nginx -t" that validates the conf of the service ### ### Re-calling 'yunohost service add' during the upgrade script is the right way ### to proceed if you later realize that you need to enable some flags that ### weren't enabled on old installs (be careful it'll override the existing ### service though so you should re-provide all relevant flags when doing so) {% endif -%} {% endif %} {% if data.use_logrotate %} # Use logrotate to manage application logfile(s) ynh_use_logrotate {% endif %} {% if data.use_fail2ban -%} # Create a dedicated Fail2Ban config ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failregex="{{ data.fail2ban_regex }}" {% endif %} {% if data.use_cron -%} # Add cron job cron_path="/etc/cron.d/$app" ynh_add_config --template="../conf/task.cron" --destination="$cron_path" chown root: "$cron_path" chmod 644 "$cron_path" {% endif %} #================================================= # APP INITIAL CONFIGURATION #================================================= # ADD A CONFIGURATION #================================================= ynh_script_progression --message="Adding app's configuration file..." {% if data.generator_mode == 'tutorial' -%} ### 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. {% endif %} ynh_add_config --template="{{ data.custom_config_file }}" --destination="$install_dir/{{ data.custom_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/{{ data.custom_config_file }}" chown $app:$app "$install_dir/{{ data.custom_config_file }}" {% if data.generator_mode == 'tutorial' -%} ### 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" {% endif %} {% if data.install_snippet -%} #================================================= # INSTALL APP #================================================= ynh_script_progression --message="Installing app..." --weight=5 pushd $install_dir {{ data.install_snippet }} popd {% endif %} #================================================= # FINALIZE APP INSTALL WITH CURL #================================================= {% if data.generator_mode == 'tutorial' -%} ### Use these lines only if the app installation needs to be finalized through ### web forms. We generally don't want to ask the final user, ### so we're going to use curl to automatically fill the fields and submit the ### forms. {% endif %} # REMOVEME? ynh_script_progression --message="Finalizing installation..." # REMOVEME? ynh_local_curl "/INSTALL_PATH" "key1=value1" "key2=value2" "key3=value3" {% if data.main_technology not in ["php", "none"] -%} #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting app's systemd service..." # Start a systemd service ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" {% endif %} #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Installation of $app completed" --last