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
#=================================================
2021-05-16 16:15:54 +02:00
# GENERIC START
2017-03-01 19:37:00 +01:00
#=================================================
# 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-03-12 20:09:45 +01:00
ynh_script_progression --message="Loading installation settings..." --weight=3
2017-03-01 19:37:00 +01:00
app=$YNH_APP_INSTANCE_NAME
2019-05-20 23:09:08 +02:00
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
admin=$(ynh_app_setting_get --app=$app --key=admin)
is_public=$(ynh_app_setting_get --app=$app --key=is_public)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
overwrite_nginx=$(ynh_app_setting_get --app=$app --key=overwrite_nginx)
overwrite_phpfpm=$(ynh_app_setting_get --app=$app --key=overwrite_phpfpm)
admin_mail_html=$(ynh_app_setting_get --app=$app --key=admin_mail_html)
2017-03-01 19:37:00 +01:00
2019-06-04 20:28:32 +02:00
fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint)
fpm_usage=$(ynh_app_setting_get --app=$app --key=fpm_usage)
2020-11-25 20:55:09 +01:00
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
2019-06-04 20:28:32 +02:00
2017-12-16 23:21:37 +01:00
#=================================================
# CHECK VERSION
#=================================================
2021-05-16 16:15:54 +02:00
ynh_script_progression --message="Checking version..."
2017-12-16 23:21:37 +01:00
2018-07-13 17:33:34 +02:00
upgrade_type=$(ynh_check_app_version_changed)
2017-12-16 23:21:37 +01:00
2021-05-16 16:15:54 +02:00
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=4
# 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
#=================================================
# ACTIVATE MAINTENANCE MODE
#=================================================
ynh_script_progression --message="Activating maintenance mode..."
ynh_maintenance_mode_ON
#=================================================
# STANDARD UPGRADE STEPS
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-03-12 20:09:45 +01:00
ynh_script_progression --message="Ensuring 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
2019-07-21 12:58:13 +02:00
final_path=/var/www/$app
ynh_app_setting_set --app=$app --key=final_path --value=$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
2019-07-21 12:58:13 +02:00
db_name=$(ynh_sanitize_dbid --db_name=$app)
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
2017-03-01 19:37:00 +01:00
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
2019-07-21 12:58:13 +02:00
overwrite_nginx=1
ynh_app_setting_set --app=$app --key=overwrite_nginx --value=$overwrite_nginx
2018-09-30 11:51:17 +02:00
fi
# If overwrite_phpfpm doesn't exist, create it
if [ -z "$overwrite_phpfpm" ]; then
2019-07-21 12:58:13 +02:00
overwrite_phpfpm=1
ynh_app_setting_set --app=$app --key=overwrite_phpfpm --value=$overwrite_phpfpm
2018-09-30 11:51:17 +02:00
fi
2019-01-30 19:26:05 +01:00
# If admin_mail_html doesn't exist, create it
if [ -z "$admin_mail_html" ]; then
2019-07-21 12:58:13 +02:00
admin_mail_html=1
ynh_app_setting_set --app=$app --key=admin_mail_html --value=$admin_mail_html
2019-01-30 19:26:05 +01:00
fi
2020-03-19 18:29:28 +01:00
# If fpm_footprint doesn't exist, create it
if [ -z "$fpm_footprint" ]; then
fpm_footprint=low
ynh_app_setting_set --app=$app --key=fpm_footprint --value=$fpm_footprint
fi
# If fpm_usage doesn't exist, create it
if [ -z "$fpm_usage" ]; then
fpm_usage=low
ynh_app_setting_set --app=$app --key=fpm_usage --value=$fpm_usage
2019-01-30 19:26:05 +01:00
fi
2019-09-09 09:30:20 +02:00
# If fpm_footprint doesn't exist, create it
if [ -z "$fpm_footprint" ]; then
fpm_footprint=low
ynh_app_setting_set --app=$app --key=fpm_footprint --value=$fpm_footprint
fi
# If fpm_usage doesn't exist, create it
if [ -z "$fpm_usage" ]; then
fpm_usage=low
ynh_app_setting_set --app=$app --key=fpm_usage --value=$fpm_usage
fi
2021-05-16 16:15:54 +02:00
# Cleaning legacy permissions
if ynh_legacy_permissions_exists; then
2021-03-15 00:26:30 +01:00
ynh_legacy_permissions_delete_all
ynh_app_setting_delete --app=$app --key=is_public
fi
2018-07-13 17:33:34 +02:00
#=================================================
2021-05-16 16:15:54 +02:00
# CREATE DEDICATED USER
2018-07-13 17:33:34 +02:00
#=================================================
2021-05-16 16:15:54 +02:00
ynh_script_progression --message="Making sure dedicated system user exists..."
2018-07-13 17:33:34 +02:00
2021-05-16 16:15:54 +02:00
# Create a dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir=$final_path
2018-07-13 17:33:34 +02:00
2017-03-01 19:37:00 +01:00
#=================================================
# 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
2021-05-16 16:15:54 +02:00
ynh_script_progression --message="Upgrading source files..." --weight=3
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path"
2018-07-13 17:33:34 +02:00
fi
2014-08-18 22:05:31 +02:00
2021-05-16 16:15:54 +02:00
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:www-data "$final_path"
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
2021-05-16 16:15:54 +02:00
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=2
# Create a dedicated NGINX config
ynh_add_nginx_config
2018-09-30 11:51:17 +02:00
fi
2015-11-22 14:37:01 +01:00
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
2020-11-25 20:55:09 +01:00
ynh_script_progression --message="Upgrading PHP-FPM configuration..." --weight=2
2021-05-16 16:15:54 +02:00
# Create a dedicated PHP-FPM config
2019-07-21 12:58:13 +02:00
ynh_add_fpm_config --usage=$fpm_usage --footprint=$fpm_footprint
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
#=================================================
2021-05-16 16:15:54 +02:00
ynh_script_progression --message="Setting up a cron file..."
2015-11-22 14:37:01 +01:00
2021-05-16 16:15:54 +02:00
ynh_add_config --template="../conf/cron_leed" --destination="/etc/cron.d/$app"
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
2020-11-25 20:55:09 +01:00
ynh_script_progression --message="Upgrading Leed with cURL..." --weight=4
2019-07-21 12:58:13 +02:00
# Set the app as temporarily public for curl call
2021-09-10 22:10:09 +02:00
ynh_permission_update --permission="main" --add="visitors"
2019-07-21 12:58:13 +02:00
# Start the upgrade procedure of leed.
ynh_local_curl "/"
2021-09-25 16:03:35 +02:00
ynh_permission_update --permission="main" --remove="visitors"
2018-07-13 17:33:34 +02:00
fi
2017-03-01 19:37:00 +01:00
#=================================================
2021-05-16 16:15:54 +02:00
# GENERIC FINALIZATION
2017-12-11 20:37:45 +01:00
#=================================================
# UPGRADE FAIL2BAN
#=================================================
2020-11-25 20:55:09 +01:00
ynh_script_progression --message="Reconfiguring Fail2Ban..." --weight=8
2017-12-11 20:37:45 +01:00
2021-05-16 16:15:54 +02: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
#=================================================
# RELOAD NGINX
#=================================================
2021-05-16 16:15:54 +02:00
ynh_script_progression --message="Reloading NGINX web server..." --weight=2
2017-03-01 19:37:00 +01:00
2019-05-20 23:09:08 +02:00
ynh_systemd_action --service_name=nginx --action=reload
2018-07-13 17:33:34 +02:00
#=================================================
# DEACTIVE MAINTENANCE MODE
#=================================================
2019-03-12 20:09:45 +01:00
ynh_script_progression --message="Disabling 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
2019-06-02 19:12:29 +02:00
# Get the value of admin_mail_html
admin_mail_html=$(ynh_app_setting_get $app admin_mail_html)
admin_mail_html="${admin_mail_html:-0}"
# If a html email is required. Apply html to the changelog.
if [ "$admin_mail_html" -eq 1 ]; then
format=html
else
format=plain
fi
ynh_app_changelog --format=$format
2019-01-30 19:26:05 +01:00
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-05-20 23:09:08 +02: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
#=================================================
2019-03-12 20:09:45 +01:00
ynh_script_progression --message="Upgrade of $app completed" --last