mirror of
https://github.com/YunoHost-Apps/yunorunner_ynh.git
synced 2024-09-03 20:36:13 +02:00
166 lines
4.9 KiB
Bash
166 lines
4.9 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC STARTING
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
# Load common variables for all scripts.
|
|
source _variables
|
|
|
|
#=================================================
|
|
# LOAD SETTINGS
|
|
#=================================================
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
domain=$(ynh_app_setting_get $app domain)
|
|
path_url=$(ynh_app_setting_get $app path)
|
|
admin=$(ynh_app_setting_get $app admin)
|
|
is_public=$(ynh_app_setting_get $app is_public)
|
|
final_path=$(ynh_app_setting_get $app final_path)
|
|
port=$(ynh_app_setting_get $app port)
|
|
db_name=$(ynh_app_setting_get $app db_name)
|
|
|
|
#=================================================
|
|
# CHECK VERSION
|
|
#=================================================
|
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
|
|
|
#=================================================
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
#=================================================
|
|
|
|
if [ "$is_public" = "Yes" ]; then
|
|
ynh_app_setting_set $app is_public 1 # Fixe is_public en booléen
|
|
is_public=1
|
|
elif [ "$is_public" = "No" ]; then
|
|
ynh_app_setting_set $app is_public 0
|
|
is_public=0
|
|
fi
|
|
|
|
if [ -z $db_name ]; then # Si db_name n'est pas renseigné dans app setting
|
|
db_name=$(ynh_sanitize_dbid $app)
|
|
ynh_app_setting_set $app db_name $db_name
|
|
fi
|
|
|
|
#=================================================
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
#=================================================
|
|
|
|
# Backup the current version of the app
|
|
ynh_backup_before_upgrade
|
|
ynh_clean_setup () {
|
|
# restore it if the upgrade fails
|
|
ynh_restore_upgradebackup
|
|
}
|
|
# Exit if an error occurs during the execution of the script
|
|
ynh_abort_if_errors
|
|
|
|
#=================================================
|
|
# CHECK THE PATH
|
|
#=================================================
|
|
|
|
path_url=$(ynh_normalize_url_path $path_url) # Vérifie et corrige la syntaxe du path.
|
|
|
|
#=================================================
|
|
# ACTIVATE MAINTENANCE MODE
|
|
#=================================================
|
|
|
|
ynh_maintenance_mode_ON
|
|
|
|
#=================================================
|
|
# STANDARD UPGRADE STEPS
|
|
#=================================================
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
#=================================================
|
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
|
then
|
|
ynh_setup_source "$final_path" # Télécharge la source, décompresse et copie dans $final_path
|
|
fi
|
|
|
|
#=================================================
|
|
# NGINX CONFIGURATION
|
|
#=================================================
|
|
|
|
ynh_add_nginx_config
|
|
|
|
#=================================================
|
|
# CREATE DEDICATED USER
|
|
#=================================================
|
|
|
|
ynh_system_user_create $app # Create the dedicated user, if not exist
|
|
|
|
#=================================================
|
|
# PHP-FPM CONFIGURATION
|
|
#=================================================
|
|
|
|
ynh_add_fpm_config # Créer le fichier de configuration du pool php-fpm et le configure.
|
|
|
|
#=================================================
|
|
# SPECIFIC UPGRADE
|
|
#=================================================
|
|
# ...
|
|
#=================================================
|
|
|
|
# Copie ou modification d'un fichier de config
|
|
ynh_backup_if_checksum_is_different "$final_path/CONFIG_FILE" # Créé un backup du fichier de config si il a été modifié.
|
|
ynh_store_file_checksum "$final_path/CONFIG_FILE" # Réenregistre la somme de contrôle du fichier de config
|
|
|
|
#=================================================
|
|
# SETUP LOGROTATE
|
|
#=================================================
|
|
|
|
ynh_use_logrotate --non-append
|
|
|
|
#=================================================
|
|
# SETUP SYSTEMD
|
|
#=================================================
|
|
|
|
ynh_add_systemd_config
|
|
|
|
#=================================================
|
|
# GENERIC FINALISATION
|
|
#=================================================
|
|
# UPGRADE FAIL2BAN
|
|
#=================================================
|
|
|
|
ynh_add_fail2ban_config "/var/log/nginx/${domain}-error.log" "PHP message: Leed: wrong login for .* client: <HOST>" 5
|
|
|
|
#=================================================
|
|
# SECURING FILES AND DIRECTORIES
|
|
#=================================================
|
|
|
|
# Les fichiers appartiennent à root
|
|
chown -R root: $final_path
|
|
|
|
#=================================================
|
|
# SETUP SSOWAT
|
|
#=================================================
|
|
|
|
if [ $is_public -eq 0 ]
|
|
then # Retire l'accès public
|
|
ynh_app_setting_delete $app skipped_uris
|
|
fi
|
|
# Make app public if necessary
|
|
if [ $is_public -eq 1 ]
|
|
then
|
|
ynh_app_setting_set $app skipped_uris "/"
|
|
fi
|
|
|
|
#=================================================
|
|
# RELOAD NGINX
|
|
#=================================================
|
|
|
|
ynh_system_reload --service_name=nginx
|
|
|
|
#=================================================
|
|
# DEACTIVE MAINTENANCE MODE
|
|
#=================================================
|
|
|
|
ynh_maintenance_mode_OFF
|