#!/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 #================================================= 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 #================================================= sudo yunohost service add transmission-daemon #================================================= # START TRANSMISSION #================================================= sudo systemctl start transmission-daemon #================================================= # RELOAD NGINX #================================================= sudo systemctl reload nginx