1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/thelounge_ynh.git synced 2024-09-03 20:35:54 +02:00
thelounge_ynh/scripts/upgrade

176 lines
6.1 KiB
Text
Raw Normal View History

2015-08-22 20:24:46 +02:00
#!/bin/bash
2018-05-01 12:25:53 +02:00
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2015-08-22 20:24:46 +02:00
2018-05-01 12:25:53 +02:00
source _common.sh
source /usr/share/yunohost/helpers
2015-08-22 20:24:46 +02:00
2018-05-01 12:25:53 +02:00
#=================================================
# LOAD SETTINGS
#=================================================
2023-03-14 16:44:09 +01:00
#REMOVEME? ynh_script_progression --message="Loading installation settings..." --weight=1
2015-08-22 20:24:46 +02:00
2023-03-14 16:44:09 +01:00
#REMOVEME? app=$YNH_APP_INSTANCE_NAME
2015-08-22 22:22:45 +02:00
2023-03-14 16:44:09 +01:00
#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain)
#REMOVEME? path=$(ynh_app_setting_get --app=$app --key=path)
#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir)
#REMOVEME? data_dir=$(ynh_app_setting_get --app=$app --key=data_dir)
#REMOVEME? port=$(ynh_app_setting_get --app=$app --key=port)
2015-08-22 20:24:46 +02:00
2019-10-25 11:04:41 +02:00
#=================================================
# CHECK VERSION
#=================================================
upgrade_type=$(ynh_check_app_version_changed)
2021-08-02 08:23:59 +02:00
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
2023-03-14 16:44:09 +01:00
#REMOVEME? ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1
2021-08-02 08:23:59 +02:00
# Backup the current version of the app
2023-03-14 16:44:09 +01:00
#REMOVEME? ynh_backup_before_upgrade
#REMOVEME? ynh_clean_setup () {
2021-08-02 08:23:59 +02:00
ynh_clean_check_starting
# restore it if the upgrade fails
2023-03-14 16:44:09 +01:00
#REMOVEME? ynh_restore_upgradebackup
2021-08-02 08:23:59 +02:00
}
# Exit if an error occurs during the execution of the script
2023-03-14 16:44:09 +01:00
#REMOVEME? ynh_abort_if_errors
2021-08-02 08:23:59 +02:00
2018-05-01 12:25:53 +02:00
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
2021-11-23 08:28:18 +01:00
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
2015-08-22 20:24:46 +02:00
2023-03-14 16:44:09 +01:00
# If install_dir doesn't exist, create it
if [ -z "$install_dir" ]; then
#REMOVEME? install_dir=/var/www/$app
#REMOVEME? ynh_app_setting_set --app=$app --key=install_dir --value=$install_dir
2018-05-01 12:25:53 +02:00
fi
2015-08-22 20:24:46 +02:00
2023-03-14 16:44:09 +01:00
# If data_dir doesn't exist, create it
if [ -z "$data_dir" ]; then
data_dir=/home/yunohost.app/$app
2021-03-22 10:00:33 +01:00
mkdir -p /home/yunohost.app/$app
2023-03-14 16:44:09 +01:00
#REMOVEME? ynh_app_setting_set --app=$app --key=data_dir --value=$data_dir
2015-08-22 20:24:46 +02:00
fi
2021-03-14 23:48:12 +01:00
# Cleaning legacy permissions
2023-03-14 16:44:09 +01:00
#REMOVEME? if ynh_legacy_permissions_exists; then
#REMOVEME? ynh_legacy_permissions_delete_all
2021-03-14 23:48:12 +01:00
ynh_app_setting_delete --app=$app --key=is_public
fi
2018-05-01 12:25:53 +02:00
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
2019-10-25 11:04:41 +02:00
# STOP SYSTEMD SERVICE
2018-05-01 12:25:53 +02:00
#=================================================
2021-11-23 08:28:18 +01:00
ynh_script_progression --message="Stopping a systemd service..." --weight=1
2018-05-01 12:25:53 +02:00
2021-03-22 10:00:33 +01:00
ynh_systemd_action --service_name=$app --action=stop --log_path=systemd
2015-08-22 20:24:46 +02:00
2021-03-22 09:06:18 +01:00
#=================================================
# CREATE DEDICATED USER
#=================================================
2023-03-14 16:44:09 +01:00
#REMOVEME? ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
2021-03-22 09:06:18 +01:00
# Create a dedicated user (if not existing)
2023-03-14 16:44:09 +01:00
#REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir"
2021-03-22 09:06:18 +01:00
2018-05-01 12:25:53 +02:00
#=================================================
2019-10-25 11:04:41 +02:00
# DOWNLOAD, CHECK AND UNPACK SOURCE
2018-05-01 12:25:53 +02:00
#=================================================
2015-08-22 20:24:46 +02:00
2019-10-25 11:04:41 +02:00
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
2021-11-23 08:28:18 +01:00
ynh_script_progression --message="Upgrading source files..." --weight=2
2020-05-27 17:03:30 +02:00
2023-03-14 16:44:09 +01:00
#REMOVEME? ynh_secure_remove --file="$install_dir"
2019-10-25 11:04:41 +02:00
# Download, check integrity, uncompress and patch the source from app.src
2023-03-14 16:44:09 +01:00
ynh_setup_source --dest_dir=$install_dir
2019-10-25 11:04:41 +02:00
fi
2018-05-01 12:25:53 +02:00
2023-03-14 16:44:09 +01:00
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R $app:www-data "$install_dir"
chown -R $app:www-data $data_dir
2021-08-02 08:23:59 +02:00
2018-05-03 19:57:18 +02:00
#=================================================
2020-05-30 19:18:05 +02:00
# NGINX CONFIGURATION
2018-05-03 19:57:18 +02:00
#=================================================
2021-11-23 08:28:18 +01:00
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=2
2018-05-03 19:57:18 +02:00
2020-08-09 14:48:13 +02:00
# Create a dedicated NGINX config
2020-05-30 19:18:05 +02:00
ynh_add_nginx_config
2020-05-27 17:03:30 +02:00
#=================================================
2020-05-30 19:18:05 +02:00
# UPGRADE DEPENDENCIES
2020-05-27 17:03:30 +02:00
#=================================================
2023-03-14 16:44:09 +01:00
#REMOVEME? ynh_script_progression --message="Upgrading dependencies..." --weight=5
2020-05-27 17:03:30 +02:00
# Install Nodejs
2020-05-29 22:51:48 +02:00
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
2020-05-27 17:03:30 +02:00
# Install Yarn
2023-03-14 16:44:09 +01:00
#REMOVEME? ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
2018-05-03 19:57:18 +02:00
2020-05-30 19:18:05 +02:00
#=================================================
# SPECIFIC UPGRADE
2018-05-01 22:09:53 +02:00
#=================================================
2019-10-25 11:04:41 +02:00
# UPGRADE THE LOUNGE
2018-05-01 22:09:53 +02:00
#=================================================
2019-10-25 11:04:41 +02:00
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
2023-03-14 16:44:09 +01:00
pushd $install_dir
2022-01-04 14:31:04 +01:00
ynh_use_nodejs
2022-01-04 11:14:08 +01:00
ynh_exec_warn_less sudo -u $app env $ynh_node_load_PATH yarn install
2022-01-04 14:31:04 +01:00
ynh_exec_warn_less sudo -u $app env $ynh_node_load_PATH NODE_ENV=production yarn build
2020-05-27 17:03:30 +02:00
popd
2019-10-25 11:04:41 +02:00
fi
2018-05-01 22:09:53 +02:00
2019-10-25 11:04:41 +02:00
#=================================================
# SETUP SYSTEMD
#=================================================
2021-11-23 08:28:18 +01:00
ynh_script_progression --message="Upgrading systemd configuration..." --weight=2
2018-05-01 22:09:53 +02:00
2022-03-27 10:59:38 +02:00
env_path="$PATH"
2020-05-27 17:03:30 +02:00
ynh_add_systemd_config
2018-05-01 12:25:53 +02:00
2019-10-25 11:04:41 +02:00
#=================================================
2020-05-30 19:18:05 +02:00
# GENERIC FINALIZATION
2018-05-01 12:25:53 +02:00
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
2021-11-23 08:28:18 +01:00
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
2018-05-01 12:25:53 +02:00
2020-12-14 11:14:10 +01:00
yunohost service add $app --description="Client Web IRC" --log="/var/log/$app/$app.log"
2018-05-01 12:25:53 +02:00
2019-10-25 11:04:41 +02:00
#=================================================
# START SYSTEMD SERVICE
#=================================================
2021-11-23 08:28:18 +01:00
ynh_script_progression --message="Starting a systemd service..." --weight=1
2019-10-25 11:04:41 +02:00
2021-08-30 22:37:35 +02:00
ynh_systemd_action --service_name=$app --action=start --log_path=systemd
2019-10-25 11:04:41 +02:00
2018-05-01 12:25:53 +02:00
#=================================================
# RELOAD NGINX
#=================================================
2023-03-14 16:44:09 +01:00
#REMOVEME? ynh_script_progression --message="Reloading NGINX web server..." --weight=1
2019-10-25 11:04:41 +02:00
2023-03-14 16:44:09 +01:00
#REMOVEME? ynh_systemd_action --service_name=nginx --action=reload
2019-10-25 11:04:41 +02:00
#=================================================
# END OF SCRIPT
#=================================================
2018-05-01 12:25:53 +02:00
2021-11-23 08:28:18 +01:00
ynh_script_progression --message="Upgrade of $app completed" --last