1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/freshrss_ynh.git synced 2024-09-03 18:36:33 +02:00
freshrss_ynh/scripts/upgrade

194 lines
6.8 KiB
Text
Raw Normal View History

2014-09-21 12:12:55 +02:00
#!/bin/bash
2016-08-31 08:44:08 +02:00
2019-02-23 11:48:57 +01:00
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
2020-09-04 22:24:17 +02:00
ynh_script_progression --message="Loading installation settings..."
2019-02-23 11:48:57 +01:00
app=$YNH_APP_INSTANCE_NAME
2019-07-02 00:38:57 +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)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
language=$(ynh_app_setting_get --app=$app --key=language)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
2020-10-01 22:19:32 +02:00
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
2019-07-02 00:38:57 +02:00
#=================================================
# CHECK VERSION
#=================================================
upgrade_type=$(ynh_check_app_version_changed)
2016-08-31 08:44:08 +02:00
2018-10-21 17:55:39 +02:00
#=================================================
2019-02-23 11:48:57 +01:00
# ENSURE DOWNWARD COMPATIBILITY
2018-10-21 17:55:39 +02:00
#=================================================
2020-09-04 22:24:17 +02:00
ynh_script_progression --message="Ensuring downward compatibility..."
2019-02-23 11:48:57 +01:00
# If db_name doesn't exist, create it
2019-07-02 00:38:57 +02:00
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
2019-02-23 11:48:57 +01:00
fi
2019-07-02 00:38:57 +02:00
if [ -z "$admin" ]; then
admin=$(ynh_app_setting_get --app=$app --key=admin_user)
if [ -z $admin ]; then
ynh_die --message="no admin user found"
fi;
2019-07-02 00:38:57 +02:00
ynh_app_setting_delete --app=$app --key=admin_user
ynh_app_setting_set --app=$app --key=admin --value=$admin
fi
2019-02-23 11:48:57 +01:00
# If final_path doesn't exist, create it
2019-07-02 00:38:57 +02:00
if [ -z "$final_path" ]; then
2019-02-23 11:48:57 +01:00
final_path=/var/www/$app
2019-07-02 00:38:57 +02:00
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
2019-02-23 11:48:57 +01:00
fi
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
2020-09-04 22:24:17 +02:00
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
2019-02-23 11:48:57 +01:00
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
# restore it if the upgrade fails
ynh_restore_upgradebackup
}
2018-10-21 17:55:39 +02:00
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
2019-02-23 11:48:57 +01:00
#=================================================
# CHECK THE PATH
#=================================================
# Normalize the URL path syntax
2019-07-02 00:38:57 +02:00
path_url=$(ynh_normalize_url_path --path_url=$path_url)
2018-10-21 17:55:39 +02:00
2019-02-23 11:48:57 +01:00
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
2020-09-04 22:24:17 +02:00
ynh_script_progression --message="Upgrading source files..."
2017-03-12 18:38:14 +01:00
2019-02-23 11:48:57 +01:00
# Download, check integrity, uncompress and patch the source from app.src
# into tmp dir
tmp_path=$(mktemp -d)
ynh_setup_source "$tmp_path"
2017-02-14 10:58:25 +01:00
2019-02-23 11:48:57 +01:00
#=================================================
# NGINX CONFIGURATION
#=================================================
2020-09-04 22:24:17 +02:00
ynh_script_progression --message="Upgrading NGINX web server configuration..."
2016-08-30 22:42:56 +02:00
2019-02-23 11:48:57 +01:00
# Create a dedicated nginx config
ynh_add_nginx_config
2017-03-05 20:56:16 +01:00
2019-02-23 11:48:57 +01:00
#=================================================
# CREATE DEDICATED USER
#=================================================
2020-09-04 22:24:17 +02:00
ynh_script_progression --message="Making sure dedicated system user exists..."
2019-02-23 11:48:57 +01:00
# Create a dedicated user (if not existing)
2020-10-01 22:19:32 +02:00
ynh_system_user_create --username=$app
2019-02-23 11:48:57 +01:00
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
2020-09-04 22:24:17 +02:00
ynh_script_progression --message="Upgrading PHP-FPM configuration..."
2019-02-23 11:48:57 +01:00
2020-09-04 22:39:46 +02:00
# Create a dedicated PHP-FPM config
2020-10-01 22:19:32 +02:00
ynh_add_fpm_config --phpversion=$YNH_PHP_VERSION --package="$extra_php_dependencies"
2019-02-23 11:48:57 +01:00
#=================================================
# SPECIFIC UPGRADE
#=================================================
#old version cleanup
if [ -f $final_path/data/user.php.dist ]; then
ynh_secure_remove $final_path/data/user.php.dist
2018-07-07 15:43:31 +02:00
fi
2019-02-23 11:48:57 +01:00
#restore config
ynh_secure_remove $tmp_path/data/do-install.txt
cp $final_path/data/config.php $tmp_path/data/config.php
cp -r $final_path/data/users/. $tmp_path/data/users/
cp -r $final_path/extensions/. $tmp_path/extensions/
2016-08-30 22:42:56 +02:00
2019-02-23 11:48:57 +01:00
# Set permissions to freshrss directory
# Clean up existing files and copy new files to the right place
ynh_secure_remove "$final_path"
cp -rp "$tmp_path" "$final_path"
2016-08-30 22:42:56 +02:00
2018-10-20 10:31:29 +02:00
#update hook for multi instance
2020-09-04 22:24:17 +02:00
ynh_replace_string --match_string="APPNAMETOCHANGE" --replace_string=$app --target_file="../hooks/post_app_addaccess"
ynh_replace_string --match_string="APPNAMETOCHANGE" --replace_string=$app --target_file="../hooks/post_user_create"
ynh_replace_string --match_string="APPNAMETOCHANGE" --replace_string=$app --target_file="../hooks/post_user_delete"
2019-02-23 11:48:57 +01:00
2019-05-27 12:44:46 +02:00
#=================================================
# CRON SETUP
#=================================================
2020-09-04 22:24:17 +02:00
ynh_script_progression --message="Setting up cron..."
2019-11-13 01:03:28 +01:00
2019-05-27 12:44:46 +02:00
cron_path="/etc/cron.d/$app"
2020-09-04 22:39:46 +02:00
ynh_replace_string --match_string="__FINALPATH__" --replace_string=$final_path --target_file="../conf/freshrss.cron"
ynh_replace_string --match_string="__APP__" --replace_string=$app --target_file="../conf/freshrss.cron"
2019-05-27 12:44:46 +02:00
cp ../conf/freshrss.cron "$cron_path"
chmod 644 "$cron_path"
if [ -f /tmp/FreshRSS.log ]; then
ynh_secure_remove /tmp/FreshRSS.log
fi
2019-02-23 11:48:57 +01:00
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# Set permissions on app files
chown -R root: $final_path
chmod 755 $final_path
2020-09-04 22:24:17 +02:00
chown -R $app: $final_path/{data,extensions}
2019-02-23 11:48:57 +01:00
# reconfigure application with latest parameters
$final_path/cli/reconfigure.php --default_user $admin --auth_type http_auth --environment production --base_url https://$domain$path_url --title FreshRSS --api_enabled --db-type mysql --db-host localhost --db-user $db_name --db-password $db_pwd --db-base $db_name
2019-07-02 00:38:57 +02:00
2019-02-23 11:48:57 +01:00
#=================================================
# SETUP SSOWAT
#=================================================
2020-09-04 22:24:17 +02:00
ynh_script_progression --message="Upgrading SSOwat configuration..."
2018-10-20 10:31:29 +02:00
2020-04-05 09:48:43 +02:00
ynh_app_setting_set --app="$app" --key=skipped_uris --value="/api/,/scripts/api.js"
2019-10-24 20:02:48 +02:00
ynh_app_setting_delete --app="$app" --key=unprotected_regex
2020-04-05 09:48:43 +02:00
ynh_app_setting_delete --app="$app" --key=unprotected_uris
2016-08-30 22:42:56 +02:00
2019-02-23 11:48:57 +01:00
#=================================================
# RELOAD NGINX
#=================================================
2020-09-04 22:39:46 +02:00
ynh_script_progression --message="Reloading NGINX web server..."
2019-02-23 11:48:57 +01:00
2019-07-02 00:38:57 +02:00
ynh_systemd_action --service_name=nginx --action=reload
2019-02-23 11:48:57 +01:00
#=================================================
# END OF SCRIPT
#=================================================
2020-09-04 22:24:17 +02:00
ynh_script_progression --message="Upgrade of $app completed"