1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/lutim_ynh.git synced 2024-09-03 19:36:24 +02:00
lutim_ynh/scripts/upgrade

265 lines
8.2 KiB
Text
Raw Normal View History

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
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)
2018-09-30 11:52:12 +02:00
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)
2015-03-16 21:10:39 +01:00
2017-12-16 23:22:54 +01:00
#=================================================
# CHECK VERSION
#=================================================
2018-07-13 17:33:54 +02:00
upgrade_type=$(ynh_check_app_version_changed)
2017-12-16 23:22:54 +01:00
2017-03-19 19:16:10 +01:00
#=================================================
2018-09-30 11:52:12 +02:00
# ENSURE DOWNWARD COMPATIBILITY
2017-03-19 19:16:10 +01:00
#=================================================
2019-01-18 19:56:43 +01:00
# Fix is_public as a boolean
2017-03-19 19:16:10 +01:00
if [ "$is_public" = "Yes" ]; then
2019-01-18 19:56:43 +01:00
ynh_app_setting_set $app is_public 1
2017-03-19 19:16:10 +01:00
is_public=1
elif [ "$is_public" = "No" ]; then
ynh_app_setting_set $app is_public 0
is_public=0
fi
2019-01-18 19:56:43 +01:00
# if final_path isn't set, which can happens with old scripts, set final_path.
2016-03-31 23:26:35 +02:00
if [ "${#final_path}" -eq 0 ]
2019-01-18 19:56:43 +01:00
then
2016-03-31 23:26:35 +02:00
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
2019-01-18 19:56:43 +01:00
# Fix always_encrypt as a boolean
2017-03-19 19:16:10 +01:00
if [ "$always_encrypt" = "Yes" ]; then
2019-01-18 19:56:43 +01:00
ynh_app_setting_set $app always_encrypt 1
2017-03-19 19:16:10 +01:00
always_encrypt=1
elif [ "$always_encrypt" = "No" ]; then
ynh_app_setting_set $app always_encrypt 0
always_encrypt=0
fi
2018-09-30 11:52:12 +02:00
# 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
2017-03-19 19:16:10 +01:00
#=================================================
# 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 () {
2019-01-18 19:56:43 +01:00
# Clean installation remaining that are not handle by the remove script.
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
2019-01-18 19:56:43 +01:00
# Normalize the URL path syntax
path_url=$(ynh_normalize_url_path $path_url)
2017-03-19 19:16:10 +01:00
2018-05-20 20:55:15 +02:00
#=================================================
# ACTIVATE MAINTENANCE MODE
#=================================================
ynh_maintenance_mode_ON
2017-03-19 19:16:10 +01:00
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
2019-01-13 19:10:28 +01:00
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
2019-01-18 19:56:43 +01:00
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source "$final_path"
2019-01-13 19:10:28 +01:00
fi
2017-03-19 19:16:10 +01:00
2017-12-05 19:36:40 +01:00
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
2019-01-13 19:10:28 +01:00
ynh_install_app_dependencies $app_depencencies
2017-12-05 19:36:40 +01:00
2017-03-19 19:16:10 +01:00
#=================================================
# NGINX CONFIGURATION
#=================================================
2016-06-15 23:56:45 +02:00
2018-09-30 11:52:12 +02:00
# Overwrite the nginx configuration only if it's allowed
if [ $overwrite_nginx -eq 1 ]
then
ynh_add_nginx_config
fi
2015-03-26 13:07:01 +01:00
2017-03-19 19:16:10 +01:00
#=================================================
# CREATE DEDICATED USER
#=================================================
2019-01-18 19:56:43 +01:00
# Create a dedicated user (if not existing)
ynh_system_user_create $app
2017-03-19 19:16:10 +01:00
#=================================================
# SPECIFIC UPGRADE
#=================================================
# SETUP LUTIM
#=================================================
2018-09-30 11:52:12 +02:00
# Overwrite the settings config file only if it's allowed
if [ $overwrite_settings -eq 1 ]
then
2019-01-18 19:56:43 +01:00
# Configure Lutim
# Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script.
ynh_backup_if_checksum_is_different "$final_path/lutim.conf"
2018-09-30 11:52:12 +02:00
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"
2019-01-18 19:56:43 +01:00
# Recalculate and store the checksum of the file for the next upgrade.
ynh_store_file_checksum "$final_path/lutim.conf"
2018-09-30 11:52:12 +02:00
# 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
2015-03-16 21:10:39 +01:00
2017-03-19 19:16:10 +01:00
#=================================================
# SETUP SYSTEMD
#=================================================
2018-09-30 11:52:12 +02:00
# Overwrite the systemd configuration only if it's allowed
if [ $overwrite_systemd -eq 1 ]
then
ynh_add_systemd_config
fi
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
2018-07-13 17:33:54 +02:00
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
(cd $final_path
carton install 2>&1 | tee -a "/var/log/$app/setup_carton.log")
fi
2017-03-19 19:16:10 +01:00
#=================================================
# SECURING FILES AND DIRECTORIES
#=================================================
2019-01-18 19:56:43 +01:00
# Set permissions on app files
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 ]
2019-01-18 19:56:43 +01:00
then
# If the app is private, viewing images stays publicly accessible.
# Modify the domain to be used in a regex
2017-03-19 19:16:10 +01:00
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
2019-01-13 19:10:28 +01:00
ynh_systemd_action --action=reload --service_name=nginx
2017-05-24 16:48:26 +02:00
#=================================================
# START AND CHECK LUTIM BOOTING
#=================================================
2019-01-18 19:56:43 +01:00
# Wait for lutim to be fully started
2019-01-13 19:10:28 +01:00
ynh_systemd_action --action=restart --line_match="Manager.*started" --log_path="/var/log/$app/production.log" --timeout="120"
2018-05-20 20:55:15 +02:00
#=================================================
# DEACTIVE MAINTENANCE MODE
#=================================================
ynh_maintenance_mode_OFF