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

106 lines
4 KiB
Bash

#!/bin/bash
#=================================================
# 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
#=================================================
# ADD SWAP
#=================================================
# if ! ynh_in_ci_tests; then
# ynh_script_progression "Adding swap..."
# ynh_add_swap --size=$swap_needed
# fi
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_script_progression "Restoring the app main directory..."
ynh_restore "$install_dir/$appname"
ynh_restore "$install_dir/custom-addons"
ynh_restore "$install_dir/.local"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R o-rwx "$install_dir"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R "$app:$app" "$install_dir"
ynh_restore "$conf_file"
chmod 400 "$conf_file"
chown "$app:$app" "$conf_file"
#=================================================
# RESTORE THE POSTGRESQL DATABASE
#=================================================
ynh_script_progression "Restoring the PostgreSQL database..."
# Make sure that its encoding is UTF-8
ynh_psql_db_shell <<< "update pg_database set encoding = pg_char_to_encoding('UTF8') where datname = '$db_name'"
# Restore the database contents
ynh_psql_db_shell < ./db.sql
#=================================================
# BUILD APP
#=================================================
ynh_script_progression "Building app..."
pushd "$install_dir"
ynh_hide_warnings 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_safe_rm "$install_dir/.cargo"
ynh_safe_rm "$install_dir/.rustup"
popd
#=================================================
# RESTORE VARIOUS FILES
#=================================================
ynh_script_progression "Restoring various files..."
ynh_restore "/var/log/$app.log"
#REMOVEME? Assuming ynh_config_add_logrotate is called, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown "$app:$app" "/var/log/$app.log"
#=================================================
# RESTORE SYSTEM CONFIGURATIONS
#=================================================
ynh_script_progression "Restoring system configurations related to $app..."
ynh_restore "/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_restore "/etc/systemd/system/$app.service"
systemctl enable "$app.service" --quiet
yunohost service add "$app" --log="/var/log/$app.log"
#=================================================
# RELOAD NGINX AND PHP-FPM OR THE APP SERVICE
#=================================================
ynh_script_progression "Reloading NGINX web server and $app's service..."
ynh_systemctl --service="$app" --action="start" --log_path="/var/log/$app.log"
ynh_systemctl --service=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression "Restoration completed for $app"