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/restore
2022-02-13 22:09:18 +01:00

182 lines
6.4 KiB
Bash

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
true
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..."
export app=$YNH_APP_INSTANCE_NAME
export domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
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 db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
export db_pass=$(ynh_app_setting_get --app=$app --key=psqlpwd)
export final_path=$(ynh_app_setting_get --app=$app --key=final_path)
export conf_file=$(ynh_app_setting_get --app=$app --key=conf_file)
export is_public=0
export bin_file="$final_path/venv/bin/python $final_path/$appname/$FORKNAME-bin"
if [ "$app_version" = "9" ]; then
bin_file="$final_path/venv/bin/python $final_path/$appname/$FORKNAME.py"
fi
if [ "$app_version" = "8" ]; then
bin_file="$final_path/venv/bin/python $final_path/$appname/$FORKNAME.py"
fi
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
ynh_script_progression --message="Validating restoration parameters..."
test ! -d $final_path \
|| ynh_die --message="There is already a directory: $final_path "
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the NGINX web server configuration..."
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
ynh_script_progression --message="Recreating the dedicated system user..."
# Create the dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir="$final_path"
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_script_progression --message="Restoring the app main directory..."
ynh_restore_file --origin_path="$final_path/$appname"
ynh_restore_file --origin_path="$final_path/custom-addons"
ynh_restore_file --origin_path="$final_path/.local"
chown -R $app:$app "$final_path"
#=================================================
# SPECIFIC RESTORATION
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Reinstalling dependencies..."
# Define and install dependencies
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# BUILD APP
#=================================================
ynh_script_progression --message="Building $app..."
ynh_add_swap 1024
if ! wkhtmltopdf --version | grep "wkhtmltopdf 0.12.4 (with patched qt)"; then
# 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
fi
pushd $final_path
if grep "python3" $final_path/$appname/$FORKNAME-bin ; then
python3 -m venv venv
venv/bin/pip3 install wheel
venv/bin/pip3 install -r $appname/requirements.txt
else
virtualenv venv
venv/bin/pip install wheel
venv/bin/pip install -r $appname/requirements.txt
fi
popd
#=================================================
# RESTORE THE POSTGRESQL DATABASE
#=================================================
ynh_script_progression --message="Restoring the PostgreSQL database..."
# Make sure that postgresql is installed and running
ynh_psql_test_if_first_run
ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pass
ynh_psql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql
#=================================================
# RESTORE VARIOUS FILES
#=================================================
ynh_script_progression --message="Restoring various files..."
ynh_restore_file --origin_path="$conf_file"
chown $app:$app $conf_file
touch /var/log/$app.log
chown $app:$app /var/log/$app.log
#=================================================
# RESTORE SYSTEMD
#=================================================
ynh_script_progression --message="Restoring the systemd configuration..."
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
systemctl enable $app.service --quiet
#=================================================
# 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"
#=================================================
# GENERIC FINALIZATION
#=================================================
# 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="Restoration completed for $app"