2021-12-05 09:05:11 +01: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..." --weight=2
|
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
|
|
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
|
|
|
path_url=$(ynh_app_setting_get --app=$app --key=path)
|
|
|
|
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK VERSION
|
|
|
|
#=================================================
|
2022-03-19 19:08:33 +01:00
|
|
|
ynh_script_progression --message="Checking version..."
|
2021-12-05 09:05:11 +01:00
|
|
|
|
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
|
|
#=================================================
|
2022-03-19 19:08:33 +01:00
|
|
|
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=20
|
2021-12-05 09:05:11 +01:00
|
|
|
|
|
|
|
# Backup the current version of the app
|
|
|
|
ynh_backup_before_upgrade
|
|
|
|
ynh_clean_setup () {
|
2022-03-19 19:08:33 +01:00
|
|
|
ynh_clean_check_starting
|
|
|
|
# Restore it if the upgrade fails
|
|
|
|
ynh_restore_upgradebackup
|
2021-12-05 09:05:11 +01:00
|
|
|
}
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD UPGRADE STEPS
|
|
|
|
#=================================================
|
2022-05-31 00:12:17 +02:00
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
2021-12-05 09:05:11 +01:00
|
|
|
#=================================================
|
2022-05-31 00:12:17 +02:00
|
|
|
ynh_script_progression --message="Ensuring downward compatibility..."
|
2021-12-05 09:05:11 +01:00
|
|
|
|
2022-05-31 00:12:17 +02:00
|
|
|
# Remove the service from the list of services known by Yunohost (added from `yunohost service add`)
|
|
|
|
if ynh_exec_warn_less yunohost service status $app >/dev/null
|
|
|
|
then
|
|
|
|
ynh_script_progression --message="Removing $app service..." --weight=1
|
|
|
|
yunohost service remove $app
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Remove the dedicated systemd config
|
|
|
|
ynh_remove_systemd_config
|
|
|
|
|
|
|
|
# Remove the app-specific logrotate config
|
|
|
|
ynh_remove_logrotate
|
2021-12-05 09:05:11 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
|
|
|
|
|
|
|
|
# Create a dedicated user (if not existing)
|
2022-03-19 19:08:33 +01:00
|
|
|
ynh_system_user_create --username=$app --home_dir="$final_path"
|
2021-12-05 09:05:11 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
|
|
|
then
|
|
|
|
ynh_script_progression --message="Upgrading source files..." --weight=1
|
|
|
|
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
2022-05-31 00:12:17 +02:00
|
|
|
ynh_setup_source --dest_dir="$final_path/build"
|
2021-12-05 09:05:11 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
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..." --weight=2
|
|
|
|
|
2022-03-19 19:08:33 +01:00
|
|
|
# Create a dedicated NGINX config
|
2021-12-05 09:05:11 +01:00
|
|
|
ynh_add_nginx_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# UPGRADE DEPENDENCIES
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrading dependencies..." --weight=18
|
|
|
|
|
2022-05-31 00:12:17 +02:00
|
|
|
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
|
2021-12-05 09:05:11 +01:00
|
|
|
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
|
2022-05-31 00:12:17 +02:00
|
|
|
ynh_exec_warn_less ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
|
2021-12-05 09:05:11 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC UPGRADE
|
|
|
|
#=================================================
|
2022-03-19 19:08:33 +01:00
|
|
|
# BUILD APP
|
2021-12-05 09:05:11 +01:00
|
|
|
#=================================================
|
2022-05-31 00:12:17 +02:00
|
|
|
ynh_script_progression --message="Building app... (this will take some time and resources!)" --weight=40
|
2021-12-05 09:05:11 +01:00
|
|
|
|
2022-05-31 00:12:17 +02:00
|
|
|
pushd "$final_path/build"
|
|
|
|
ynh_use_nodejs
|
|
|
|
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH yarn install --ignore-optional
|
|
|
|
ynh_exec_warn_less ynh_exec_as $app env NODE_ENV=production $ynh_node_load_PATH yarn build
|
|
|
|
ynh_exec_warn_less ynh_exec_as $app env NODE_ENV=production $ynh_node_load_PATH yarn cache clean --all
|
|
|
|
popd
|
2021-12-05 09:05:11 +01:00
|
|
|
|
2022-05-31 00:12:17 +02:00
|
|
|
ynh_secure_remove --file="$final_path/live"
|
|
|
|
ynh_exec_as $app mv "$final_path/build/build" "$final_path/live"
|
|
|
|
ynh_secure_remove --file="$final_path/build"
|
2021-12-05 09:05:11 +01:00
|
|
|
|
2022-05-31 00:12:17 +02:00
|
|
|
chmod 750 "$final_path"
|
|
|
|
chmod -R o-rwx "$final_path"
|
|
|
|
chown -R $app:www-data "$final_path"
|
2021-12-05 09:05:11 +01:00
|
|
|
|
|
|
|
#=================================================
|
2022-05-31 00:12:17 +02:00
|
|
|
# GENERIC FINALIZATION
|
2021-12-05 09:05:11 +01:00
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
|
|
|
|
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|