mirror of
https://github.com/YunoHost-Apps/leed_ynh.git
synced 2024-09-03 19:26:32 +02:00
278 lines
9.5 KiB
Bash
278 lines
9.5 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# LOAD SETTINGS
|
|
#=================================================
|
|
ynh_script_progression --message="Loading installation settings..." --weight=3
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
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)
|
|
|
|
fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint)
|
|
fpm_usage=$(ynh_app_setting_get --app=$app --key=fpm_usage)
|
|
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
|
|
|
|
#=================================================
|
|
# CHECK VERSION
|
|
#=================================================
|
|
ynh_script_progression --message="Checking version..."
|
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
|
|
|
#=================================================
|
|
# 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
|
|
#=================================================
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
#=================================================
|
|
ynh_script_progression --message="Ensuring downward compatibility..."
|
|
|
|
# If final_path doesn't exist, create it
|
|
if [ -z "$final_path" ]; then
|
|
final_path=/var/www/$app
|
|
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
|
fi
|
|
|
|
# If db_name doesn't exist, create it
|
|
if [ -z "$db_name" ]; then
|
|
db_name=$(ynh_sanitize_dbid --db_name=$app)
|
|
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
|
|
fi
|
|
|
|
# If overwrite_nginx doesn't exist, create it
|
|
if [ -z "$overwrite_nginx" ]; then
|
|
overwrite_nginx=1
|
|
ynh_app_setting_set --app=$app --key=overwrite_nginx --value=$overwrite_nginx
|
|
fi
|
|
|
|
# If overwrite_phpfpm doesn't exist, create it
|
|
if [ -z "$overwrite_phpfpm" ]; then
|
|
overwrite_phpfpm=1
|
|
ynh_app_setting_set --app=$app --key=overwrite_phpfpm --value=$overwrite_phpfpm
|
|
fi
|
|
|
|
# If admin_mail_html doesn't exist, create it
|
|
if [ -z "$admin_mail_html" ]; then
|
|
admin_mail_html=1
|
|
ynh_app_setting_set --app=$app --key=admin_mail_html --value=$admin_mail_html
|
|
fi
|
|
|
|
# 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
|
|
|
|
# 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
|
|
|
|
# Cleaning legacy permissions
|
|
if ynh_legacy_permissions_exists; then
|
|
ynh_legacy_permissions_delete_all
|
|
|
|
ynh_app_setting_delete --app=$app --key=is_public
|
|
fi
|
|
|
|
#=================================================
|
|
# CREATE DEDICATED USER
|
|
#=================================================
|
|
ynh_script_progression --message="Making sure dedicated system user exists..."
|
|
|
|
# Create a dedicated user (if not existing)
|
|
ynh_system_user_create --username=$app --home_dir=$final_path
|
|
|
|
#=================================================
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
#=================================================
|
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
|
then
|
|
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"
|
|
fi
|
|
|
|
chmod 750 "$final_path"
|
|
chmod -R o-rwx "$final_path"
|
|
chown -R $app:www-data "$final_path"
|
|
|
|
#=================================================
|
|
# NGINX CONFIGURATION
|
|
#=================================================
|
|
|
|
# Overwrite the nginx configuration only if it's allowed
|
|
if [ $overwrite_nginx -eq 1 ]
|
|
then
|
|
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=2
|
|
# Create a dedicated NGINX config
|
|
ynh_add_nginx_config
|
|
fi
|
|
|
|
#=================================================
|
|
# PHP-FPM CONFIGURATION
|
|
#=================================================
|
|
|
|
# Overwrite the php-fpm configuration only if it's allowed
|
|
if [ $overwrite_phpfpm -eq 1 ]
|
|
then
|
|
ynh_script_progression --message="Upgrading PHP-FPM configuration..." --weight=2
|
|
# Create a dedicated PHP-FPM config
|
|
ynh_add_fpm_config --usage=$fpm_usage --footprint=$fpm_footprint
|
|
fi
|
|
|
|
#=================================================
|
|
# SPECIFIC UPGRADE
|
|
#=================================================
|
|
# RETRIEVE SYNCHRONISATION CODE
|
|
#=================================================
|
|
|
|
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
|
|
#=================================================
|
|
ynh_script_progression --message="Setting up a cron file..."
|
|
|
|
ynh_add_config --template="../conf/cron_leed" --destination="/etc/cron.d/$app"
|
|
|
|
#=================================================
|
|
# UPGRADE WITH CURL
|
|
#=================================================
|
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
|
then
|
|
ynh_script_progression --message="Upgrading Leed with cURL..." --weight=4
|
|
# Set the app as temporarily public for curl call
|
|
ynh_permission_update --permission="main" --add="visitors"
|
|
# Start the upgrade procedure of leed.
|
|
ynh_local_curl "/"
|
|
ynh_permission_update --permission="main" --remove="visitors"
|
|
fi
|
|
|
|
#=================================================
|
|
# GENERIC FINALIZATION
|
|
#=================================================
|
|
# UPGRADE FAIL2BAN
|
|
#=================================================
|
|
ynh_script_progression --message="Reconfiguring Fail2Ban..." --weight=8
|
|
|
|
# Create a dedicated Fail2Ban config
|
|
ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failregex="PHP message: Leed: wrong login for .* client: <HOST>" --max_retry=5
|
|
|
|
#=================================================
|
|
# SETUP SSOWAT
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring permissions..." --weight=1
|
|
|
|
# Make app public if necessary
|
|
if [ $is_public -eq 1 ]
|
|
then
|
|
ynh_permission_update --permission="main" --add="visitors"
|
|
fi
|
|
|
|
#=================================================
|
|
# RELOAD NGINX
|
|
#=================================================
|
|
ynh_script_progression --message="Reloading NGINX web server..." --weight=2
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
#=================================================
|
|
# DEACTIVE MAINTENANCE MODE
|
|
#=================================================
|
|
ynh_script_progression --message="Disabling maintenance mode..."
|
|
|
|
ynh_maintenance_mode_OFF
|
|
|
|
#=================================================
|
|
# 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"
|
|
|
|
# Build the changelog
|
|
# 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
|
|
|
|
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
|
|
|
|
ynh_send_readme_to_admin --app_message="mail_to_send" --recipients="$admin" --type=upgrade
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|