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

126 lines
4.4 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
# Rapatrie le fichier de fonctions si il n'est pas dans le dossier courant
sudo cp ../settings/scripts/_common.sh ./_common.sh
sudo chmod a+rx _common.sh
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-06-13 23:37:51 +02:00
sudo yunohost app checkurl "${domain}${path_url}" -a "$app" \
|| 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-06-13 23:37:51 +02:00
ALL_QUIET sudo yunohost firewall allow --no-upnp TCP $port
ALL_QUIET sudo yunohost firewall allow TCP $peer_port
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
sudo systemctl stop transmission-daemon
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
if [ -d "${YNH_APP_BACKUP_DIR}/home/yunohost.transmission" ] # Le dossier data est restauré seulement si il existe. Si le backup a été fait avec l'option backup_core_only, ce dossier n'a pas été sauvegardé.
then
ynh_restore_file "/home/yunohost.transmission"
else
sudo mkdir -p /home/yunohost.transmission/{progress,completed,watched}
sudo chown -R debian-transmission:www-data /home/yunohost.transmission/
sudo chown -R debian-transmission: /home/yunohost.transmission/{progress,watched}
sudo chmod -R 640 /home/yunohost.transmission
sudo chmod -R 777 /home/yunohost.transmission/watched
fi
ynh_app_setting_delete $app backup_core_only # Retire l'option backup_core_only du fichier settings.yml le cas échéant
#=================================================
# 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
sudo 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
#=================================================
sudo 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-06-13 23:37:51 +02:00
sudo systemctl reload nginx