1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/gotosocial_ynh.git synced 2024-09-03 19:16:06 +02:00
gotosocial_ynh/scripts/upgrade

193 lines
7.1 KiB
Text
Raw Normal View History

2021-08-15 21:48:06 +02:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..."
2021-08-15 21:48:06 +02:00
app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
2022-03-14 23:21:15 +01:00
domain=$(ynh_app_setting_get --app=$app --key=domain)
port=$(ynh_app_setting_get --app=$app --key=port)
2022-03-15 02:14:16 +01:00
path_url=$(ynh_app_setting_get --app=$app --key=path_url)
2022-03-14 23:21:15 +01:00
2021-08-15 21:48:06 +02:00
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
2022-03-14 23:21:15 +01:00
db_user=$(ynh_app_setting_get --app=$app --key=db_user)
db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd)
2022-03-15 02:14:16 +01:00
registration_open=$(ynh_app_setting_get --app=$app --key=registration_open)
2022-03-14 23:21:15 +01:00
registration_approval=$(ynh_app_setting_get --app=$app --key=registration_approval)
registration_reason=$(ynh_app_setting_get --app=$app --key=registration_reason)
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
2021-08-15 21:48:06 +02:00
#=================================================
# CHECK VERSION
#=================================================
### This helper will compare the version of the currently installed app and the version of the upstream package.
### $upgrade_type can have 2 different values
### - UPGRADE_APP if the upstream app version has changed
### - UPGRADE_PACKAGE if only the YunoHost package has changed
### ynh_check_app_version_changed will stop the upgrade if the app is up to date.
### UPGRADE_APP should be used to upgrade the core app only if there's an upgrade to do.
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)..."
2021-08-15 21:48:06 +02:00
# 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
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..."
2021-08-15 21:48:06 +02:00
ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Making sure dedicated system user exists..."
2021-08-15 21:48:06 +02:00
# 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..."
2021-08-15 21:48:06 +02:00
2022-03-15 22:47:43 +01:00
# ynh_detect_arch comes from _common.sh / personnal helpers
architecture=$ynh_detect_arch
2021-08-15 21:48:06 +02:00
# Download, check integrity, uncompress and patch the source from app.src
2022-03-15 02:14:16 +01:00
ynh_setup_source --dest_dir="$final_path" --source_id=$architecture --keep="config.yaml"
2021-08-15 21:48:06 +02:00
fi
# FIXME: this should be managed by the core in the future
# Here, as a packager, you may have to tweak the ownerhsip/permissions
# such that the appropriate users (e.g. maybe www-data) can access
# files in some cases.
# But FOR THE LOVE OF GOD, do not allow r/x for "others" on the entire folder -
# this will be treated as a security issue.
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:www-data "$final_path"
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading NGINX web server configuration..."
2021-08-15 21:48:06 +02:00
# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
ynh_script_progression --message="Upgrading dependencies..."
2021-08-15 21:48:06 +02:00
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# SPECIFIC UPGRADE
#=================================================
# ...
#=================================================
#=================================================
# UPDATE A CONFIG FILE
#=================================================
ynh_script_progression --message="Updating a configuration file..."
2021-08-15 21:48:06 +02:00
### Same as during install
###
### The file will automatically be backed-up if it's found to be manually modified (because
### ynh_add_config keeps track of the file's checksum)
2022-03-14 19:54:17 +01:00
ynh_add_config --template="config.yaml" --destination="$final_path/config.yaml"
2021-08-15 21:48:06 +02:00
# FIXME: this should be handled by the core in the future
# You may need to use chmod 600 instead of 400,
# for example if the app is expected to be able to modify its own config
2022-03-14 19:54:17 +01:00
chmod 400 "$final_path/config.yaml"
chown $app:$app "$final_path/config.yaml"
2021-08-15 21:48:06 +02:00
### For more complex cases where you want to replace stuff using regexes,
### you shoud rely on ynh_replace_string (which is basically a wrapper for sed)
### When doing so, you also need to manually call ynh_store_file_checksum
###
### ynh_replace_string --match_string="match_string" --replace_string="replace_string" --target_file="$final_path/some_config_file"
### ynh_store_file_checksum --file="$final_path/some_config_file"
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Upgrading systemd configuration..."
2021-08-15 21:48:06 +02:00
# Create a dedicated systemd config
ynh_add_systemd_config
#=================================================
# GENERIC FINALIZATION
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Upgrading logrotate configuration..."
2021-08-15 21:48:06 +02:00
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
2021-08-15 21:48:06 +02:00
2022-03-13 21:46:54 +01:00
yunohost service add $app --description="Gotosocial server" --log="/var/log/$app/$app.log"
2021-08-15 21:48:06 +02:00
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..."
2021-08-15 21:48:06 +02:00
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..."
2021-08-15 21:48:06 +02:00
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed"