2013-12-19 03:02:51 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2018-06-25 05:57:41 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
|
|
|
|
2018-09-30 04:20:19 +02:00
|
|
|
ynh_clean_setup () {
|
|
|
|
### Remove this function if there's nothing to clean before calling the remove script.
|
|
|
|
true
|
|
|
|
}
|
2018-06-25 05:57:41 +02:00
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
2018-09-30 04:20:19 +02:00
|
|
|
|
2018-06-25 05:57:41 +02:00
|
|
|
#=================================================
|
|
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
|
|
#=================================================
|
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
|
|
|
path_url=$YNH_APP_ARG_PATH
|
|
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
|
|
|
|
2019-04-05 12:29:32 +02:00
|
|
|
### If it's a multi-instance app, meaning it can be installed several times independently
|
|
|
|
### The id of the app as stated in the manifest is available as $YNH_APP_ID
|
|
|
|
### The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...)
|
|
|
|
### The app instance name is available as $YNH_APP_INSTANCE_NAME
|
|
|
|
### - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample
|
|
|
|
### - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2
|
|
|
|
### - ynhexample__{N} for the subsequent installations, with N=3,4, ...
|
|
|
|
### The app instance name is probably what interests you most, since this is
|
|
|
|
### guaranteed to be unique. This is a good unique identifier to define installation path,
|
|
|
|
### db names, ...
|
2018-06-25 05:57:41 +02:00
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
2017-02-26 17:11:40 +01:00
|
|
|
|
2017-06-17 12:13:14 +02:00
|
|
|
#=================================================
|
2018-09-30 04:20:19 +02:00
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
2017-06-17 12:13:14 +02:00
|
|
|
#=================================================
|
2019-04-05 12:29:32 +02:00
|
|
|
ynh_print_info "Validating installation parameters..."
|
2017-06-17 12:13:14 +02:00
|
|
|
|
2018-09-30 04:20:19 +02:00
|
|
|
### If the app uses nginx as web server (written in HTML/PHP in most cases), the final path should be "/var/www/$app".
|
|
|
|
### If the app provides an internal web server (or uses another application server such as uwsgi), the final path should be "/opt/yunohost/$app"
|
2018-06-25 05:57:41 +02:00
|
|
|
final_path=/var/www/$app
|
|
|
|
test ! -e "$final_path" || ynh_die "This path already contains a folder"
|
|
|
|
|
|
|
|
# Register (book) web path
|
|
|
|
ynh_webpath_register $app $domain $path_url
|
|
|
|
|
2017-06-17 13:23:43 +02:00
|
|
|
|
2018-06-25 05:57:41 +02:00
|
|
|
#=================================================
|
|
|
|
# STORE SETTINGS FROM MANIFEST
|
|
|
|
#=================================================
|
2019-04-05 12:29:32 +02:00
|
|
|
ynh_print_info "Storing installation settings..."
|
2018-06-25 05:57:41 +02:00
|
|
|
|
|
|
|
ynh_app_setting_set $app domain $domain
|
|
|
|
ynh_app_setting_set $app path $path_url
|
|
|
|
ynh_app_setting_set $app is_public $is_public
|
2013-12-19 03:02:51 +01:00
|
|
|
|
|
|
|
|
2019-04-05 12:29:32 +02:00
|
|
|
#=================================================
|
|
|
|
# INSTALL DEPENDENCIES
|
|
|
|
#=================================================
|
|
|
|
ynh_print_info "Installing dependencies..."
|
|
|
|
|
|
|
|
### `ynh_install_app_dependencies` allows you to add any "apt" dependencies to the package.
|
|
|
|
### Those deb packages will be installed as dependencies of this package.
|
|
|
|
### If you're not using this helper:
|
|
|
|
### - Remove the section "REMOVE DEPENDENCIES" in the remove script
|
|
|
|
### - Remove the variable "pkg_dependencies" in _common.sh
|
|
|
|
### - As well as the section "REINSTALL DEPENDENCIES" in the restore script
|
|
|
|
### - And the section "UPGRADE DEPENDENCIES" in the upgrade script
|
2013-12-29 17:52:50 +01:00
|
|
|
|
2019-04-05 12:29:32 +02:00
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
2017-02-19 23:17:19 +01:00
|
|
|
|
2018-06-25 05:57:41 +02:00
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
2019-04-05 12:29:32 +02:00
|
|
|
ynh_print_info "Setting up source files..."
|
|
|
|
|
|
|
|
### `ynh_setup_source` is used to install an app from a zip or tar.gz file,
|
|
|
|
### downloaded from an upstream source, like a git repository.
|
|
|
|
### `ynh_setup_source` use the file conf/app.src
|
2018-06-25 05:57:41 +02:00
|
|
|
|
|
|
|
ynh_app_setting_set $app final_path $final_path
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
|
|
ynh_setup_source "$final_path"
|
2013-12-19 03:02:51 +01:00
|
|
|
|
2018-06-25 05:57:41 +02:00
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2019-04-05 12:29:32 +02:00
|
|
|
ynh_print_info "Configuring nginx web server..."
|
|
|
|
|
|
|
|
### `ynh_add_nginx_config` will use the file conf/nginx.conf
|
2017-02-26 17:11:40 +01:00
|
|
|
|
2018-06-25 05:57:41 +02:00
|
|
|
# Create a dedicated nginx config
|
|
|
|
ynh_add_nginx_config
|
2017-02-26 17:11:40 +01:00
|
|
|
|
2018-06-25 05:57:41 +02:00
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
2019-04-05 12:29:32 +02:00
|
|
|
ynh_print_info "Configuring system user..."
|
2013-12-19 03:02:51 +01:00
|
|
|
|
2018-06-25 05:57:41 +02:00
|
|
|
# Create a system user
|
|
|
|
ynh_system_user_create $app
|
2017-02-26 17:11:40 +01:00
|
|
|
|
2018-06-25 05:57:41 +02:00
|
|
|
#=================================================
|
|
|
|
# PHP-FPM CONFIGURATION
|
|
|
|
#=================================================
|
2019-04-05 12:29:32 +02:00
|
|
|
ynh_print_info "Configuring php-fpm..."
|
|
|
|
|
|
|
|
### `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 and conf/php-fpm.ini
|
|
|
|
### 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
|
2018-06-25 05:57:41 +02:00
|
|
|
|
|
|
|
# Create a dedicated php-fpm config
|
|
|
|
ynh_add_fpm_config
|
2013-12-19 03:02:51 +01:00
|
|
|
|
2017-02-27 16:52:17 +01:00
|
|
|
# set proper permissions
|
2019-04-05 12:29:32 +02:00
|
|
|
ynh_print_info "Set permissions..."
|
2019-05-22 09:59:07 +02:00
|
|
|
find $final_path -type f | xargs sudo chmod 644
|
|
|
|
find $final_path -type d | xargs sudo chmod 755
|
2018-06-25 05:57:41 +02:00
|
|
|
|
|
|
|
# Set right permissions for curl install
|
2019-04-05 12:29:32 +02:00
|
|
|
ynh_print_info "Set rights..."
|
2018-06-25 05:57:41 +02:00
|
|
|
chown -R $app: $final_path
|
|
|
|
|
2018-09-27 22:44:34 +02:00
|
|
|
#=================================================
|
|
|
|
# SETUP LOGROTATE
|
|
|
|
#=================================================
|
2019-04-05 12:29:32 +02:00
|
|
|
ynh_print_info "Configuring log rotation..."
|
2018-09-27 22:44:34 +02:00
|
|
|
|
|
|
|
### `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)
|
2019-09-26 14:21:49 +02:00
|
|
|
# We gotta create the file explicitly to avoid triggering https://github.com/YunoHost/issues/issues/1390
|
|
|
|
touch "$final_path/data/log.txt"
|
2018-09-27 22:44:34 +02:00
|
|
|
ynh_use_logrotate "$final_path/data/log.txt"
|
|
|
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP FAIL2BAN
|
|
|
|
#=================================================
|
2019-04-05 12:29:32 +02:00
|
|
|
ynh_print_info "Add Fail2Ban configuration..."
|
2019-07-22 16:27:12 +02:00
|
|
|
ynh_add_fail2ban_config_temp "$final_path/data/log.txt" "\s-\s<HOST>\s-\sLogin failed for user.*$" 5
|
2018-09-27 22:44:34 +02:00
|
|
|
|
2018-06-25 05:57:41 +02:00
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
2019-04-05 12:29:32 +02:00
|
|
|
ynh_print_info "Configuring SSOwat..."
|
2018-06-25 05:57:41 +02:00
|
|
|
|
|
|
|
# Make app public if necessary
|
|
|
|
if [ $is_public -eq 1 ]
|
|
|
|
then
|
2019-04-05 12:29:32 +02:00
|
|
|
# unprotected_uris allows SSO credentials to be passed anyway.
|
2018-06-25 05:57:41 +02:00
|
|
|
ynh_app_setting_set $app unprotected_uris "/"
|
|
|
|
fi
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2019-04-05 12:29:32 +02:00
|
|
|
ynh_print_info "Reloading nginx web server..."
|
2018-06-25 05:57:41 +02:00
|
|
|
|
|
|
|
systemctl reload nginx
|
2019-04-05 12:29:32 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_print_info "Installation of $app completed"
|