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

218 lines
7.5 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
#=================================================
2020-05-27 17:03:30 +02:00
ynh_script_progression --message="Loading installation settings..."
2015-08-22 20:24:46 +02:00
2018-05-01 12:25:53 +02:00
app=$YNH_APP_INSTANCE_NAME
2015-08-22 22:22:45 +02:00
2020-05-27 18:18:11 +02:00
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
is_public=$(ynh_app_setting_get --app=$app --key=is_public)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
config_path=$(ynh_app_setting_get --app=$app --key=config_path)
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
#=================================================
2020-05-30 19:18:05 +02:00
ynh_script_progression --message="Checking version..."
2019-10-25 11:04:41 +02:00
upgrade_type=$(ynh_check_app_version_changed)
2018-05-01 12:25:53 +02:00
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
2020-05-27 17:03:30 +02:00
ynh_script_progression --message="Ensuring downward compatibility..."
2015-08-22 20:24:46 +02:00
2018-05-01 12:25:53 +02:00
# Fix is_public as a boolean value
if [ "$is_public" = "Yes" ]; then
2019-10-25 11:04:41 +02:00
ynh_app_setting_set --app=$app --key=is_public --value=1
2018-05-01 12:25:53 +02:00
is_public=1
elif [ "$is_public" = "No" ]; then
2019-10-25 11:04:41 +02:00
ynh_app_setting_set --app=$app --key=is_public --value=0
2018-05-01 12:25:53 +02:00
is_public=0
fi
# If final_path doesn't exist, create it
2019-10-25 11:04:41 +02:00
if [ -z "$final_path" ]; then
2018-05-01 12:25:53 +02:00
final_path=/var/www/$app
2019-10-25 11:04:41 +02:00
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
2018-05-01 12:25:53 +02:00
fi
2015-08-22 20:24:46 +02:00
2018-05-01 12:25:53 +02:00
# If config_path doesn't exist, create it
2019-10-25 11:04:41 +02:00
if [ -z "$config_path" ]; then
2019-10-26 20:08:23 +02:00
config_path=/home/yunohost.app/$app
ynh_app_setting_set --app=$app --key=config_path --value=$config_path
2015-08-22 20:24:46 +02:00
fi
2018-05-01 12:25:53 +02:00
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
2020-05-27 17:03:30 +02:00
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
2018-05-01 12:25:53 +02:00
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
2020-05-30 11:57:12 +02:00
ynh_clean_check_starting
2018-05-01 12:25:53 +02:00
# restore it if the upgrade fails
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# CHECK THE PATH
#=================================================
# Normalize the URL path syntax
2020-05-30 19:18:05 +02:00
path_url=$(ynh_normalize_url_path --path_url=$path_url)
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
#=================================================
2020-05-27 17:03:30 +02:00
ynh_script_progression --message="Stopping a systemd service..."
2018-05-01 12:25:53 +02:00
2020-05-29 22:51:48 +02:00
ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd"
2015-08-22 20:24:46 +02: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
2020-05-27 17:03:30 +02:00
ynh_script_progression --message="Upgrading source files..."
2020-05-29 22:51:48 +02:00
ynh_secure_remove --file=$final_path
2019-10-25 11:04:41 +02:00
# Download, check integrity, uncompress and patch the source from app.src
2020-05-30 19:18:05 +02:00
ynh_setup_source --dest_dir="$final_path"
2019-10-25 11:04:41 +02:00
fi
2018-05-01 12:25:53 +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
#=================================================
2020-05-30 19:18:05 +02:00
ynh_script_progression --message="Upgrading nginx web server configuration..."
2018-05-03 19:57:18 +02:00
2020-05-30 19:18:05 +02:00
# Create a dedicated nginx config
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
#=================================================
ynh_script_progression --message="Upgrading dependencies..."
# 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
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
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Making sure dedicated system user exists..."
# Create a dedicated user (if not existing)
ynh_system_user_create --username=$app
#=================================================
# 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
2020-05-30 19:18:05 +02:00
ynh_script_progression --message="Upgrading the lounge..."
2020-05-29 22:51:48 +02:00
pushd $final_path
2020-05-30 19:23:03 +02:00
ynh_use_nodejs
yarn install
ynh_exec_warn_less 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
#=================================================
2020-05-30 19:18:05 +02:00
# MODIFY A CONFIG FILE
2018-05-01 22:09:53 +02:00
#=================================================
2020-05-30 19:18:05 +02:00
ynh_script_progression --message="Modifying a config file..."
2018-05-01 22:09:53 +02:00
2020-05-30 19:18:05 +02:00
ynh_backup_if_checksum_is_different --file="$config_path"
# Main config File
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="../conf/config.js"
2018-05-01 22:09:53 +02:00
2020-05-30 19:18:05 +02:00
cp -a ../conf/config.js "$config_path"
ynh_store_file_checksum "$config_path/config.js"
2018-05-01 22:09:53 +02:00
2019-10-25 11:04:41 +02:00
#=================================================
# SETUP SYSTEMD
#=================================================
2020-05-30 19:18:05 +02:00
ynh_script_progression --message="Upgrading systemd configuration..."
2018-05-01 22:09:53 +02:00
2020-05-27 17:03:30 +02:00
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="../conf/systemd.service"
ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="../conf/systemd.service"
ynh_replace_string --match_string="__ENV_PATH__" --replace_string="$PATH" --target_file="../conf/systemd.service"
ynh_replace_string --match_string="__NODE__" --replace_string="$nodejs_path" --target_file="../conf/systemd.service"
2018-05-01 22:09:53 +02:00
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
2019-10-25 11:04:41 +02:00
#=================================================
2020-05-30 19:18:05 +02:00
# SECURE FILES AND DIRECTORIES
#=================================================
ynh_script_progression --message="Securing files and directories..."
2019-10-25 11:04:41 +02:00
2020-05-30 19:18:05 +02:00
# Set permissions on app files
chown -R $app: $final_path
chown -R $app: $config_path
2018-05-01 12:25:53 +02:00
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
2020-05-30 19:23:03 +02:00
ynh_script_progression --message="Integrating service in YunoHost..."
2018-05-01 12:25:53 +02:00
2020-05-30 19:23:03 +02:00
yunohost service add $app --description "Self-hosted web IRC client" --log_type "systemd"
2018-05-01 12:25:53 +02:00
#=================================================
2020-05-30 19:15:17 +02:00
# SETUP SSOWAT
2018-05-01 12:25:53 +02:00
#=================================================
2020-05-30 19:23:03 +02:00
ynh_script_progression --message="Upgrading SSOwat configuration..."
2018-05-01 12:25:53 +02:00
2020-05-30 19:15:17 +02:00
# Make app public if necessary
2020-05-30 19:23:03 +02:00
[ $is_public -eq 0 ] || ynh_permission_update --permission "main" --add "visitors"
2018-05-01 12:25:53 +02:00
2019-10-25 11:04:41 +02:00
#=================================================
# START SYSTEMD SERVICE
#=================================================
2020-05-27 17:03:30 +02:00
ynh_script_progression --message="Starting a systemd service..."
2019-10-25 11:04:41 +02:00
2020-05-30 11:57:12 +02:00
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Available at http"
2019-10-25 11:04:41 +02:00
2018-05-01 12:25:53 +02:00
#=================================================
# RELOAD NGINX
#=================================================
2020-05-27 17:03:30 +02:00
ynh_script_progression --message="Reloading nginx web server..."
2019-10-25 11:04:41 +02:00
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
2018-05-01 12:25:53 +02:00
2020-05-30 19:18:05 +02:00
ynh_script_progression --message="Upgrade of $app completed"