1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/shaarli_ynh.git synced 2024-09-03 20:26:10 +02:00
shaarli_ynh/scripts/install

192 lines
7.2 KiB
Text
Raw Normal View History

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
#=================================================
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-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
### 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-06-17 12:13:14 +02:00
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
2017-06-17 12:13:14 +02:00
#=================================================
ynh_print_info "Validating installation parameters..."
2017-06-17 12:13:14 +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
#=================================================
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
#=================================================
# 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
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
#=================================================
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
#=================================================
ynh_print_info "Configuring nginx web server..."
### `ynh_add_nginx_config` will use the file conf/nginx.conf
2018-06-25 05:57:41 +02:00
# Create a dedicated nginx config
ynh_add_nginx_config
2018-06-25 05:57:41 +02:00
#=================================================
# CREATE DEDICATED USER
#=================================================
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
2018-06-25 05:57:41 +02:00
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
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
2018-09-27 22:44:34 +02:00
#=================================================
# SETUP LOGROTATE
#=================================================
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"
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# set proper permissions
ynh_print_info "Set permissions..."
find $final_path -type f | xargs chmod 644
find $final_path -type d | xargs chmod 755
# Set right permissions for curl install
ynh_print_info "Set rights..."
chown -R $app: $final_path
2018-09-27 22:44:34 +02:00
#=================================================
# SETUP FAIL2BAN
#=================================================
ynh_print_info "Add Fail2Ban configuration..."
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
#=================================================
ynh_print_info "Configuring SSOwat..."
2018-06-25 05:57:41 +02:00
# Make app public if necessary
if [ $is_public -eq 1 ]
then
# 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
#=================================================
ynh_print_info "Reloading nginx web server..."
2018-06-25 05:57:41 +02:00
systemctl reload nginx
#=================================================
# END OF SCRIPT
#=================================================
ynh_print_info "Installation of $app completed"