2015-09-14 17:12:17 +02:00
|
|
|
#!/bin/bash
|
2017-05-18 23:28:18 +02:00
|
|
|
|
2022-02-13 22:09:18 +01:00
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
|
2017-05-18 23:28:18 +02:00
|
|
|
source ../settings/scripts/_common.sh
|
2022-02-13 22:09:18 +01:00
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
2017-05-18 23:28:18 +02:00
|
|
|
|
2022-02-13 22:09:18 +01:00
|
|
|
ynh_clean_setup () {
|
2022-10-20 02:27:52 +02:00
|
|
|
true
|
2022-02-13 22:09:18 +01:00
|
|
|
}
|
|
|
|
# Exit if an error occurs during the execution of the script
|
2018-12-14 03:36:58 +01:00
|
|
|
ynh_abort_if_errors
|
2017-05-18 23:28:18 +02:00
|
|
|
|
2022-02-13 22:09:18 +01:00
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
2022-10-20 02:27:52 +02:00
|
|
|
ynh_script_progression --message="Loading installation settings..." --weight=1
|
2022-02-13 22:09:18 +01: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)
|
|
|
|
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
|
2022-02-17 01:23:35 +01:00
|
|
|
export db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
|
2022-02-13 22:09:18 +01:00
|
|
|
export final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
|
|
|
export conf_file=$(ynh_app_setting_get --app=$app --key=conf_file)
|
2022-02-13 19:55:00 +01:00
|
|
|
export bin_file="$final_path/venv/bin/python $final_path/$appname/$FORKNAME-bin"
|
2018-12-16 19:41:40 +01:00
|
|
|
if [ "$app_version" = "9" ]; then
|
2022-06-17 13:32:01 +02:00
|
|
|
bin_file="$final_path/venv/bin/python $final_path/$appname/$FORKNAME.py"
|
2018-12-16 19:41:40 +01:00
|
|
|
fi
|
|
|
|
if [ "$app_version" = "8" ]; then
|
2022-06-17 13:32:01 +02:00
|
|
|
bin_file="$final_path/venv/bin/python $final_path/$appname/$FORKNAME.py"
|
2018-12-16 19:41:40 +01:00
|
|
|
fi
|
2022-02-16 01:26:09 +01:00
|
|
|
export preinstall=0
|
2017-05-18 23:28:18 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE RESTORED
|
|
|
|
#=================================================
|
2022-10-20 02:27:52 +02:00
|
|
|
ynh_script_progression --message="Validating restoration parameters..." --weight=1
|
2022-02-13 22:09:18 +01:00
|
|
|
|
|
|
|
test ! -d $final_path \
|
|
|
|
|| ynh_die --message="There is already a directory: $final_path "
|
2017-05-18 23:28:18 +02:00
|
|
|
|
|
|
|
#=================================================
|
2022-02-13 22:09:18 +01:00
|
|
|
# STANDARD RESTORATION STEPS
|
|
|
|
#=================================================
|
|
|
|
# RECREATE THE DEDICATED USER
|
|
|
|
#=================================================
|
2022-10-20 02:27:52 +02:00
|
|
|
ynh_script_progression --message="Recreating the dedicated system user..." --weight=1
|
2022-02-13 22:09:18 +01:00
|
|
|
|
|
|
|
# Create the dedicated user (if not existing)
|
|
|
|
ynh_system_user_create --username=$app --home_dir="$final_path"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RESTORE THE APP MAIN DIR
|
|
|
|
#=================================================
|
2022-10-20 02:27:52 +02:00
|
|
|
ynh_script_progression --message="Restoring the app main directory..." --weight=1
|
2022-02-13 22:09:18 +01:00
|
|
|
|
|
|
|
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"
|
|
|
|
|
2022-02-17 01:23:35 +01:00
|
|
|
chmod 750 "$final_path"
|
|
|
|
chmod -R o-rwx "$final_path"
|
2022-02-13 22:09:18 +01:00
|
|
|
chown -R $app:$app "$final_path"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC RESTORATION
|
|
|
|
#=================================================
|
|
|
|
# REINSTALL DEPENDENCIES
|
|
|
|
#=================================================
|
2022-10-20 02:27:52 +02:00
|
|
|
ynh_script_progression --message="Reinstalling dependencies..." --weight=1
|
2022-02-13 22:09:18 +01:00
|
|
|
|
|
|
|
# Define and install dependencies
|
2022-02-17 01:23:35 +01:00
|
|
|
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
|
|
|
|
|
2022-06-15 02:10:40 +02:00
|
|
|
#=================================================
|
|
|
|
# RESTORE THE NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2022-10-20 02:27:52 +02:00
|
|
|
ynh_script_progression --message="Restoring the NGINX web server configuration..." --weight=1
|
2022-06-15 02:10:40 +02:00
|
|
|
|
|
|
|
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
|
|
|
|
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-10-20 02:27:52 +02:00
|
|
|
ynh_script_progression --message="Adding swap..." --weight=1
|
2022-06-17 13:32:01 +02:00
|
|
|
ynh_add_swap --size=$swap_needed
|
2022-05-29 16:07:32 +02:00
|
|
|
fi
|
2017-05-18 23:28:18 +02:00
|
|
|
|
2022-02-13 22:09:18 +01:00
|
|
|
#=================================================
|
|
|
|
# BUILD APP
|
|
|
|
#=================================================
|
2022-10-20 02:27:52 +02:00
|
|
|
ynh_script_progression --message="Building app..." --weight=1
|
2022-02-13 22:09:18 +01:00
|
|
|
|
|
|
|
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-10-20 02:27:52 +02:00
|
|
|
ynh_exec_warn_less ynh_exec_as $app RUSTUP_HOME="$final_path"/.rustup CARGO_HOME="$final_path"/.cargo bash -c 'curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -q -y'
|
|
|
|
export PATH="$PATH:$final_path/.cargo/bin:$final_path/.local/bin:/usr/local/sbin"
|
2022-06-17 13:32:01 +02:00
|
|
|
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
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RESTORE THE POSTGRESQL DATABASE
|
|
|
|
#=================================================
|
2022-10-20 02:27:52 +02:00
|
|
|
ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=1
|
2022-02-13 22:09:18 +01:00
|
|
|
|
|
|
|
# Make sure that postgresql is installed and running
|
2018-12-14 20:21:31 +01:00
|
|
|
ynh_psql_test_if_first_run
|
2017-05-18 23:28:18 +02:00
|
|
|
|
2022-02-17 01:23:35 +01:00
|
|
|
# Create the database
|
|
|
|
ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
|
|
|
|
|
|
|
|
# Make sure that its encoding is UTF-8
|
|
|
|
ynh_psql_execute_as_root --sql="update pg_database set encoding = pg_char_to_encoding('UTF8') where datname = '$db_name'"
|
|
|
|
|
|
|
|
# Restore the database contents
|
2022-02-13 22:09:18 +01:00
|
|
|
ynh_psql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RESTORE VARIOUS FILES
|
|
|
|
#=================================================
|
2022-10-20 02:27:52 +02:00
|
|
|
ynh_script_progression --message="Restoring various files..." --weight=1
|
2022-02-13 22:09:18 +01:00
|
|
|
|
|
|
|
ynh_restore_file --origin_path="$conf_file"
|
2022-02-17 01:23:35 +01:00
|
|
|
chmod 400 "$conf_file"
|
|
|
|
chown $app:$app "$conf_file"
|
2022-02-13 22:09:18 +01:00
|
|
|
|
|
|
|
touch /var/log/$app.log
|
|
|
|
chown $app:$app /var/log/$app.log
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RESTORE SYSTEMD
|
|
|
|
#=================================================
|
2022-10-20 02:27:52 +02:00
|
|
|
ynh_script_progression --message="Restoring the systemd configuration..." --weight=1
|
2022-02-13 22:09:18 +01:00
|
|
|
|
|
|
|
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
|
|
|
|
systemctl enable $app.service --quiet
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
|
|
#=================================================
|
2022-10-20 02:27:52 +02:00
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
|
2022-02-13 22:09:18 +01:00
|
|
|
|
|
|
|
yunohost service add $app --log="/var/log/$app.log"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2022-10-20 02:27:52 +02:00
|
|
|
ynh_script_progression --message="Starting a systemd service..." --weight=1
|
2022-02-13 22:09:18 +01:00
|
|
|
|
|
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app.log"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2022-10-20 02:27:52 +02:00
|
|
|
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
|
2022-02-13 22:09:18 +01:00
|
|
|
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
2017-05-18 23:28:18 +02:00
|
|
|
|
2022-02-13 22:09:18 +01:00
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
2017-05-18 23:28:18 +02:00
|
|
|
|
2022-10-20 02:27:52 +02:00
|
|
|
ynh_script_progression --message="Restoration completed for $app" --last
|