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)
|
|
|
|
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
|
|
|
# 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
|
|
|
|
|
2021-03-14 23:48:12 +01:00
|
|
|
# Cleaning legacy permissions
|
|
|
|
if ynh_legacy_permissions_exists; then
|
|
|
|
ynh_legacy_permissions_delete_all
|
|
|
|
|
|
|
|
ynh_app_setting_delete --app=$app --key=is_public
|
|
|
|
fi
|
|
|
|
|
2018-05-01 12:25:53 +02:00
|
|
|
#=================================================
|
|
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
|
|
#=================================================
|
2020-08-09 14:48:13 +02:00
|
|
|
ynh_script_progression --message="Backing up $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
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# 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
|
|
|
|
2021-03-22 09:06:18 +01: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 --home_dir="$final_path"
|
|
|
|
|
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-08-09 14:48:13 +02:00
|
|
|
ynh_script_progression --message="Upgrading NGINX web server configuration..."
|
2018-05-03 19:57:18 +02:00
|
|
|
|
2020-08-09 14:48:13 +02:00
|
|
|
# Create a dedicated NGINX config
|
2020-05-30 19:18:05 +02:00
|
|
|
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
|
|
|
#=================================================
|
|
|
|
# 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
|
|
|
|
2021-03-14 23:48:12 +01:00
|
|
|
ynh_add_config --template="../conf/config.js" --destination="$config_path"
|
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
|
|
|
|
2021-03-22 09:06:18 +01:00
|
|
|
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-12-14 11:14:10 +01:00
|
|
|
yunohost service add $app --description="Client Web IRC" --log="/var/log/$app/$app.log"
|
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-08-09 14:48:13 +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"
|