1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/archivist_ynh.git synced 2024-09-03 18:15:55 +02:00
archivist_ynh/scripts/upgrade

207 lines
7.4 KiB
Text
Raw Normal View History

2017-11-01 20:57:58 +01:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC 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
2020-04-08 19:59:52 +02:00
source _common.sh
source /usr/share/yunohost/helpers
2017-11-01 20:57:58 +01:00
#=================================================
# LOAD SETTINGS
#=================================================
2019-05-26 17:00:09 +02:00
ynh_script_progression --message="Loading installation settings..." --weight=3
2017-11-01 20:57:58 +01:00
app=$YNH_APP_INSTANCE_NAME
2019-05-26 17:00:09 +02:00
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
frequency="$(ynh_app_setting_get --app=$app --key=frequency)"
encrypt=$(ynh_app_setting_get --app=$app --key=encrypt)
core_backup=$(ynh_app_setting_get --app=$app --key=core_backup)
apps_backup=$(ynh_app_setting_get --app=$app --key=apps_backup)
overwrite_cron=$(ynh_app_setting_get --app=$app --key=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
#=================================================
2019-05-26 17:00:09 +02:00
ynh_script_progression --message="Ensuring downward compatibility..."
2018-09-30 20:01:19 +02:00
# 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
2019-05-26 17:00:09 +02:00
ynh_app_setting_set --app=$app --key=encrypt --value=$encrypt
2018-09-30 20:01:19 +02:00
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)"
2019-05-26 17:00:09 +02:00
ynh_app_setting_set --app=$app --key=core_backup --value=$core_backup
2018-09-30 20:01:19 +02:00
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")"
2019-05-26 17:00:09 +02:00
ynh_app_setting_set --app=$app --key=apps_backup --value=$apps_backup
2018-09-30 20:01:19 +02:00
fi
# If overwrite_cron doesn't exist, create it
if [ -z "$overwrite_cron" ]; then
overwrite_cron=1
2019-05-26 17:00:09 +02:00
ynh_app_setting_set --app=$app --key=overwrite_cron --value=$overwrite_cron
2018-09-30 20:01:19 +02:00
fi
2019-05-26 17:00:09 +02:00
admin_mail_html=$(ynh_app_setting_get --app=$app --key=admin_mail_html)
2019-01-30 19:21:03 +01:00
# If admin_mail_html doesn't exist, create it
if [ -z "$admin_mail_html" ]; then
admin_mail_html=1
2019-05-26 17:00:09 +02:00
ynh_app_setting_set --app=$app --key=admin_mail_html --value=$admin_mail_html
2019-01-30 19:21:03 +01:00
fi
2018-07-13 17:31:45 +02:00
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
2019-05-26 17:00:09 +02:00
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=2
2018-07-13 17:31:45 +02:00
# 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
2019-05-26 17:00:09 +02:00
ynh_script_progression --message="Upgrading source files..." --weight=2
2018-07-13 17:31:45 +02:00
# Download, check integrity, uncompress and patch the source from app.src
2019-05-26 17:00:09 +02:00
ynh_setup_source --dest_dir="$final_path"
2018-07-13 17:31:45 +02:00
fi
2017-11-01 20:57:58 +01:00
2019-01-13 17:19:46 +01:00
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
2019-05-26 17:00:09 +02:00
ynh_script_progression --message="Upgrading dependencies..." --weight=8
2019-01-13 17:19:46 +01:00
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
2019-05-26 17:00:09 +02:00
ynh_replace_string --match_string="yunohost backup create --ignore-apps" --replace_string="yunohost backup create" --target_file="$final_path/archivist.sh"
ynh_replace_string --match_string="yunohost backup create --ignore-system" --replace_string="yunohost backup create" --target_file="$final_path/archivist.sh"
2018-07-21 19:39:31 +02:00
fi
2017-11-01 20:57:58 +01:00
#=================================================
# UPDATE THE CRON FILE
#=================================================
2019-05-26 17:00:09 +02:00
ynh_script_progression --message="Updating the cron file..."
2017-11-01 20:57:58 +01:00
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
2019-05-26 17:00:09 +02:00
ynh_backup_if_checksum_is_different --file="/etc/cron.d/$app"
2018-09-30 20:01:19 +02:00
cp ../conf/cron /etc/cron.d/$app
2019-05-26 17:00:09 +02:00
ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file=/etc/cron.d/$app
ynh_replace_string --match_string="__APP__" --replace_string=$app --target_file=/etc/cron.d/$app
2018-09-30 20:01:19 +02:00
if [ "$frequency" = "Daily" ]; then
cron_freq="0 2 * * *"
2019-01-19 18:55:14 +01:00
run_freq="every day"
2018-09-30 20:01:19 +02:00
elif [ "$frequency" = "Each 3 days" ]; then
cron_freq="0 2 */3 * *"
2019-01-19 18:55:14 +01:00
run_freq="each 3 days"
2018-09-30 20:01:19 +02:00
elif [ "$frequency" = "Weekly" ]; then
cron_freq="0 2 * * 0"
2019-01-19 18:55:14 +01:00
run_freq="once a week on sunday"
2018-09-30 20:01:19 +02:00
elif [ "$frequency" = "Biweekly" ]; then
cron_freq="0 2 * * 0/2"
2019-01-19 18:55:14 +01:00
run_freq="one sunday out of two"
2018-09-30 20:01:19 +02:00
else # Monthly
cron_freq="0 2 1 * *"
2019-01-19 18:55:14 +01:00
run_freq="once a month on the first sunday"
2018-09-30 20:01:19 +02:00
fi
2019-05-26 17:00:09 +02:00
ynh_replace_string --match_string="__FREQUENCY__" --replace_string="$cron_freq" --target_file=/etc/cron.d/$app
2018-09-30 20:01:19 +02:00
# Recalculate and store the config file checksum into the app settings
2019-05-26 17:00:09 +02:00
ynh_store_file_checksum --file="/etc/cron.d/$app"
2017-11-01 20:57:58 +01:00
fi
#=================================================
# SETUP LOGROTATE
#=================================================
2019-05-26 17:00:09 +02:00
ynh_script_progression --message="Upgrading logrotate configuration..."
2017-11-01 20:57:58 +01:00
# 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
2019-01-19 18:55:14 +01:00
#=================================================
# SEND A README FOR THE ADMIN
#=================================================
# Get main domain and buid the url of the admin panel of the app.
admin_panel="https://$(grep portal_domain /etc/ssowat/conf.json | cut -d'"' -f4)/yunohost/admin/#/apps/$app"
2019-01-30 19:21:03 +01:00
# Build the changelog
ynh_app_changelog || true
echo "Archivist is going to run $run_freq.
2019-01-19 18:55:14 +01:00
If you want to change the frequency, have a look to the file /etc/cron.d/$app.
2019-01-30 19:21:03 +01:00
Please read the __URL_TAG1__documentation__URL_TAG2__https://github.com/maniackcrudelis/archivist/blob/master/Configuration.md__URL_TAG3__ about the configuration of archivist for more information.
You can configure this app easily by using the experimental __URL_TAG1__config-panel feature__URL_TAG2__$admin_panel/config-panel__URL_TAG3__.
You can also find some specific actions for this app by using the experimental __URL_TAG1__action feature__URL_TAG2__$admin_panel/actions__URL_TAG3__.
If you're facing an issue or want to improve this app, please open a new issue in this __URL_TAG1__project__URL_TAG2__https://github.com/YunoHost-Apps/archivist_ynh__URL_TAG3__.
2019-01-19 18:55:14 +01:00
2019-01-30 19:21:03 +01:00
---
2019-01-19 18:55:14 +01:00
2019-01-30 19:21:03 +01:00
Changelog since your last upgrade:
$(cat changelog)" > mail_to_send
2019-01-19 18:55:14 +01:00
2019-05-26 17:00:09 +02:00
ynh_send_readme_to_admin --app_message="mail_to_send" --recipients="root" --type=upgrade
2019-01-30 16:07:38 +01:00
#=================================================
# END OF SCRIPT
#=================================================
2019-05-26 17:00:09 +02:00
ynh_script_progression --message="Upgrade of $app completed" --last