1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/code-server_ynh.git synced 2024-09-03 18:16:28 +02:00
code-server_ynh/scripts/upgrade

146 lines
4.8 KiB
Text
Raw Normal View History

2021-05-27 02:26:40 +02:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
2021-05-29 05:47:54 +02:00
ynh_script_progression --message="Loading installation settings..." --weight=1
2021-05-27 02:26:40 +02:00
2021-05-29 05:47:54 +02:00
load_settings
2021-05-27 02:26:40 +02:00
#=================================================
# CHECK VERSION
#=================================================
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
2021-05-29 05:47:54 +02:00
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=50
2021-05-27 02:26:40 +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
#=================================================
2021-05-29 05:47:54 +02:00
ynh_script_progression --message="Stopping a systemd service..." --weight=1
2021-05-27 02:26:40 +02:00
ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
2021-05-29 05:47:54 +02:00
ynh_script_progression --message="Upgrading source files..." --weight=5
2021-05-27 02:26:40 +02:00
2021-05-29 05:47:54 +02:00
setup_source
2021-05-27 02:26:40 +02:00
fi
#=================================================
# NGINX CONFIGURATION
#=================================================
2021-05-29 05:47:54 +02:00
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1
2021-05-27 02:26:40 +02:00
# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
2021-05-29 05:47:54 +02:00
ynh_script_progression --message="Upgrading dependencies..." --weight=15
2021-05-27 02:26:40 +02:00
2021-05-29 05:47:54 +02:00
install_dependencies
2021-05-27 02:26:40 +02:00
#=================================================
# SPECIFIC UPGRADE
#=================================================
2021-05-29 05:47:54 +02:00
# BUILD APP
2021-05-27 02:26:40 +02:00
#=================================================
2021-05-29 05:47:54 +02:00
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Compiling code-server..." --weight=600
2021-05-27 02:26:40 +02:00
2021-05-29 05:47:54 +02:00
build_app
fi
2021-05-27 02:26:40 +02:00
2021-05-29 05:47:54 +02:00
#=================================================
# UPDATE CONFIG FILES
#=================================================
ynh_script_progression --message="Updating a configuration file..." --weight=1
2021-05-27 02:26:40 +02:00
2021-05-29 05:47:54 +02:00
add_configs
2021-05-27 02:26:40 +02:00
#=================================================
# SETUP SYSTEMD
#=================================================
2021-05-29 05:47:54 +02:00
ynh_script_progression --message="Upgrading systemd configuration..." --weight=1
2021-05-27 02:26:40 +02:00
# Create a dedicated systemd config
ynh_add_systemd_config
#=================================================
# GENERIC FINALIZATION
#=================================================
# SETUP LOGROTATE
#=================================================
2021-05-29 05:47:54 +02:00
ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1
2021-05-27 02:26:40 +02:00
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
2021-05-29 05:47:54 +02:00
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
2021-05-27 02:26:40 +02:00
2021-05-29 05:47:54 +02:00
yunohost service add $app --description="Server for accessing VS Code from the browser" --log="/var/log/$app/$app.log"
2021-05-27 02:26:40 +02:00
#=================================================
# START SYSTEMD SERVICE
#=================================================
2021-05-29 05:47:54 +02:00
ynh_script_progression --message="Starting a systemd service..." --weight=1
2021-05-27 02:26:40 +02:00
2021-05-29 05:47:54 +02:00
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" --line_match=" HTTP server listening on "
2021-05-27 02:26:40 +02:00
#=================================================
# UPGRADE FAIL2BAN
#=================================================
2021-05-29 05:47:54 +02:00
ynh_script_progression --message="Reconfiguring Fail2Ban..." --weight=1
2021-05-27 02:26:40 +02:00
# Create a dedicated Fail2Ban config
2021-05-29 05:47:54 +02:00
ynh_add_fail2ban_config --logpath="/var/log/$app/$app.log" --failregex='^Failed login attempt {"xForwardedFor":"<HOST>"'
2021-05-27 02:26:40 +02:00
#=================================================
# RELOAD NGINX
#=================================================
2021-05-29 05:47:54 +02:00
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
2021-05-27 02:26:40 +02:00
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
2021-05-29 05:47:54 +02:00
ynh_script_progression --message="Upgrade of $app completed" --last