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)
|
2021-08-02 08:23:59 +02:00
|
|
|
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
|
2020-05-27 18:18:11 +02:00
|
|
|
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)
|
|
|
|
|
2021-08-02 08:23:59 +02:00
|
|
|
#=================================================
|
|
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
|
|
|
|
|
|
|
|
# Backup the current version of the app
|
|
|
|
ynh_backup_before_upgrade
|
|
|
|
ynh_clean_setup () {
|
|
|
|
ynh_clean_check_starting
|
|
|
|
# restore it if the upgrade fails
|
|
|
|
ynh_restore_upgradebackup
|
|
|
|
}
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
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
|
|
|
|
2021-08-02 08:23:59 +02:00
|
|
|
# If datadir doesn't exist, create it
|
|
|
|
if [ -z "$datadir" ]; then
|
|
|
|
datadir=/home/yunohost.app/$app
|
2021-03-22 10:00:33 +01:00
|
|
|
mkdir -p /home/yunohost.app/$app
|
2021-08-02 08:23:59 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=datadir --value=$datadir
|
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
|
|
|
#=================================================
|
|
|
|
# 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
|
|
|
|
2021-03-22 10:00:33 +01: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..."
|
|
|
|
|
2021-08-30 22:37:35 +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
|
2021-08-30 22:37:35 +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
|
|
|
|
2021-08-02 08:23:59 +02:00
|
|
|
chmod 750 "$final_path"
|
|
|
|
chmod -R o-rwx "$final_path"
|
|
|
|
chown -R $app:www-data "$final_path"
|
|
|
|
chown -R $app:www-data $datadir
|
|
|
|
|
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-29 22:51:48 +02:00
|
|
|
pushd $final_path
|
2021-08-30 22:37:35 +02:00
|
|
|
ynh_use_nodejs
|
|
|
|
ynh_exec_warn_less NODE_ENV=production yarn install
|
|
|
|
yarn add webpack webpack-dev-server --dev
|
2020-05-30 19:23:03 +02:00
|
|
|
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
|
|
|
|
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"
|
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
|
2018-05-01 12:25:53 +02:00
|
|
|
#=================================================
|
|
|
|
# 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
|
|
|
|
2021-08-30 22:37:35 +02:00
|
|
|
ynh_systemd_action --service_name=$app --action=start --log_path=systemd
|
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"
|