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

128 lines
4.4 KiB
Bash

#!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# MANAGE FAILURE OF THE SCRIPT
#=================================================
# Exit on command errors and treat unset variables as an error
set -eu
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
if [ ! -e _common.sh ]; then
# Get the _common.sh file if it's not in the current directory
cp ../settings/scripts/_common.sh ./_common.sh
chmod a+rx _common.sh
fi
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain)
path_url=$(ynh_app_setting_get $app path)
port=$(ynh_app_setting_get $app port)
peer_port=$(ynh_app_setting_get $app peer_port)
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
ynh_webpath_available $domain $path_url \
|| ynh_die "Path not available: ${domain}${path_url}"
#=================================================
# STANDARD RESTORE STEPS
#=================================================
# RESTORE OF THE NGINX CONFIGURATION
#=================================================
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# OPEN PORTS
#=================================================
yunohost firewall allow --no-upnp TCP $port >/dev/null 2>&1
yunohost firewall allow Both $peer_port >/dev/null 2>&1
#=================================================
# SPECIFIC RESTORE
#=================================================
# REINSTALL TRANSMISSION
#=================================================
ynh_install_app_dependencies transmission-daemon transmission-cli transmission-common acl
#=================================================
# RESTORE TRANSMISSION CONFIGURATION
#=================================================
# Transmission has to be stopped before modifying its config
systemctl stop transmission-daemon
ynh_secure_remove /etc/transmission-daemon/settings.json
ynh_restore_file /etc/transmission-daemon/settings.json
#=================================================
# RESTORE DATA
#=================================================
ynh_secure_remove /usr/share/transmission
ynh_restore_file /usr/share/transmission
ynh_secure_remove /var/lib/transmission-daemon
ynh_restore_file /var/lib/transmission-daemon
# The data directory is restored only if it's in the backup.
# If the backup have made with backup_core_only option, this directory didn't saved.
if [ -d "${YNH_APP_BACKUP_DIR}/home/yunohost.transmission" ]
then
ynh_restore_file "/home/yunohost.transmission"
else
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
fi
# Remove the backup_core_only option from the settings.yml
ynh_app_setting_delete $app backup_core_only
#=================================================
# YUNOHOST MULTIMEDIA INTEGRATION
#=================================================
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 "/home/yunohost.transmission" "share/Torrents"
# And share completed directory
ynh_multimedia_addfolder "/home/yunohost.transmission/completed" "share/Torrents"
# Share also watched directory, to allow to use it easily
ynh_multimedia_addfolder "/home/yunohost.transmission/watched" "share/Torrent to download"
#=================================================
# ENABLE SERVICE IN ADMIN PANEL
#=================================================
yunohost service add transmission-daemon --log "/var/log/syslog"
#=================================================
# START TRANSMISSION
#=================================================
systemctl start transmission-daemon
#=================================================
# RELOAD NGINX
#=================================================
systemctl reload nginx