|
|
|
@ -46,7 +46,15 @@ app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
#=================================================
|
|
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
|
|
|
|
#=================================================
|
|
|
|
|
ynh_print_info --message="Validating installation parameters..."
|
|
|
|
|
### About --weight and --time
|
|
|
|
|
### ynh_script_progression will show to your final users the progression of each scripts.
|
|
|
|
|
### In order to do that, --weight will represent the relative time of execution compared to the other steps in the script.
|
|
|
|
|
### --time is a packager option, it will show you the execution time since the previous call.
|
|
|
|
|
### This option should be removed before releasing your app.
|
|
|
|
|
### Use the execution time, given by --time, to estimate the weight of a step.
|
|
|
|
|
### A common way to do it is to set a weight equal to the execution time in second +1.
|
|
|
|
|
### The execution time is given for the duration since the previous call. So the weight should be applied to this previous call.
|
|
|
|
|
ynh_script_progression --message="Validating installation parameters..." --time --weight=1
|
|
|
|
|
|
|
|
|
|
### 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"
|
|
|
|
@ -59,7 +67,7 @@ ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
|
|
|
|
|
#=================================================
|
|
|
|
|
# STORE SETTINGS FROM MANIFEST
|
|
|
|
|
#=================================================
|
|
|
|
|
ynh_print_info --message="Storing installation settings..."
|
|
|
|
|
ynh_script_progression --message="Storing installation settings..." --time --weight=1
|
|
|
|
|
|
|
|
|
|
ynh_app_setting_set --app=$app --key=domain --value=$domain
|
|
|
|
|
ynh_app_setting_set --app=$app --key=path --value=$path_url
|
|
|
|
@ -72,7 +80,7 @@ ynh_app_setting_set --app=$app --key=language --value=$language
|
|
|
|
|
#=================================================
|
|
|
|
|
# FIND AND OPEN A PORT
|
|
|
|
|
#=================================================
|
|
|
|
|
ynh_print_info --message="Configuring firewall..."
|
|
|
|
|
ynh_script_progression --message="Configuring firewall..." --time --weight=1
|
|
|
|
|
|
|
|
|
|
### Use these lines if you have to open a port for the application
|
|
|
|
|
### `ynh_find_port` will find the first available port starting from the given port.
|
|
|
|
@ -88,7 +96,7 @@ ynh_app_setting_set --app=$app --key=port --value=$port
|
|
|
|
|
#=================================================
|
|
|
|
|
# INSTALL DEPENDENCIES
|
|
|
|
|
#=================================================
|
|
|
|
|
ynh_print_info --message="Installing dependencies..."
|
|
|
|
|
ynh_script_progression --message="Installing dependencies..." --time --weight=1
|
|
|
|
|
|
|
|
|
|
### `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.
|
|
|
|
@ -103,7 +111,7 @@ ynh_install_app_dependencies $pkg_dependencies
|
|
|
|
|
#=================================================
|
|
|
|
|
# CREATE A MYSQL DATABASE
|
|
|
|
|
#=================================================
|
|
|
|
|
ynh_print_info --message="Creating a MySQL database..."
|
|
|
|
|
ynh_script_progression --message="Creating a MySQL database..." --time --weight=1
|
|
|
|
|
|
|
|
|
|
### Use these lines if you need a database for the application.
|
|
|
|
|
### `ynh_mysql_setup_db` will create a database, an associated user and a ramdom password.
|
|
|
|
@ -121,7 +129,7 @@ ynh_mysql_setup_db --db_user=$db_name --db_name=$db_name
|
|
|
|
|
#=================================================
|
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
|
#=================================================
|
|
|
|
|
ynh_print_info --message="Setting up source files..."
|
|
|
|
|
ynh_script_progression --message="Setting up source files..." --time --weight=1
|
|
|
|
|
|
|
|
|
|
### `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.
|
|
|
|
@ -134,7 +142,7 @@ ynh_setup_source --dest_dir="$final_path"
|
|
|
|
|
#=================================================
|
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
|
#=================================================
|
|
|
|
|
ynh_print_info --message="Configuring nginx web server..."
|
|
|
|
|
ynh_script_progression --message="Configuring nginx web server..." --time --weight=1
|
|
|
|
|
|
|
|
|
|
### `ynh_add_nginx_config` will use the file conf/nginx.conf
|
|
|
|
|
|
|
|
|
@ -144,7 +152,7 @@ ynh_add_nginx_config
|
|
|
|
|
#=================================================
|
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
|
#=================================================
|
|
|
|
|
ynh_print_info --message="Configuring system user..."
|
|
|
|
|
ynh_script_progression --message="Configuring system user..." --time --weight=1
|
|
|
|
|
|
|
|
|
|
# Create a system user
|
|
|
|
|
ynh_system_user_create --username=$app
|
|
|
|
@ -152,7 +160,7 @@ ynh_system_user_create --username=$app
|
|
|
|
|
#=================================================
|
|
|
|
|
# PHP-FPM CONFIGURATION
|
|
|
|
|
#=================================================
|
|
|
|
|
ynh_print_info --message="Configuring php-fpm..."
|
|
|
|
|
ynh_script_progression --message="Configuring php-fpm..." --time --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.
|
|
|
|
@ -177,7 +185,7 @@ ynh_add_fpm_config
|
|
|
|
|
#=================================================
|
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
|
#=================================================
|
|
|
|
|
ynh_print_info --message="Configuring a systemd service..."
|
|
|
|
|
ynh_script_progression --message="Configuring a systemd service..." --time --weight=1
|
|
|
|
|
|
|
|
|
|
### `ynh_systemd_config` is used to configure a systemd script for an app.
|
|
|
|
|
### It can be used for apps that use sysvinit (with adaptation) or systemd.
|
|
|
|
@ -206,16 +214,16 @@ ynh_add_systemd_config
|
|
|
|
|
chown -R $app: $final_path
|
|
|
|
|
|
|
|
|
|
# Set the app as temporarily public for curl call
|
|
|
|
|
ynh_print_info --message="Configuring SSOwat..."
|
|
|
|
|
ynh_script_progression --message="Configuring SSOwat..." --time --weight=1
|
|
|
|
|
ynh_app_setting_set --app=$app --key=skipped_uris --value="/"
|
|
|
|
|
# Reload SSOwat config
|
|
|
|
|
yunohost app ssowatconf
|
|
|
|
|
|
|
|
|
|
# Reload Nginx
|
|
|
|
|
systemctl reload nginx
|
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
|
|
|
|
|
|
# Installation with curl
|
|
|
|
|
ynh_print_info --message="Finalizing installation..."
|
|
|
|
|
ynh_script_progression --message="Finalizing installation..." --time --weight=1
|
|
|
|
|
ynh_local_curl "/INSTALL_PATH" "key1=value1" "key2=value2" "key3=value3"
|
|
|
|
|
|
|
|
|
|
# Remove the public access
|
|
|
|
@ -260,7 +268,7 @@ chown -R root: $final_path
|
|
|
|
|
#=================================================
|
|
|
|
|
# SETUP LOGROTATE
|
|
|
|
|
#=================================================
|
|
|
|
|
ynh_print_info --message="Configuring log rotation..."
|
|
|
|
|
ynh_script_progression --message="Configuring log rotation..." --time --weight=1
|
|
|
|
|
|
|
|
|
|
### `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.
|
|
|
|
@ -289,10 +297,18 @@ yunohost service add $app --log "/var/log/$app/$app.log"
|
|
|
|
|
# if using yunohost version 3.2 or more in the 'manifest.json', a description can be added
|
|
|
|
|
#yunohost service add $app --description "$app daemon for XXX" --log "/var/log/$app/$app.log"
|
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
|
# SETUP FAIL2BAN
|
|
|
|
|
#=================================================
|
|
|
|
|
ynh_script_progression --message="Configuring fail2ban..." --time --weight=1
|
|
|
|
|
|
|
|
|
|
# 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"
|
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
|
# SETUP SSOWAT
|
|
|
|
|
#=================================================
|
|
|
|
|
ynh_print_info --message="Configuring SSOwat..."
|
|
|
|
|
ynh_script_progression --message="Configuring SSOwat..." --time --weight=1
|
|
|
|
|
|
|
|
|
|
# Make app public if necessary
|
|
|
|
|
if [ $is_public -eq 1 ]
|
|
|
|
@ -304,12 +320,12 @@ fi
|
|
|
|
|
#=================================================
|
|
|
|
|
# RELOAD NGINX
|
|
|
|
|
#=================================================
|
|
|
|
|
ynh_print_info --message="Reloading nginx web server..."
|
|
|
|
|
ynh_script_progression --message="Reloading nginx web server..." --time --weight=1
|
|
|
|
|
|
|
|
|
|
systemctl reload nginx
|
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
|
# END OF SCRIPT
|
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
|
|
ynh_print_info --message="Installation of $app completed"
|
|
|
|
|
ynh_script_progression --message="Installation of $app completed" --time --last
|
|
|
|
|