1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/libreerp_ynh.git synced 2024-09-03 19:36:13 +02:00
libreerp_ynh/scripts/upgrade

186 lines
6.2 KiB
Text
Raw Normal View History

2015-09-14 17:12:17 +02:00
#!/bin/bash
2017-05-18 23:28:18 +02:00
2018-05-21 15:44:09 +02:00
#=================================================
2022-02-13 22:09:18 +01:00
# GENERIC START
2018-05-21 15:44:09 +02:00
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2016-07-05 15:22:12 +02:00
2017-05-18 23:28:18 +02:00
source _common.sh
2022-02-13 22:09:18 +01:00
source /usr/share/yunohost/helpers
2017-05-18 23:28:18 +02:00
2018-05-21 15:44:09 +02:00
#=================================================
# LOAD SETTINGS
#=================================================
2022-02-13 22:09:18 +01:00
ynh_script_progression --message="Loading installation settings..."
2016-07-05 15:22:12 +02:00
2017-05-18 23:28:18 +02:00
export app=$YNH_APP_INSTANCE_NAME
2022-02-13 22:09:18 +01:00
export domain=$(ynh_app_setting_get --app=$app --key=domain)
export app_version=$(ynh_app_setting_get --app=$app --key=app_version)
export oca=$(ynh_app_setting_get --app=$app --key=oca)
export port=$(ynh_app_setting_get --app=$app --key=port)
export port_chat=$(ynh_app_setting_get --app=$app --key=port_chat)
export final_path=$(ynh_app_setting_get --app=$app --key=final_path)
export conf_file=$(ynh_app_setting_get --app=$app --key=conf_file)
2019-04-17 22:45:59 +02:00
export preinstall=0
2017-05-18 23:28:18 +02:00
2018-05-21 15:44:09 +02:00
#=================================================
# CHECK VERSION
#=================================================
2022-02-13 22:09:18 +01:00
ynh_script_progression --message="Checking version..."
2017-05-18 23:28:18 +02:00
2022-02-13 22:09:18 +01:00
upgrade_type=$(ynh_check_app_version_changed)
2015-09-14 17:12:17 +02:00
2018-05-21 15:44:09 +02:00
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
2022-02-13 22:09:18 +01:00
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
2018-05-21 15:44:09 +02:00
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
2022-02-17 01:23:35 +01:00
ynh_clean_check_starting
2022-02-13 22:09:18 +01:00
# Restore it if the upgrade fails
2018-05-21 15:44:09 +02:00
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
2022-02-13 22:09:18 +01:00
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..."
ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app.log"
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..."
# Cleaning legacy permissions
if ynh_legacy_permissions_exists; then
ynh_legacy_permissions_delete_all
ynh_app_setting_delete --app=$app --key=is_public
fi
2022-02-17 01:23:35 +01:00
if ! ynh_permission_exists --permission="admin"; then
# Create the required permissions
ynh_permission_create --permission="admin" --url="/web/database/manager" --allowed="all_users"
fi
2022-02-13 22:09: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"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Upgrading source files..."
# Download, check integrity, uncompress and patch the source from app.src
setup_files
fi
2017-05-18 23:28:18 +02:00
2018-05-21 15:44:09 +02:00
#=================================================
2022-02-13 22:09:18 +01:00
# UPGRADE DEPENDENCIES
2018-05-21 15:44:09 +02:00
#=================================================
2022-02-13 22:09:18 +01:00
ynh_script_progression --message="Upgrading dependencies..."
2022-02-17 01:23:35 +01:00
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
2022-02-13 22:09:18 +01:00
2022-06-15 02:10:40 +02:00
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading NGINX web server configuration..."
# Create a dedicated NGINX config
ynh_add_nginx_config
2022-02-13 22:09:18 +01:00
#=================================================
# SPECIFIC UPGRADE
2022-02-17 01:23:35 +01:00
#=================================================
# ADD SWAP
#=================================================
2022-05-29 16:07:32 +02:00
if [ ${PACKAGE_CHECK_EXEC:-0} -eq 1 ]; then
2022-06-17 13:32:01 +02:00
:
2022-05-29 16:07:32 +02:00
else
2022-06-17 13:32:01 +02:00
ynh_script_progression --message="Adding swap..."
ynh_add_swap --size=$swap_needed
2022-05-29 16:07:32 +02:00
fi
2022-02-17 01:23:35 +01:00
2022-02-13 22:09:18 +01:00
#=================================================
# BUILD APP
#=================================================
ynh_script_progression --message="Building $app..."
if ! wkhtmltopdf --version | grep "wkhtmltopdf 0.12.4 (with patched qt)"; then
2022-06-17 13:32:01 +02:00
# The debian package has a bug so we deploy a more recent version
if [ -f '../manifest.json' ] ; then
ynh_setup_source /usr/
else
OLD_YNH_CWD=$YNH_CWD
YNH_CWD=$YNH_CWD/../settings/conf
ynh_setup_source /usr/
YNH_CWD=$OLD_YNH_CWD
fi
2022-02-13 22:09:18 +01:00
fi
pushd $final_path
2022-06-17 13:32:01 +02:00
RUSTUP_HOME="$final_path/.rustup" CARGO_HOME="$final_path/.cargo" bash -c 'curl -sSf -L https://static.rust-lang.org/rustup.sh | sh -s -- -y --default-toolchain=stable --profile=minimal'
PATH="$PATH:$final_path/.cargo/bin:$final_path/.local/bin:/usr/local/sbin"
if grep "python3" $final_path/$appname/$FORKNAME-bin ; then
python3 -m venv venv
venv/bin/pip3 install --upgrade pip
venv/bin/pip3 install wheel
venv/bin/pip3 install -r $appname/requirements.txt
else
virtualenv venv
venv/bin/pip3 install --upgrade pip
venv/bin/pip install wheel
venv/bin/pip install -r $appname/requirements.txt
fi
ynh_secure_remove --file="$final_path/.cargo"
ynh_secure_remove --file="$final_path/.rustup"
2022-02-13 22:09:18 +01:00
popd
#=================================================
# GENERIC FINALIZATION
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
yunohost service add $app --log="/var/log/$app.log"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..."
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app.log"
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..."
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed"