#!/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) is_public=$(ynh_app_setting_get $app is_public) port=$(ynh_app_setting_get $app port) always_encrypt=$(ynh_app_setting_get $app always_encrypt) final_path=$(ynh_app_setting_get $app final_path) secret=$(ynh_app_setting_get $app secret) overwrite_settings=$(ynh_app_setting_get $app overwrite_settings) overwrite_nginx=$(ynh_app_setting_get $app overwrite_nginx) overwrite_systemd=$(ynh_app_setting_get $app overwrite_systemd) # Optional parameters from config-panel feature antiflood=$(ynh_app_setting_get $app antiflood) delay=$(ynh_app_setting_get $app delay) #================================================= # 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 [ "${#final_path}" -eq 0 ] then # Si final_path n'est pas renseigné dans la config yunohost, cas d'ancien script, code final_path en dur final_path=/var/www/$app ynh_app_setting_set $app final_path $final_path fi if [ "$always_encrypt" = "Yes" ]; then ynh_app_setting_set $app always_encrypt 1 # Fixe always_encrypt en booléen always_encrypt=1 elif [ "$always_encrypt" = "No" ]; then ynh_app_setting_set $app always_encrypt 0 always_encrypt=0 fi # If overwrite_settings doesn't exist, create it if [ -z "$overwrite_settings" ]; then overwrite_settings=1 ynh_app_setting_set $app overwrite_settings $overwrite_settings fi # If overwrite_nginx doesn't exist, create it if [ -z "$overwrite_nginx" ]; then overwrite_nginx=1 ynh_app_setting_set $app overwrite_nginx $overwrite_nginx fi # If overwrite_systemd doesn't exist, create it if [ -z "$overwrite_systemd" ]; then overwrite_systemd=1 ynh_app_setting_set $app overwrite_systemd $overwrite_systemd fi # If secret doesn't exist, create it if [ -z "$secret" ]; then secret=$(grep "secrets *=>" "$final_path/lutim.conf" | cut -d\' -f2) ynh_app_setting_set $app secret $secret fi #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= # Backup the current version of the app ynh_backup_before_upgrade ynh_clean_setup () { # Nettoyage des résidus d'installation non pris en charge par le script remove. ynh_clean_check_starting # 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 #================================================= ynh_setup_source "$final_path" # Télécharge la source, décompresse et copie dans $final_path #================================================= # UPGRADE DEPENDENCIES #================================================= if [ "$upgrade_type" == "UPGRADE_APP" ] then ynh_install_app_dependencies $app_depencencies fi #================================================= # NGINX CONFIGURATION #================================================= # Overwrite the nginx configuration only if it's allowed if [ $overwrite_nginx -eq 1 ] then ynh_add_nginx_config fi #================================================= # CREATE DEDICATED USER #================================================= ynh_system_user_create $app # Create the dedicated user, if not exist #================================================= # SPECIFIC UPGRADE #================================================= # SETUP LUTIM #================================================= # Overwrite the settings config file only if it's allowed if [ $overwrite_settings -eq 1 ] then ## Copie et configuration du fichier de conf. ynh_backup_if_checksum_is_different "$final_path/lutim.conf" # Créé un backup du fichier de config si il a été modifié. cp ../conf/lutim.conf.template "$final_path/lutim.conf" ynh_replace_string "__DOMAIN__" "$domain" "$final_path/lutim.conf" ynh_replace_string "__PATH__" "$path_url" "$final_path/lutim.conf" ynh_replace_string "__PORT__" "$port" "$final_path/lutim.conf" ynh_replace_string "__ENCRYPT__" "$always_encrypt" "$final_path/lutim.conf" ynh_replace_string "__SECRET__" "$secret" "$final_path/lutim.conf" ynh_store_file_checksum "$final_path/lutim.conf" # Réenregistre la somme de contrôle du fichier de config # Optional parameters from config-panel feature if [ -n "$antiflood" ]; then ynh_replace_string ".*anti_flood_delay *=>.*" " anti_flood_delay => $antiflood," "$final_path/lutim.conf" # Disable anti_flood_delay if the delay is 0 if [ $antiflood = 0 ]; then ynh_replace_string "\(anti_flood_delay *=>.*\)" "#\1" "$final_path/lutim.conf" fi fi if [ -n "$delay" ]; then ynh_replace_string ".*default_delay *=>.*" " default_delay => $delay," "$final_path/lutim.conf" fi fi #================================================= # SETUP SYSTEMD #================================================= # Overwrite the systemd configuration only if it's allowed if [ $overwrite_systemd -eq 1 ] then ynh_add_systemd_config fi #================================================= # SETUP CRON #================================================= cp ../conf/cron_lutim /etc/cron.d/$app ynh_replace_string "__FINALPATH__" "$final_path/" /etc/cron.d/$app #================================================= # UPDATE LUTIM WITH CARTON #================================================= if [ "$upgrade_type" == "UPGRADE_APP" ] then (cd $final_path carton install 2>&1 | tee -a "/var/log/$app/setup_carton.log") fi #================================================= # SECURING FILES AND DIRECTORIES #================================================= chown -R $app: $final_path #================================================= # GENERIC FINALISATION #================================================= # SETUP LOGROTATE #================================================= ynh_use_logrotate --non-append chown $app -R /var/log/$app #================================================= # SETUP SSOWAT #================================================= ynh_app_setting_set $app skipped_uris "/" if [ $is_public -eq 0 ] then # Si l'app est privée, seul le visionnage des images reste public # Modifie le domaine pour qu'il passe dans une regex domain_regex=$(echo "$domain" | sed 's@-@.@g') ynh_app_setting_set $app protected_regex "$domain_regex$path_url/stats$","$domain_regex$path_url/manifest.webapp$","$domain_regex$path_url/$","$domain_regex$path_url/d/.*$","$domain_regex$path_url/m/.*$" fi #================================================= # RELOAD NGINX #================================================= ynh_system_reload --service_name=nginx #================================================= # START AND CHECK LUTIM BOOTING #================================================= # Wait for lutim fully started ynh_check_starting --line_to_match="Manager.*started" --app_log="/var/log/$app/production.log" --timeout="120" #================================================= # DEACTIVE MAINTENANCE MODE #================================================= ynh_maintenance_mode_OFF