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

129 lines
4.3 KiB
Text
Raw Normal View History

2016-05-14 10:06:20 +02:00
#!/bin/bash
2017-06-13 23:37:51 +02:00
#=================================================
# GENERIC STARTING
#=================================================
# MANAGE FAILURE OF THE SCRIPT
#=================================================
# Exit on command errors and treat unset variables as an error
set -eu
2016-05-14 10:06:20 +02:00
2017-06-13 23:37:51 +02:00
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
if [ ! -e _common.sh ]; then
2017-08-27 22:01:10 +02:00
# 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
2017-06-13 23:37:51 +02:00
fi
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
2016-05-14 10:06:20 +02:00
app=$YNH_APP_INSTANCE_NAME
2017-06-13 23:37:51 +02:00
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)
2016-05-14 10:06:20 +02:00
2017-06-13 23:37:51 +02:00
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
2016-05-14 10:06:20 +02:00
2017-08-27 22:01:10 +02:00
ynh_webpath_available $domain $path_url \
2017-06-13 23:37:51 +02:00
|| ynh_die "Path not available: ${domain}${path_url}"
2016-05-14 10:06:20 +02:00
2017-06-13 23:37:51 +02:00
#=================================================
# STANDARD RESTORE STEPS
#=================================================
# RESTORE OF THE NGINX CONFIGURATION
#=================================================
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
2016-05-14 10:06:20 +02:00
2017-06-13 23:37:51 +02:00
#=================================================
# OPEN PORTS
#=================================================
2016-05-14 10:06:20 +02:00
2017-08-27 22:01:10 +02:00
yunohost firewall allow --no-upnp TCP $port >/dev/null 2>&1
yunohost firewall allow TCP $peer_port >/dev/null 2>&1
2016-05-14 10:06:20 +02:00
2017-06-13 23:37:51 +02:00
#=================================================
# SPECIFIC RESTORE
#=================================================
# REINSTALL TRANSMISSION
#=================================================
2016-05-14 10:06:20 +02:00
2017-06-13 23:37:51 +02:00
ynh_package_install transmission-daemon
2016-05-14 10:06:20 +02:00
2017-06-13 23:37:51 +02:00
#=================================================
# RESTORE TRANSMISSION CONFIGURATION
#=================================================
# Transmission has to be stopped before modifying its config
2017-08-27 22:01:10 +02:00
systemctl stop transmission-daemon
2017-06-13 23:37:51 +02:00
ynh_secure_remove /etc/transmission-daemon/settings.json
ynh_restore_file /etc/transmission-daemon/settings.json
2017-06-13 23:37:51 +02:00
#=================================================
# 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
2017-06-13 23:37:51 +02:00
2017-08-27 22:01:10 +02:00
# 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" ]
2017-06-13 23:37:51 +02:00
then
ynh_restore_file "/home/yunohost.transmission"
else
2017-08-27 22:01:10 +02:00
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
2017-06-13 23:37:51 +02:00
fi
2017-08-27 22:01:10 +02:00
# Remove the backup_core_only option from the settings.yml
ynh_app_setting_delete $app backup_core_only
2017-06-13 23:37:51 +02:00
#=================================================
# YUNOHOST MULTIMEDIA INTEGRATION
#=================================================
2017-06-18 15:57:00 +02:00
ynh_multimedia_build_main_dir
2017-06-13 23:37:51 +02:00
# Set rights on transmission directory (parent need to be readable by other, and progress need to be writable by multimedia. Because files will move)
2017-06-18 15:57:00 +02:00
ynh_multimedia_addfolder "/home/yunohost.transmission" "share/Torrents"
2017-06-13 23:37:51 +02:00
# And share completed directory
2017-06-18 15:57:00 +02:00
ynh_multimedia_addfolder "/home/yunohost.transmission/completed" "share/Torrents"
2017-06-13 23:37:51 +02:00
# Share also watched directory, to allow to use it easily
2017-06-18 15:57:00 +02:00
ynh_multimedia_addfolder "/home/yunohost.transmission/watched" "share/Torrent to download"
2017-06-13 23:37:51 +02:00
#=================================================
# ENABLE SERVICE IN ADMIN PANEL
#=================================================
2016-05-14 10:06:20 +02:00
2017-08-27 22:01:10 +02:00
yunohost service add transmission-daemon --log "/var/log/syslog"
2016-05-14 10:06:20 +02:00
2017-06-13 23:37:51 +02:00
#=================================================
# START TRANSMISSION
#=================================================
2017-08-27 22:01:10 +02:00
systemctl start transmission-daemon
2016-05-14 10:06:20 +02:00
2017-06-13 23:37:51 +02:00
#=================================================
# RELOAD NGINX
#=================================================
2016-05-14 10:06:20 +02:00
2017-08-27 22:01:10 +02:00
systemctl reload nginx