2013-12-19 03:02:51 +01:00
#!/bin/bash
2018-06-25 05:57:41 +02:00
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
2020-11-24 19:35:51 +01:00
#=================================================
# CHECK VERSION
#=================================================
upgrade_type=$(ynh_check_app_version_changed)
2020-11-01 16:00:22 +01:00
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
2021-02-28 21:54:57 +01:00
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)
2020-11-01 16:00:22 +01:00
then
2023-11-15 11:26:05 +01:00
ynh_script_progression --message="Upgrading source files..." --weight=1
2020-11-01 16:00:22 +01:00
2020-12-01 12:03:07 +01:00
# Create a temporary directory
tmpdir="$(mktemp -d)"
# Backup the config file in the temp dir
2023-03-21 18:14:35 +01:00
cp -a "$install_dir/data" "$tmpdir/data"
cp -a "$install_dir/tpl" "$tmpdir/tpl"
2020-12-01 12:03:07 +01:00
2020-11-01 16:00:22 +01:00
# Download, check integrity, uncompress and patch the source from app.src
2023-03-21 18:14:35 +01:00
ynh_setup_source --dest_dir="$install_dir"
2020-11-01 16:00:22 +01:00
2023-03-21 18:14:35 +01:00
cp -a "$tmpdir/data" "$install_dir/"
cp -a -n "$tmpdir/tpl" "$install_dir/" # copy without erasing existing templates (from official source)
2018-06-25 05:57:41 +02:00
2020-12-01 12:03:07 +01:00
# Remove the tmp directory securely
ynh_secure_remove --file="$tmpdir"
fi
2018-06-25 05:57:41 +02:00
2023-03-21 18:14:35 +01:00
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"
2020-11-01 16:00:22 +01:00
2018-06-25 05:57:41 +02:00
#=================================================
2023-11-15 11:26:05 +01:00
# REAPPLY SYSTEM CONFIGURATIONS
2018-06-25 05:57:41 +02:00
#=================================================
2023-11-15 11:26:05 +01:00
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
2018-06-25 05:57:41 +02:00
2022-07-22 00:47:28 +02:00
# Create a dedicated PHP-FPM config
2023-11-15 11:17:59 +01:00
ynh_add_fpm_config
2018-06-25 05:57:41 +02:00
2022-07-22 00:47:28 +02:00
# Create a dedicated NGINX config
ynh_add_nginx_config
2018-09-27 22:44:34 +02:00
# Use logrotate to manage app-specific logfile(s)
2019-07-28 08:33:23 +02:00
# Temporary fix for .txt log file and ynh_use_logrotate
2023-03-21 18:14:35 +01:00
if [ -d "$install_dir/data/log.txt" ]
2019-09-26 14:21:49 +02:00
then
2023-03-21 18:14:35 +01:00
ynh_secure_remove "$install_dir/data/log.txt"
2023-05-11 09:56:38 +02:00
touch "$install_dir/data/log.txt"
2019-09-26 14:21:49 +02:00
fi
2023-03-21 18:14:35 +01:00
chown $app:www-data "$install_dir/data/log.txt"
2020-12-01 12:03:07 +01:00
2023-05-11 09:56:38 +02:00
ynh_use_logrotate --non-append --specific_user=$app
2018-09-27 22:44:34 +02:00
2020-12-01 13:35:39 +01:00
# Create a dedicated Fail2Ban config
2023-03-21 18:14:35 +01:00
ynh_add_fail2ban_config --logpath="$install_dir/data/log.txt" --failregex="\s-\s<HOST>\s-\sLogin failed for user.*$"
2018-06-25 05:57:41 +02:00
2019-04-05 12:29:32 +02:00
#=================================================
# END OF SCRIPT
#=================================================
2020-11-01 16:00:22 +01:00
ynh_script_progression --message="Upgrade of $app completed"