2017-11-01 20:57:58 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
2019-01-13 17:19:46 +01:00
|
|
|
# Load common variables for all scripts.
|
|
|
|
source _variables
|
2017-11-01 20:57:58 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
|
|
|
final_path=$(ynh_app_setting_get $app final_path)
|
2017-12-23 23:56:21 +01:00
|
|
|
frequency="$(ynh_app_setting_get $app frequency)"
|
2018-09-30 20:01:19 +02:00
|
|
|
encrypt=$(ynh_app_setting_get $app encrypt)
|
|
|
|
core_backup=$(ynh_app_setting_get $app core_backup)
|
|
|
|
apps_backup=$(ynh_app_setting_get $app apps_backup)
|
|
|
|
overwrite_cron=$(ynh_app_setting_get $app overwrite_cron)
|
2017-11-01 20:57:58 +01:00
|
|
|
|
2017-12-16 23:06:00 +01:00
|
|
|
#=================================================
|
|
|
|
# CHECK VERSION
|
|
|
|
#=================================================
|
|
|
|
|
2018-07-13 17:31:45 +02:00
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
|
|
|
|
2018-09-30 20:01:19 +02:00
|
|
|
#=================================================
|
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# If encrypt doesn't exist, create it
|
|
|
|
if [ -z "$encrypt" ]; then
|
|
|
|
encrypt="$(grep "^encrypt=" "$final_path/Backup_list.conf" | cut -d= -f2)"
|
|
|
|
if [ "$encrypt" = true ]; then
|
|
|
|
encrypt=1
|
|
|
|
else
|
|
|
|
encrypt=0
|
|
|
|
fi
|
|
|
|
ynh_app_setting_set $app encrypt $encrypt
|
|
|
|
fi
|
|
|
|
|
|
|
|
# If core_backup doesn't exist, create it
|
|
|
|
if [ -z "$core_backup" ]; then
|
|
|
|
core_backup="$(grep "^ynh_core_backup=" "$final_path/Backup_list.conf" | cut -d= -f2)"
|
|
|
|
ynh_app_setting_set $app core_backup $core_backup
|
|
|
|
fi
|
|
|
|
|
|
|
|
# If apps_backup doesn't exist, create it
|
|
|
|
if [ -z "$apps_backup" ]; then
|
|
|
|
apps_backup="$(grep --count --max-count=1 "^ynh_app_backup=" "$final_path/Backup_list.conf")"
|
|
|
|
ynh_app_setting_set $app apps_backup $apps_backup
|
|
|
|
fi
|
|
|
|
|
|
|
|
# If overwrite_cron doesn't exist, create it
|
|
|
|
if [ -z "$overwrite_cron" ]; then
|
|
|
|
overwrite_cron=1
|
|
|
|
ynh_app_setting_set $app overwrite_cron $overwrite_cron
|
|
|
|
fi
|
|
|
|
|
2018-07-13 17:31:45 +02:00
|
|
|
#=================================================
|
|
|
|
# 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
|
2017-12-16 23:06:00 +01:00
|
|
|
|
2017-11-01 20:57:58 +01:00
|
|
|
#=================================================
|
|
|
|
# STANDARD UPGRADE STEPS
|
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
|
|
|
|
2018-07-13 17:31:45 +02:00
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
|
|
|
then
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
|
|
ynh_setup_source "$final_path"
|
|
|
|
fi
|
2017-11-01 20:57:58 +01:00
|
|
|
|
2019-01-13 17:19:46 +01:00
|
|
|
#=================================================
|
|
|
|
# UPGRADE DEPENDENCIES
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_install_app_dependencies $app_depencencies
|
|
|
|
|
2017-11-01 20:57:58 +01:00
|
|
|
#=================================================
|
|
|
|
# SPECIFIC UPGRADE
|
2018-07-21 19:39:31 +02:00
|
|
|
#=================================================
|
|
|
|
# STRETCH COMPATIBILITY
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
if is_stretch
|
|
|
|
then
|
|
|
|
ynh_replace_string "yunohost backup create --ignore-apps" "yunohost backup create" "$final_path/archivist.sh"
|
|
|
|
ynh_replace_string "yunohost backup create --ignore-system" "yunohost backup create" "$final_path/archivist.sh"
|
|
|
|
fi
|
|
|
|
|
2017-11-01 20:57:58 +01:00
|
|
|
#=================================================
|
|
|
|
# UPDATE THE CRON FILE
|
|
|
|
#=================================================
|
|
|
|
|
2018-09-30 20:01:19 +02:00
|
|
|
# Overwrite the cron file only if it's allowed
|
|
|
|
if [ $overwrite_cron -eq 1 ]
|
|
|
|
then
|
|
|
|
# Verify the checksum and backup the file if it's different
|
|
|
|
ynh_backup_if_checksum_is_different "/etc/cron.d/$app"
|
|
|
|
|
|
|
|
cp ../conf/cron /etc/cron.d/$app
|
|
|
|
ynh_replace_string "__FINALPATH__" "$final_path" /etc/cron.d/$app
|
|
|
|
ynh_replace_string "__APP__" "$app" /etc/cron.d/$app
|
|
|
|
if [ "$frequency" = "Daily" ]; then
|
|
|
|
cron_freq="0 2 * * *"
|
|
|
|
elif [ "$frequency" = "Each 3 days" ]; then
|
|
|
|
cron_freq="0 2 */3 * *"
|
|
|
|
elif [ "$frequency" = "Weekly" ]; then
|
|
|
|
cron_freq="0 2 * * 0"
|
|
|
|
elif [ "$frequency" = "Biweekly" ]; then
|
|
|
|
cron_freq="0 2 * * 0/2"
|
|
|
|
else # Monthly
|
|
|
|
cron_freq="0 2 1 * *"
|
|
|
|
fi
|
|
|
|
ynh_replace_string "__FREQUENCY__" "$cron_freq" /etc/cron.d/$app
|
|
|
|
|
|
|
|
# Recalculate and store the config file checksum into the app settings
|
|
|
|
ynh_store_file_checksum "/etc/cron.d/$app"
|
2017-11-01 20:57:58 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP LOGROTATE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Use logrotate to manage app-specific logfile(s)
|
2017-12-16 23:06:00 +01:00
|
|
|
ynh_use_logrotate --non-append
|
2017-11-01 20:57:58 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# SECURE FILES AND DIRECTORIES
|
|
|
|
#=================================================
|
|
|
|
|
2019-01-13 17:27:09 +01:00
|
|
|
# Set permissions on app files
|
2017-11-01 20:57:58 +01:00
|
|
|
chown -R root: $final_path
|