2023-12-20 19:03:04 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
2023-12-20 19:08:54 +01:00
|
|
|
# CHECK VERSION
|
2023-12-20 19:03:04 +01:00
|
|
|
#=================================================
|
2023-12-20 19:08:54 +01:00
|
|
|
ynh_script_progression --message="Checking version..."
|
2023-12-20 19:03:04 +01:00
|
|
|
|
2023-12-20 19:08:54 +01:00
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
2023-12-20 19:03:04 +01:00
|
|
|
|
2023-12-20 19:08:54 +01:00
|
|
|
#=================================================
|
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
|
|
#=================================================
|
2023-12-20 19:03:04 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STOP SYSTEMD SERVICE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Stopping a systemd service..." --weight=1
|
|
|
|
|
2023-12-20 19:08:54 +01:00
|
|
|
# Stop service before backup, to not loose message in case of failed upgrade and restore
|
2023-12-29 16:09:53 +01:00
|
|
|
ynh_systemd_action --service_name=$app --action="stop" --log_path=systemd
|
2023-12-20 19:03:04 +01:00
|
|
|
|
|
|
|
#=================================================
|
2023-12-20 19:08:54 +01:00
|
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD UPGRADE STEPS
|
|
|
|
#=================================================
|
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
|
|
|
|
|
|
|
|
# If db_name doesn't exist, create it
|
|
|
|
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
|
|
|
|
fi
|
|
|
|
|
|
|
|
# If install_dir doesn't exist, create it
|
|
|
|
if [ -z "$install_dir" ]; then
|
|
|
|
install_dir=/var/www/$app
|
|
|
|
ynh_app_setting_set --app=$app --key=install_dir --value=$install_dir
|
|
|
|
fi
|
|
|
|
|
2023-12-20 19:03:04 +01:00
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
2023-12-22 15:44:21 +01:00
|
|
|
|
2023-12-20 19:03:04 +01:00
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
2023-12-23 07:48:22 +01:00
|
|
|
|
2023-12-23 10:08:46 +01:00
|
|
|
then
|
|
|
|
ynh_script_progression --message="Upgrading source files..." --weight=5
|
|
|
|
|
|
|
|
pushd $install_dir
|
|
|
|
chown -R $app:www-data "$install_dir"
|
2024-05-25 09:23:01 +02:00
|
|
|
ynh_exec_warn_less ynh_exec_as $app git config --global --add safe.directory "$install_dir"
|
2023-12-29 14:06:51 +01:00
|
|
|
ynh_exec_warn_less ynh_exec_as $app git fetch
|
|
|
|
ynh_exec_warn_less ynh_exec_as $app git pull
|
2023-12-23 10:08:46 +01:00
|
|
|
popd
|
2023-12-20 19:03:04 +01:00
|
|
|
fi
|
|
|
|
|
2023-12-20 19:08:54 +01:00
|
|
|
chmod 750 "$install_dir"
|
|
|
|
chmod -R o-rwx "$install_dir"
|
2023-12-20 19:03:04 +01:00
|
|
|
chown -R $app:www-data "$install_dir"
|
|
|
|
|
2023-12-22 14:23:16 +01:00
|
|
|
|
2023-12-20 19:03:04 +01:00
|
|
|
#=================================================
|
2023-12-20 19:08:54 +01:00
|
|
|
# UPGRADE DEPENDENCIES
|
2023-12-20 19:03:04 +01:00
|
|
|
#=================================================
|
2023-12-20 19:08:54 +01:00
|
|
|
ynh_script_progression --message="Upgrading dependencies..." --weight=5
|
2023-12-20 19:03:04 +01:00
|
|
|
|
2023-12-20 19:08:54 +01:00
|
|
|
ynh_install_nodejs --nodejs_version=$NODEJS_VERSION
|
2023-12-20 19:03:04 +01:00
|
|
|
|
2023-12-20 19:08:54 +01:00
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1
|
2023-12-20 19:03:04 +01:00
|
|
|
|
2023-12-20 19:08:54 +01:00
|
|
|
# Create a dedicated NGINX config
|
2023-12-20 19:03:04 +01:00
|
|
|
ynh_add_nginx_config
|
|
|
|
|
2023-12-20 19:08:54 +01:00
|
|
|
#=================================================
|
|
|
|
# BUILD APP
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Building app..."
|
2023-12-20 19:03:04 +01:00
|
|
|
|
2023-12-20 19:08:54 +01:00
|
|
|
pushd "$install_dir"
|
|
|
|
ynh_use_nodejs
|
2024-05-12 15:35:21 +02:00
|
|
|
env $ynh_node_load_PATH corepack enable
|
|
|
|
env $ynh_node_load_PATH COREPACK_ENABLE_DOWNLOAD_PROMPT=0 corepack prepare --activate
|
|
|
|
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH COREPACK_ENABLE_DOWNLOAD_PROMPT=0 yarn cleanall
|
2023-12-20 19:08:54 +01:00
|
|
|
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH yarn install
|
|
|
|
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH NODE_ENV=production yarn build
|
|
|
|
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH yarn migrate
|
|
|
|
popd
|
2023-12-20 19:03:04 +01:00
|
|
|
|
2023-12-20 19:08:54 +01:00
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrading systemd configuration..." --weight=1
|
2023-12-20 19:03:04 +01:00
|
|
|
|
2023-12-20 19:08:54 +01:00
|
|
|
# Create a dedicated systemd config
|
|
|
|
ynh_add_systemd_config
|
2023-12-20 19:03:04 +01:00
|
|
|
|
|
|
|
#=================================================
|
2023-12-20 19:08:54 +01:00
|
|
|
# GENERIC FINALIZATION
|
2023-12-20 19:03:04 +01:00
|
|
|
#=================================================
|
2023-12-20 19:08:54 +01:00
|
|
|
# SETUP LOGROTATE
|
2023-12-20 19:03:04 +01:00
|
|
|
#=================================================
|
2023-12-20 19:08:54 +01:00
|
|
|
ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1
|
2023-12-20 19:03:04 +01:00
|
|
|
|
2023-12-20 19:08:54 +01:00
|
|
|
# Use logrotate to manage app-specific logfile(s)
|
|
|
|
ynh_use_logrotate --non-append
|
2023-12-20 19:03:04 +01:00
|
|
|
|
2023-12-20 19:08:54 +01:00
|
|
|
#=================================================
|
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
|
2023-12-20 19:03:04 +01:00
|
|
|
|
2023-12-20 19:08:54 +01:00
|
|
|
yunohost service add $app --description="A interplanetary blogging platform" --log="/var/log/$app/$app.log"
|
2023-12-20 19:03:04 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Starting a systemd service..." --weight=1
|
|
|
|
|
2023-12-29 16:09:53 +01:00
|
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path=systemd
|
2023-12-20 19:08:54 +01:00
|
|
|
|
2023-12-20 19:03:04 +01:00
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2023-12-20 19:08:54 +01:00
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|