1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/transmission_ynh.git synced 2024-09-04 01:46:12 +02:00
transmission_ynh/scripts/restore
Éric Gaspar c65b76e919
Testing (#85)
* Fix linter warnings (#84)
2021-04-17 19:32:05 +02:00

145 lines
5.6 KiB
Bash

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading settings..."
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
port=$(ynh_app_setting_get --app=$app --key=port)
peer_port=$(ynh_app_setting_get --app=$app --key=peer_port)
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
ynh_script_progression --message="Validating restoration parameters..."
ynh_webpath_available $domain $path_url \
|| ynh_die "Path not available: ${domain}${path_url}"
#=================================================
# STANDARD RESTORE STEPS
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# OPEN PORTS
#=================================================
ynh_script_progression --message="Configuring firewall..." --weight=13
ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $port
ynh_exec_warn_less yunohost firewall allow Both $peer_port
#=================================================
# SPECIFIC RESTORE
#=================================================
# REINSTALL TRANSMISSION
#=================================================
ynh_script_progression --message="Reinstalling Transmission..." --weight=16
# Define and install dependencies
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# RESTORE TRANSMISSION CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring Transmission configuration..." --weight=2
# Transmission has to be stopped before modifying its config
ynh_systemd_action --service_name=transmission-daemon --action=stop
ynh_secure_remove --file=/etc/transmission-daemon/settings.json
ynh_restore_file --origin_path=/etc/transmission-daemon/settings.json
if [ -e /proc/sys/net/core/rmem_max ]
then
ynh_restore_file --origin_path="/etc/sysctl.d/90-transmission.conf"
sysctl --load=/etc/sysctl.d/90-transmission.conf
fi
#=================================================
# RESTORE DATA
#=================================================
ynh_script_progression --message="Restoring transmission data..."
ynh_secure_remove --file=/usr/share/transmission
ynh_restore_file --origin_path=/usr/share/transmission
ynh_secure_remove --file=/var/lib/transmission-daemon
ynh_restore_file --origin_path=/var/lib/transmission-daemon
# Use --not_mandatory for the data directory, because if the backup has been made with BACKUP_CORE_ONLY, there's no data into the backup.
ynh_restore_file --origin_path="/home/yunohost.transmission" --not_mandatory
#=================================================
# RESTORE USER RIGHTS
#=================================================
mkdir -p /home/yunohost.transmission/{progress,completed,watched}
chown -R debian-transmission:www-data /home/yunohost.transmission/
chown -R debian-transmission: /home/yunohost.transmission/{progress,watched}
chmod -R 640 /home/yunohost.transmission
chmod -R 777 /home/yunohost.transmission/watched
#=================================================
# YUNOHOST MULTIMEDIA INTEGRATION
#=================================================
ynh_script_progression --message="Adding multimedia directories..." --weight=4
ynh_multimedia_build_main_dir
# Set rights on transmission directory (parent need to be readable by other, and progress need to be writable by multimedia. Because files will move)
ynh_multimedia_addfolder --source_dir="/home/yunohost.transmission" --dest_dir="share/Torrents"
# And share completed directory
ynh_multimedia_addfolder --source_dir="/home/yunohost.transmission/completed" --dest_dir="share/Torrents"
# Share also watched directory, to allow to use it easily
ynh_multimedia_addfolder --source_dir="/home/yunohost.transmission/watched" --dest_dir="share/Torrent to download"
#=================================================
# START TRANSMISSION
#=================================================
ynh_script_progression --message="Starting transmission..."
ynh_systemd_action --service_name=transmission-daemon --action=start
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
#=================================================
yunohost service add transmission-daemon --description="BitTorrent Client" --log="/var/log/syslog" --needs_exposed_ports="$peer_port"
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX AND PHP-FPM
#=================================================
ynh_script_progression --message="Reloading NGINX web server..." --weight=2
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Restoration completed for $app" --last