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

108 lines
3.9 KiB
Text
Raw Normal View History

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
#=================================================
# 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
#=================================================
2024-03-20 20:49:39 +01:00
# ADD SWAP
2022-02-13 22:09:18 +01:00
#=================================================
2024-03-20 20:49:39 +01:00
if [ "${PACKAGE_CHECK_EXEC:-0}" -ne 1 ]; then
ynh_script_progression --message="Adding swap..." --weight=1
ynh_add_swap --size=$swap_needed
2018-12-16 19:41:40 +01:00
fi
2022-02-13 22:09:18 +01:00
#=================================================
# 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
2024-03-20 20:49:39 +01:00
ynh_restore_file --origin_path="$install_dir/$appname"
ynh_restore_file --origin_path="$install_dir/custom-addons"
ynh_restore_file --origin_path="$install_dir/.local"
2022-02-13 22:09:18 +01:00
2024-03-20 20:49:39 +01:00
chmod -R o-rwx "$install_dir"
chown -R "$app:$app" "$install_dir"
2022-02-13 22:09:18 +01:00
2024-03-20 20:49:39 +01:00
ynh_restore_file --origin_path="$conf_file"
chmod 400 "$conf_file"
chown "$app:$app" "$conf_file"
2022-02-17 01:23:35 +01:00
2022-06-15 02:10:40 +02:00
#=================================================
2024-03-20 20:49:39 +01:00
# RESTORE THE POSTGRESQL DATABASE
2022-06-15 02:10:40 +02:00
#=================================================
2024-03-20 20:49:39 +01:00
ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=1
2022-06-15 02:10:40 +02:00
2024-03-20 20:49:39 +01:00
# 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'"
2022-02-17 01:23:35 +01:00
2024-03-20 20:49:39 +01:00
# Restore the database contents
ynh_psql_connect_as --user="$db_user" --password="$db_pwd" --database="$db_name" < ./db.sql
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
2024-03-20 20:49:39 +01:00
pushd "$install_dir"
ynh_exec_warn_less ynh_exec_as "$app" \
RUSTUP_HOME="$install_dir/.rustup" \
CARGO_HOME="$install_dir/.cargo" \
bash -c 'curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -q -y'
export PATH="$PATH:$install_dir/.cargo/bin:$install_dir/.local/bin:/usr/local/sbin"
if grep "python3" "$install_dir/$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="$install_dir/.cargo"
ynh_secure_remove --file="$install_dir/.rustup"
2022-02-13 22:09:18 +01:00
popd
#=================================================
# 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
2024-03-20 20:49:39 +01:00
ynh_restore_file --origin_path="/var/log/$app.log"
chown "$app:$app" "/var/log/$app.log"
2022-02-13 22:09:18 +01:00
#=================================================
2024-03-20 20:49:39 +01:00
# RESTORE SYSTEM CONFIGURATIONS
2022-02-13 22:09:18 +01:00
#=================================================
2024-03-20 20:49:39 +01:00
ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1
2022-02-13 22:09:18 +01:00
2024-03-20 20:49:39 +01:00
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
2022-02-13 22:09:18 +01:00
2024-03-20 20:49:39 +01:00
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
systemctl enable "$app.service" --quiet
yunohost service add "$app" --log="/var/log/$app.log"
2022-02-13 22:09:18 +01:00
#=================================================
2024-03-20 20:49:39 +01:00
# RELOAD NGINX AND PHP-FPM OR THE APP SERVICE
2022-02-13 22:09:18 +01:00
#=================================================
2024-03-20 20:49:39 +01:00
ynh_script_progression --message="Reloading NGINX web server and $app's service..." --weight=1
2022-02-13 22:09:18 +01:00
2024-03-20 20:49:39 +01:00
ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app.log"
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