1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/shaarli_ynh.git synced 2024-09-03 20:26:10 +02:00
shaarli_ynh/scripts/upgrade
Éric Gaspar 84b4977180 cleaning
2023-11-15 11:17:59 +01:00

94 lines
3.1 KiB
Bash

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# CHECK VERSION
#=================================================
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
if [ "$upgrade_type" == "UPGRADE_APP" ] || [ "$upgrade_type" == "UPGRADE_FORCED" ] # we should do that during a force upgrade too (as it could lead to a version upgrade for instance)
then
ynh_script_progression --message="Upgrading source files..."
# Create a temporary directory
tmpdir="$(mktemp -d)"
# Backup the config file in the temp dir
cp -a "$install_dir/data" "$tmpdir/data"
cp -a "$install_dir/tpl" "$tmpdir/tpl"
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir"
cp -a "$tmpdir/data" "$install_dir/"
cp -a -n "$tmpdir/tpl" "$install_dir/" # copy without erasing existing templates (from official source)
# Remove the tmp directory securely
ynh_secure_remove --file="$tmpdir"
fi
chmod -R o-rwx "$install_dir"
chmod -R u+rwX $install_dir/{cache/,data/,pagecache/,tmp/}
chown -R $app:www-data "$install_dir"
chmod 700 "$install_dir/data/config.json.php"
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading PHP-FPM configuration..."
# Create a dedicated PHP-FPM config
ynh_add_fpm_config
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading NGINX web server configuration..."
# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
# GENERIC FINALIZATION
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Upgrading logrotate configuration..."
# Use logrotate to manage app-specific logfile(s)
# Temporary fix for .txt log file and ynh_use_logrotate
if [ -d "$install_dir/data/log.txt" ]
then
ynh_secure_remove "$install_dir/data/log.txt"
touch "$install_dir/data/log.txt"
fi
chown $app:www-data "$install_dir/data/log.txt"
ynh_use_logrotate --non-append --specific_user=$app
#=================================================
# UPGRADE FAIL2BAN
#=================================================
ynh_script_progression --message="Reconfiguring Fail2Ban..."
# Create a dedicated Fail2Ban config
ynh_add_fail2ban_config --logpath="$install_dir/data/log.txt" --failregex="\s-\s<HOST>\s-\sLogin failed for user.*$"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed"