mirror of
https://github.com/YunoHost-Apps/transmission_ynh.git
synced 2024-09-04 01:46:12 +02:00
127 lines
4.7 KiB
Bash
127 lines
4.7 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
|
|
# 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
|
|
#=================================================
|
|
|
|
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
|
|
#=================================================
|
|
|
|
sudo yunohost app checkurl "${domain}${path_url}" -a "$app" \
|
|
|| 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
|
|
#=================================================
|
|
|
|
ALL_QUIET sudo yunohost firewall allow --no-upnp TCP $port
|
|
ALL_QUIET sudo yunohost firewall allow TCP $peer_port
|
|
|
|
#=================================================
|
|
# SPECIFIC RESTORE
|
|
#=================================================
|
|
# REINSTALL TRANSMISSION
|
|
#=================================================
|
|
|
|
ynh_package_install transmission-daemon
|
|
|
|
#=================================================
|
|
# 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
|
|
|
|
#=================================================
|
|
# 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
|
|
|
|
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
|
|
#=================================================
|
|
|
|
wget -qq https://github.com/YunoHost-Apps/yunohost.multimedia/archive/master.zip
|
|
unzip -qq master.zip
|
|
sudo ./yunohost.multimedia-master/script/ynh_media_build.sh
|
|
# Set rights on transmission directory (parent need to be readable by other, and progress need to be writable by multimedia. Because files will move)
|
|
sudo ./yunohost.multimedia-master/script/ynh_media_addfolder.sh --source="/home/yunohost.transmission" --dest="share/Torrents"
|
|
# And share completed directory
|
|
sudo ./yunohost.multimedia-master/script/ynh_media_addfolder.sh --source="/home/yunohost.transmission/completed" --dest="share/Torrents"
|
|
# Share also watched directory, to allow to use it easily
|
|
sudo ./yunohost.multimedia-master/script/ynh_media_addfolder.sh --source="/home/yunohost.transmission/watched" --dest="share/Torrent to download"
|
|
|
|
#=================================================
|
|
# ENABLE SERVICE IN ADMIN PANEL
|
|
#=================================================
|
|
|
|
sudo yunohost service add transmission-daemon
|
|
|
|
#=================================================
|
|
# START TRANSMISSION
|
|
#=================================================
|
|
|
|
sudo systemctl start transmission-daemon
|
|
|
|
#=================================================
|
|
# RELOAD NGINX
|
|
#=================================================
|
|
|
|
sudo systemctl reload nginx
|