2015-03-16 21:10:39 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-03-19 19:16:10 +01:00
|
|
|
#=================================================
|
|
|
|
# GENERIC STARTING
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
2016-06-15 23:56:45 +02:00
|
|
|
|
2017-03-21 00:44:14 +01:00
|
|
|
source _common.sh
|
2016-12-14 16:10:00 +01:00
|
|
|
source /usr/share/yunohost/helpers
|
2017-12-05 19:36:40 +01:00
|
|
|
# Load common variables for all scripts.
|
|
|
|
source _variables
|
|
|
|
source _apt
|
2016-12-14 16:10:00 +01:00
|
|
|
|
2017-03-19 19:16:10 +01:00
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
2016-12-14 16:10:00 +01:00
|
|
|
domain=$(ynh_app_setting_get $app domain)
|
2017-03-19 19:16:10 +01:00
|
|
|
path_url=$(ynh_app_setting_get $app path)
|
2016-12-14 16:10:00 +01:00
|
|
|
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)
|
2015-03-16 21:10:39 +01:00
|
|
|
|
2017-12-16 23:22:54 +01:00
|
|
|
#=================================================
|
|
|
|
# CHECK VERSION
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_abort_if_up_to_date
|
|
|
|
|
2017-03-19 19:16:10 +01:00
|
|
|
#=================================================
|
|
|
|
# FIX OLD THINGS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2016-03-31 23:26:35 +02:00
|
|
|
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
|
2017-05-24 16:48:26 +02:00
|
|
|
ynh_app_setting_set $app final_path $final_path
|
2016-03-31 23:26:35 +02:00
|
|
|
fi
|
|
|
|
|
2017-03-19 19:16:10 +01:00
|
|
|
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
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
|
|
#=================================================
|
|
|
|
|
2017-09-05 00:25:58 +02:00
|
|
|
# Backup the current version of the app
|
|
|
|
ynh_backup_before_upgrade
|
2017-03-19 19:16:10 +01:00
|
|
|
ynh_clean_setup () {
|
2017-12-05 19:36:40 +01:00
|
|
|
# Nettoyage des résidus d'installation non pris en charge par le script remove.
|
2017-12-16 23:22:54 +01:00
|
|
|
ynh_clean_check_starting
|
2017-09-05 00:25:58 +02:00
|
|
|
# restore it if the upgrade fails
|
|
|
|
ynh_restore_upgradebackup
|
2017-03-19 19:16:10 +01:00
|
|
|
}
|
2017-09-05 00:25:58 +02:00
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
2016-03-31 23:26:35 +02:00
|
|
|
|
2017-03-19 19:16:10 +01:00
|
|
|
#=================================================
|
|
|
|
# CHECK THE PATH
|
|
|
|
#=================================================
|
2015-03-27 23:26:10 +01:00
|
|
|
|
2017-03-19 19:16:10 +01:00
|
|
|
path_url=$(ynh_normalize_url_path $path_url) # Vérifie et corrige la syntaxe du path.
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD UPGRADE STEPS
|
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
|
|
|
|
2017-05-24 16:48:26 +02:00
|
|
|
ynh_setup_source "$final_path" # Télécharge la source, décompresse et copie dans $final_path
|
2017-03-19 19:16:10 +01:00
|
|
|
|
2017-12-05 19:36:40 +01:00
|
|
|
#=================================================
|
|
|
|
# UPGRADE DEPENDENCIES
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_install_app_dependencies $app_depencencies
|
|
|
|
|
2017-03-19 19:16:10 +01:00
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2016-06-15 23:56:45 +02:00
|
|
|
|
2017-09-05 00:25:58 +02:00
|
|
|
ynh_add_nginx_config
|
2015-03-26 13:07:01 +01:00
|
|
|
|
2017-03-19 19:16:10 +01:00
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_system_user_create $app # Create the dedicated user, if not exist
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC UPGRADE
|
|
|
|
#=================================================
|
|
|
|
# SETUP LUTIM
|
|
|
|
#=================================================
|
|
|
|
|
2015-03-26 13:07:01 +01:00
|
|
|
## Copie et configuration du fichier de conf.
|
2017-05-24 16:48:26 +02:00
|
|
|
ynh_backup_if_checksum_is_different "$final_path/lutim.conf" # Créé un backup du fichier de config si il a été modifié.
|
2017-09-05 00:25:58 +02:00
|
|
|
cp ../conf/lutim.conf.template "$final_path/lutim.conf"
|
2017-05-24 16:48:26 +02:00
|
|
|
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_store_file_checksum "$final_path/lutim.conf" # Réenregistre la somme de contrôle du fichier de config
|
2015-03-16 21:10:39 +01:00
|
|
|
|
2017-03-19 19:16:10 +01:00
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
|
|
|
|
2017-09-05 00:25:58 +02:00
|
|
|
ynh_add_systemd_config
|
2017-03-19 19:16:10 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP CRON
|
|
|
|
#=================================================
|
2015-03-16 21:10:39 +01:00
|
|
|
|
2017-09-05 00:25:58 +02:00
|
|
|
cp ../conf/cron_lutim /etc/cron.d/$app
|
2017-05-24 16:48:26 +02:00
|
|
|
ynh_replace_string "__FINALPATH__" "$final_path/" /etc/cron.d/$app
|
2015-03-16 21:10:39 +01:00
|
|
|
|
2017-03-19 19:16:10 +01:00
|
|
|
#=================================================
|
|
|
|
# UPDATE LUTIM WITH CARTON
|
|
|
|
#=================================================
|
2016-05-15 12:15:08 +02:00
|
|
|
|
2017-12-05 19:36:40 +01:00
|
|
|
(cd $final_path
|
|
|
|
carton install 2>&1 | tee -a "/var/log/$app/setup_carton.log")
|
2017-03-19 19:16:10 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SECURING FILES AND DIRECTORIES
|
|
|
|
#=================================================
|
|
|
|
|
2017-09-05 00:25:58 +02:00
|
|
|
chown -R $app: $final_path
|
2017-03-19 19:16:10 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALISATION
|
|
|
|
#=================================================
|
|
|
|
# SETUP LOGROTATE
|
|
|
|
#=================================================
|
|
|
|
|
2017-09-08 13:10:22 +02:00
|
|
|
ynh_use_logrotate --non-append
|
|
|
|
chown $app -R /var/log/$app
|
2017-03-19 19:16:10 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
2015-08-19 21:33:40 +02:00
|
|
|
|
2016-12-14 16:10:00 +01:00
|
|
|
ynh_app_setting_set $app skipped_uris "/"
|
2017-03-19 19:16:10 +01:00
|
|
|
if [ $is_public -eq 0 ]
|
2015-03-26 13:07:01 +01:00
|
|
|
then # Si l'app est privée, seul le visionnage des images reste public
|
2017-03-19 19:16:10 +01:00
|
|
|
# Modifie le domaine pour qu'il passe dans une regex
|
|
|
|
domain_regex=$(echo "$domain" | sed 's@-@.@g')
|
2017-05-24 16:48:26 +02:00
|
|
|
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/.*$"
|
2015-03-16 21:10:39 +01:00
|
|
|
fi
|
|
|
|
|
2017-03-19 19:16:10 +01:00
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2015-03-26 13:07:01 +01:00
|
|
|
|
2018-03-14 23:24:29 +01:00
|
|
|
ynh_system_reload nginx
|
2017-05-24 16:48:26 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START AND CHECK LUTIM BOOTING
|
|
|
|
#=================================================
|
|
|
|
|
2017-12-16 23:22:54 +01:00
|
|
|
# Wait for lutim fully started
|
|
|
|
ynh_check_starting "Manager.*started" "/var/log/$app/production.log" "120"
|