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

216 lines
7.3 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
#=================================================
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
path_url=$(ynh_normalize_url_path $path_url)
#=================================================
# 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-29 22:51:48 +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-27 17:03:30 +02:00
# COPY A CONFIG FILE
2018-05-03 19:57:18 +02:00
#=================================================
2020-05-27 17:03:30 +02:00
# Main config File
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="../conf/config.js"
cp -a ../conf/config.js "$config_path"
#=================================================
# UPGRADE NODEJS AND YARN
#=================================================
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
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-29 22:51:48 +02:00
pushd $final_path
2019-10-25 11:04:41 +02:00
2020-05-27 17:03:30 +02:00
yarn install && ynh_exec_warn_less NODE_ENV=production yarn build
2019-10-25 11:04:41 +02:00
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
# NGINX CONFIGURATION
2018-05-01 22:09:53 +02:00
#=================================================
2020-05-27 17:03:30 +02:00
ynh_script_progression --message="Upgrading nginx web server configuration..."
2018-05-01 22:09:53 +02:00
2019-10-25 11:04:41 +02:00
# Create a dedicated nginx config
ynh_add_nginx_config
2018-05-01 22:09:53 +02:00
#=================================================
2019-10-25 11:04:41 +02:00
# CREATE DEDICATED USER
2018-05-01 22:09:53 +02:00
#=================================================
2020-05-27 17:03:30 +02:00
ynh_script_progression --message="Making sure dedicated system user exists..."
2018-05-01 22:09:53 +02:00
2019-10-25 11:04:41 +02:00
# Create a system user
2020-05-29 22:51:48 +02:00
ynh_system_user_create --username=$app
2018-05-01 22:09:53 +02:00
2019-10-25 11:04:41 +02:00
#=================================================
# SETUP SYSTEMD
#=================================================
2020-05-27 17:03:30 +02:00
ynh_script_progression --message="Configuring a systemd service..."
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
2020-05-29 22:51:48 +02:00
yunohost service add $app --description "Self-hosted web IRC client" --log "/var/log/$app/$app.log"
2020-05-27 18:18:11 +02:00
2019-10-25 11:04:41 +02:00
#=================================================
# STORE THE CONFIG FILE CHECKSUM
#=================================================
### Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script.
### And create a backup of this file if the checksum is different. So the file will be backed up if the admin had modified it.
ynh_backup_if_checksum_is_different --file="$config_path/config.js"
2020-05-27 17:03:30 +02:00
2019-10-25 11:04:41 +02:00
# Recalculate and store the checksum of the file for the next upgrade.
ynh_store_file_checksum --file="$config_path/config.js"
2020-05-27 17:03:30 +02:00
cp -a ../conf/config.js "$config_path"
2018-05-01 12:25:53 +02:00
#=================================================
# SETUP LOGROTATE
#=================================================
2020-05-27 17:03:30 +02:00
ynh_script_progression --message="Upgrading logrotate configuration..."
2018-05-01 12:25:53 +02:00
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# Set right permissions for curl installation
2020-05-29 22:51:48 +02:00
chown -R $app: $final_path
chown -R $app: $config_path
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-27 17:03:30 +02:00
ynh_script_progression --message="Upgrade of $app completed" --last