2014-10-20 12:55:53 -04:00
#!/bin/bash
2015-10-27 11:03:21 -04:00
2017-06-02 12:23:51 -04:00
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2017-06-05 07:11:48 -04:00
source _common.sh
2017-06-02 12:23:51 -04:00
source /usr/share/yunohost/helpers
2024-01-10 17:52:57 -05:00
### 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,
2024-09-03 07:55:06 -04:00
### or 'example__2', '__3'... for multi-instance installs)
2021-03-17 11:32:11 -04:00
2023-06-08 11:27:51 -04:00
#=================================================
2023-07-24 10:11:17 -04:00
# INITIALIZE AND STORE SETTINGS
2023-06-08 11:27:51 -04:00
#=================================================
2023-07-24 10:11:17 -04:00
# If you need to, you can define custom settings
# (or remove this section entirely if not relevant for you)
foo="bar"
2024-06-20 17:49:43 -04:00
ynh_app_setting_set --key=foo --value=$foo
2023-06-08 11:27:51 -04:00
2017-06-02 12:23:51 -04:00
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
2024-06-20 17:49:43 -04:00
ynh_script_progression "Setting up source files..."
2017-06-02 12:23:51 -04:00
2018-06-28 16:05:35 -04:00
### `ynh_setup_source` is used to install an app from a zip or tar.gz file,
2018-07-01 03:57:16 -04:00
### downloaded from an upstream source, like a git repository.
2023-10-07 17:11:13 -04:00
### `ynh_setup_source` use the file manifest.toml
2018-06-28 16:05:35 -04:00
2023-10-07 17:11:13 -04:00
# Download, check integrity, uncompress and patch the source from manifest.toml
2023-01-30 13:10:14 -05:00
ynh_setup_source --dest_dir="$install_dir"
2024-01-10 17:52:57 -05:00
### $install_dir will automatically be initialized with some decent
2024-09-03 07:55:06 -04:00
### permission by default... however, you may need to recursively reapply
2024-01-10 17:52:57 -05:00
### ownership to all files such as after the ynh_setup_source step
2023-12-29 21:02:42 -05:00
chown -R "$app:www-data" "$install_dir"
2023-01-30 13:10:14 -05:00
2024-02-21 10:34:51 -05:00
#=================================================
# APP INITIAL CONFIGURATION
#=================================================
2024-06-20 17:49:43 -04:00
ynh_script_progression "Adding $app's configuration files..."
2024-02-21 10:34:51 -05:00
### 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
###
2024-06-20 17:49:43 -04:00
### ynh_config_add will also keep track of the config file's checksum,
2024-02-21 10:34:51 -05:00
### which later during upgrade may allow to automatically backup the config file
### if it's found that the file was manually modified
###
2024-06-20 17:49:43 -04:00
### Check the documentation of `ynh_config_add` for more info.
2024-02-21 10:34:51 -05:00
2024-11-07 04:32:23 -05:00
ynh_config_add --template="run.sh" --destination="$install_dir/run.sh"
2024-02-21 10:34:51 -05:00
# 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,
2024-06-20 17:49:43 -04:00
### you shoud rely on ynh_replace (which is basically a wrapper for sed)
2024-02-21 10:34:51 -05:00
### When doing so, you also need to manually call ynh_store_file_checksum
###
2024-06-20 17:49:43 -04:00
### ynh_replace --match="match_string" --replace="replace_string" --file="$install_dir/some_config_file"
### ynh_store_file_checksum "$install_dir/some_config_file"
2024-02-21 10:34:51 -05:00
2017-06-02 12:23:51 -04:00
#=================================================
2023-01-30 13:10:14 -05:00
# SYSTEM CONFIGURATION
2017-06-02 12:23:51 -04:00
#=================================================
2024-06-20 17:49:43 -04:00
ynh_script_progression "Adding system configurations related to $app..."
2017-06-02 12:23:51 -04:00
2024-06-20 17:49:43 -04:00
### `ynh_config_add_phpfpm` is used to set up a PHP config.
2018-07-01 03:57:16 -04:00
### You can remove it if your app doesn't use PHP.
2024-06-20 17:49:43 -04:00
### `ynh_config_add_phpfpm` will use the files conf/extra_php-fpm.conf
2018-06-28 16:05:35 -04:00
### If you're not using these lines:
2024-01-10 17:34:28 -05:00
### - 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
2018-06-28 16:05:35 -04:00
2023-01-30 13:10:14 -05:00
# Create a dedicated NGINX config using the conf/nginx.conf template
2024-06-20 17:49:43 -04:00
ynh_config_add_nginx
2022-05-30 19:56:33 -04:00
2024-09-03 08:19:18 -04:00
### `ynh_config_add_systemd` is used to configure a systemd script for an app.
2023-01-30 13:10:14 -05:00
### It can be used for apps that use sysvinit (with adaptation) or systemd.
### Have a look at the app to be sure this app needs a systemd script.
2024-09-03 08:19:18 -04:00
### `ynh_config_add_systemd` will use the file conf/systemd.service
2023-01-30 13:10:14 -05:00
### If you're not using these lines:
2024-01-10 17:34:28 -05:00
### - You can remove those files in conf/.
### - Remove the section "BACKUP SYSTEMD" in the backup script
### - Remove also the section "STOP AND REMOVE SERVICE" in the remove script
### - As well as the section "RESTORE SYSTEMD" in the restore script
### - And the section "SETUP SYSTEMD" in the upgrade script
2017-06-02 12:23:51 -04:00
2023-01-30 13:10:14 -05:00
# Create a dedicated systemd config
2024-06-20 17:49:43 -04:00
ynh_config_add_systemd
2021-04-29 14:58:35 -04:00
2023-01-30 13:10:14 -05:00
### `yunohost service add` integrates a service in YunoHost. It then gets
### displayed in the admin interface and through the others `yunohost service` commands.
### (N.B.: this line only makes sense if the app adds a service to the system!)
2021-04-29 14:58:35 -04:00
### If you're not using these lines:
2024-01-10 17:34:28 -05:00
### - You can remove these files in conf/.
### - Remove the section "REMOVE SERVICE INTEGRATION IN YUNOHOST" in the remove script
### - As well as the section "INTEGRATE SERVICE IN YUNOHOST" in the restore script
### - And the section "INTEGRATE SERVICE IN YUNOHOST" in the upgrade script
2023-01-30 13:10:14 -05:00
### 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
2023-09-13 05:08:42 -04:00
### (N.B. DO NOT USE THIS if the port is only internal!!!)
2023-01-30 13:10:14 -05:00
###
### --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)
2024-11-07 04:30:44 -05:00
yunohost service add "$app" --description="A modern and self-hosted take on file uploading services that can handle anything you throw at it thanks to it's robust and fast API, chunked uploads support and more." --log="/var/log/$app/$app.log"
2021-04-29 14:58:35 -04:00
2024-06-20 17:49:43 -04:00
### `ynh_config_add_logrotate` is used to configure a logrotate configuration for the logs of this app.
2023-01-30 13:10:14 -05:00
### Use this helper only if there is effectively a log file for this app.
### If you're not using this helper:
2024-01-10 17:34:28 -05:00
### - 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
2021-04-29 14:58:35 -04:00
2023-01-30 13:10:14 -05:00
# Use logrotate to manage application logfile(s)
2024-06-20 17:49:43 -04:00
ynh_config_add_logrotate
2021-04-29 14:58:35 -04:00
2023-01-30 13:10:14 -05:00
# Create a dedicated Fail2Ban config
2024-06-20 17:49:43 -04:00
ynh_config_add_fail2ban --logpath="/var/log/nginx/${domain}-error.log" --failregex="Regex to match into the log for a failed login"
2021-04-29 14:58:35 -04:00
2017-06-02 12:23:51 -04:00
#=================================================
2017-06-17 11:49:26 -04:00
# SETUP APPLICATION WITH CURL
2017-06-02 12:23:51 -04:00
#=================================================
2018-07-01 03:57:16 -04:00
### 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.
2018-06-28 16:05:35 -04:00
2017-06-02 12:23:51 -04:00
# Installation with curl
2024-06-20 17:49:43 -04:00
ynh_script_progression "Finalizing installation..."
2024-11-07 04:30:44 -05:00
#ynh_local_curl "/INSTALL_PATH" "key1=value1" "key2=value2" "key3=value3"
2017-06-02 12:23:51 -04:00
#=================================================
2019-05-02 14:44:22 -04:00
# START SYSTEMD SERVICE
#=================================================
2024-06-20 17:49:43 -04:00
ynh_script_progression "Starting $app's systemd service..."
2019-05-02 14:44:22 -04:00
2024-06-20 17:49:43 -04:00
### `ynh_systemctl` is used to start a systemd service for an app.
2019-05-02 14:44:22 -04:00
### Only needed if you have configure a systemd service
### If you're not using these lines:
2024-01-10 17:34:28 -05:00
### - Remove the section "STOP SYSTEMD SERVICE" and "START SYSTEMD SERVICE" in the backup script
### - As well as the section "START SYSTEMD SERVICE" in the restore script
### - As well as the section"STOP SYSTEMD SERVICE" and "START SYSTEMD SERVICE" in the upgrade script
### - And the section "STOP SYSTEMD SERVICE" and "START SYSTEMD SERVICE" in the change_url script
2019-05-02 14:44:22 -04:00
# Start a systemd service
2024-06-20 17:49:43 -04:00
ynh_systemctl --service="$app" --action="start"
2019-05-02 14:44:22 -04:00
2019-02-10 09:02:38 -05:00
#=================================================
# END OF SCRIPT
#=================================================
2024-06-20 17:49:43 -04:00
ynh_script_progression "Installation of $app completed"