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

275 lines
8.9 KiB
Text
Raw Normal View History

2014-08-17 17:52:31 +02:00
#!/bin/bash
2014-08-18 22:05:31 +02:00
2017-03-01 19:37:00 +01:00
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2016-06-15 23:56:35 +02:00
2017-03-19 23:03:07 +01:00
source _common.sh
2016-12-14 16:08:29 +01:00
source /usr/share/yunohost/helpers
2017-03-01 19:37:00 +01:00
#=================================================
# LOAD SETTINGS
#=================================================
2019-01-30 16:15:24 +01:00
ynh_script_progression --message="Load settings" --weight=3
2017-03-01 19:37:00 +01:00
app=$YNH_APP_INSTANCE_NAME
2016-12-14 16:08:29 +01:00
domain=$(ynh_app_setting_get $app domain)
2017-03-01 19:37:00 +01:00
path_url=$(ynh_app_setting_get $app path)
2016-12-14 16:08:29 +01:00
admin=$(ynh_app_setting_get $app admin)
is_public=$(ynh_app_setting_get $app is_public)
final_path=$(ynh_app_setting_get $app final_path)
db_pwd=$(ynh_app_setting_get $app mysqlpwd)
2017-03-01 19:37:00 +01:00
db_name=$(ynh_app_setting_get $app db_name)
2018-09-30 11:51:17 +02:00
overwrite_nginx=$(ynh_app_setting_get $app overwrite_nginx)
overwrite_phpfpm=$(ynh_app_setting_get $app overwrite_phpfpm)
2019-01-30 19:26:05 +01:00
admin_mail_html=$(ynh_app_setting_get $app admin_mail_html)
2017-03-01 19:37:00 +01:00
2017-12-16 23:21:37 +01:00
#=================================================
# CHECK VERSION
#=================================================
2018-07-13 17:33:34 +02:00
upgrade_type=$(ynh_check_app_version_changed)
2017-12-16 23:21:37 +01:00
2017-03-01 19:37:00 +01:00
#=================================================
2019-01-19 12:13:45 +01:00
# ENSURE DOWNWARD COMPATIBILITY
2017-03-01 19:37:00 +01:00
#=================================================
2019-01-30 16:15:24 +01:00
ynh_script_progression --message="Ensure downward compatibility"
2014-08-18 22:05:31 +02:00
2019-01-19 12:13:45 +01:00
# If final_path doesn't exist, create it
if [ -z "$final_path" ]; then
2016-06-25 17:57:34 +02:00
final_path=/var/www/$app
2016-12-14 16:08:29 +01:00
ynh_app_setting_set $app final_path $final_path
2016-06-25 17:57:34 +02:00
fi
2017-03-19 18:31:53 +01:00
2019-01-19 12:13:45 +01:00
# If db_name doesn't exist, create it
if [ -z "$db_name" ]; then
2017-03-01 19:37:00 +01:00
db_name=$(ynh_make_valid_dbid $app)
ynh_app_setting_set $app db_name $db_name
fi
2017-03-19 18:31:53 +01:00
2019-01-19 12:13:45 +01:00
# If is_public doesn't exist, create it
if [ -z "$is_public" ]; then
2017-03-01 19:37:00 +01:00
public_check=$(ynh_app_setting_get $app skipped_uris)
2019-01-19 12:13:45 +01:00
# If skipped_uris is empty, that was a public installation.
if [ -z "$public_check" ]; then
2017-03-01 19:37:00 +01:00
is_public=1
else
is_public=0
fi
ynh_app_setting_set $app is_public $is_public
else
2019-01-19 12:13:45 +01:00
# Fix is_public as a boolean
2017-03-01 19:37:00 +01:00
if [ "$is_public" = "Yes" ]; then
2019-01-19 12:13:45 +01:00
ynh_app_setting_set $app is_public 1
2017-03-01 19:37:00 +01:00
is_public=1
elif [ "$is_public" = "No" ]; then
ynh_app_setting_set $app is_public 0
is_public=0
fi
fi
2017-03-19 18:31:53 +01:00
2018-09-30 11:51:17 +02:00
# 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_phpfpm doesn't exist, create it
if [ -z "$overwrite_phpfpm" ]; then
overwrite_phpfpm=1
ynh_app_setting_set $app overwrite_phpfpm $overwrite_phpfpm
fi
2019-01-30 19:26:05 +01:00
# If admin_mail_html doesn't exist, create it
if [ -z "$admin_mail_html" ]; then
admin_mail_html=1
ynh_app_setting_set $app admin_mail_html $admin_mail_html
fi
2017-03-01 19:37:00 +01:00
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
2019-01-30 16:15:24 +01:00
ynh_script_progression --message="Backup the app before upgrading" --weight=4
2016-06-15 23:56:35 +02:00
2017-09-05 00:24:01 +02:00
# Backup the current version of the app
ynh_backup_before_upgrade
2017-03-01 19:37:00 +01:00
ynh_clean_setup () {
2017-09-05 00:24:01 +02:00
# restore it if the upgrade fails
ynh_restore_upgradebackup
2017-03-01 19:37:00 +01:00
}
2017-09-05 00:24:01 +02:00
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
2016-06-15 23:56:35 +02:00
2017-03-01 19:37:00 +01:00
#=================================================
# CHECK THE PATH
#=================================================
2019-01-19 12:13:45 +01:00
# Normalize the URL path syntax
path_url=$(ynh_normalize_url_path $path_url)
2017-03-01 19:37:00 +01:00
2018-07-13 17:33:34 +02:00
#=================================================
# ACTIVATE MAINTENANCE MODE
#=================================================
2019-01-30 16:15:24 +01:00
ynh_script_progression --message="Activate maintenance mode"
2018-07-13 17:33:34 +02:00
ynh_maintenance_mode_ON
2017-03-01 19:37:00 +01:00
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
2014-08-18 22:05:31 +02:00
2018-07-13 17:33:34 +02:00
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
2019-01-30 16:15:24 +01:00
ynh_script_progression --message="Download, check and unpack source" --weight=3
2019-01-19 12:13:45 +01:00
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source "$final_path"
2018-07-13 17:33:34 +02:00
fi
2014-08-18 22:05:31 +02:00
2017-03-01 19:37:00 +01:00
#=================================================
# NGINX CONFIGURATION
#=================================================
2018-09-30 11:51:17 +02:00
# Overwrite the nginx configuration only if it's allowed
if [ $overwrite_nginx -eq 1 ]
then
2019-01-30 16:15:24 +01:00
ynh_script_progression --message="Reconfigure nginx" --weight=2
2019-01-19 12:13:45 +01:00
# Create a dedicated nginx config
2018-09-30 11:51:17 +02:00
ynh_add_nginx_config
fi
2015-11-22 14:37:01 +01:00
2017-03-01 19:37:00 +01:00
#=================================================
# CREATE DEDICATED USER
#=================================================
2019-01-30 16:15:24 +01:00
ynh_script_progression --message="Create a dedicated user"
2015-11-22 14:37:01 +01:00
2019-01-19 12:13:45 +01:00
# Create a dedicated user (if not existing)
ynh_system_user_create $app
2017-03-01 19:37:00 +01:00
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
2018-09-30 11:51:17 +02:00
# Overwrite the php-fpm configuration only if it's allowed
if [ $overwrite_phpfpm -eq 1 ]
then
2019-01-30 16:15:24 +01:00
ynh_script_progression --message="Reconfigure php-fpm" --weight=2
2019-01-19 12:13:45 +01:00
# Create a dedicated php-fpm config
ynh_add_fpm_config
2018-09-30 11:51:17 +02:00
fi
2014-08-18 22:05:31 +02:00
2017-03-01 19:37:00 +01:00
#=================================================
# SPECIFIC UPGRADE
#=================================================
# RETRIEVE SYNCHRONISATION CODE
#=================================================
2015-11-22 14:37:01 +01:00
2017-03-01 19:37:00 +01:00
code_sync=$(mysql -h localhost -u $db_name -p$db_pwd -s $db_name -e 'SELECT value FROM leed_configuration WHERE `key`="synchronisationCode"' | sed -n 1p)
#=================================================
# SETUP CRON FILE FOR SYNCHRONISATION
#=================================================
2015-11-22 14:37:01 +01:00
2017-06-13 17:11:10 +02:00
ynh_replace_string "__ADMIN__" "$admin" ../conf/cron_leed
ynh_replace_string "__DOMAIN__" "$domain" ../conf/cron_leed
ynh_replace_string "__PATH__" "$path_url" ../conf/cron_leed
ynh_replace_string "__CODESYNC__" "$code_sync" ../conf/cron_leed
2017-09-05 00:24:01 +02:00
cp ../conf/cron_leed /etc/cron.d/$app
2015-11-22 14:37:01 +01:00
2017-03-01 19:37:00 +01:00
#=================================================
# SECURING FILES AND DIRECTORIES
#=================================================
2019-01-19 12:13:45 +01:00
# Set permissions on app files
2017-09-05 00:24:01 +02:00
chown -R root: $final_path
2019-01-19 12:13:45 +01:00
# $app need write permissions in plugins, cache and updates
2017-09-05 00:24:01 +02:00
mkdir -p $final_path/cache
chown -R $app $final_path/cache $final_path/plugins $final_path/updates
2017-03-01 19:37:00 +01:00
#=================================================
# UPGRADE WITH CURL
#=================================================
2018-07-13 17:33:34 +02:00
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
2019-01-30 16:15:24 +01:00
ynh_script_progression --message="Upgrade Leed with curl" --weight=4
2019-01-19 12:13:45 +01:00
# Clear leed cache
2018-07-13 17:33:34 +02:00
ynh_secure_remove $final_path/cache/*
2019-01-19 12:13:45 +01:00
# Set the app as temporarily public for curl call
2018-07-13 17:33:34 +02:00
ynh_app_setting_set $app unprotected_uris "/"
2019-01-19 12:13:45 +01:00
# Regen SSOwat configuration
2018-07-13 17:33:34 +02:00
yunohost app ssowatconf
2019-01-19 12:13:45 +01:00
# Start the upgrade procedure of leed.
2018-07-13 17:33:34 +02:00
ynh_local_curl "/"
fi
2017-03-01 19:37:00 +01:00
#=================================================
# GENERIC FINALISATION
2017-12-11 20:37:45 +01:00
#=================================================
# UPGRADE FAIL2BAN
#=================================================
2019-01-30 16:15:24 +01:00
ynh_script_progression --message="Reconfigure fail2ban" --weight=8
2017-12-11 20:37:45 +01:00
2019-01-19 12:13:45 +01:00
# Create a dedicated fail2ban config
2019-01-19 12:00:42 +01:00
ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failregex="PHP message: Leed: wrong login for .* client: <HOST>" --max_retry=5
2017-12-11 20:37:45 +01:00
2017-03-01 19:37:00 +01:00
#=================================================
# SETUP SSOWAT
#=================================================
2019-01-30 16:15:24 +01:00
ynh_script_progression --message="Reconfigure SSOwat"
2016-06-25 13:08:00 +02:00
2014-08-18 22:05:31 +02:00
# Make app private if necessary
2017-03-01 19:37:00 +01:00
if [ $is_public -eq 0 ];
2014-08-18 22:05:31 +02:00
then
2019-01-19 12:13:45 +01:00
# Remove the public access
2016-12-14 16:08:29 +01:00
ynh_app_setting_delete $app unprotected_uris
2019-01-19 12:13:45 +01:00
# Set the action.php script public for the cron task
2016-12-14 16:08:29 +01:00
ynh_app_setting_set $app skipped_uris "/action.php"
2014-08-18 22:05:31 +02:00
fi
2017-03-01 19:37:00 +01:00
#=================================================
# RELOAD NGINX
#=================================================
2019-01-30 16:15:24 +01:00
ynh_script_progression --message="Reload nginx" --weight=2
2017-03-01 19:37:00 +01:00
2019-01-19 12:00:42 +01:00
ynh_systemd_action --action=reload --service_name=nginx
2018-07-13 17:33:34 +02:00
#=================================================
# DEACTIVE MAINTENANCE MODE
#=================================================
2019-01-31 11:34:20 +01:00
ynh_script_progression --message="Disable maintenance mode"
2018-07-13 17:33:34 +02:00
ynh_maintenance_mode_OFF
2019-01-21 13:09:35 +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:26:05 +01:00
# Build the changelog
ynh_app_changelog || true
echo "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/leed_ynh__URL_TAG3__.
---
Changelog since your last upgrade:
$(cat changelog)" > mail_to_send
2019-01-21 13:09:35 +01:00
2019-01-30 19:26:05 +01:00
ynh_send_readme_to_admin --app_message="mail_to_send" --recipients="$admin" --type="upgrade"
2019-01-21 13:09:35 +01:00
2019-01-30 16:15:24 +01:00
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade completed" --last