2016-05-14 10:06:20 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-06-13 23:37:51 +02:00
|
|
|
#=================================================
|
2019-05-01 13:24:56 +02:00
|
|
|
# GENERIC START
|
2017-06-13 23:37:51 +02:00
|
|
|
#=================================================
|
2019-05-01 13:24:56 +02:00
|
|
|
# IMPORT GENERIC HELPERS
|
2017-06-13 23:37:51 +02:00
|
|
|
#=================================================
|
|
|
|
|
2019-05-01 13:24:56 +02:00
|
|
|
source ../settings/scripts/_common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
2016-05-14 10:06:20 +02:00
|
|
|
|
2017-06-13 23:37:51 +02:00
|
|
|
#=================================================
|
2019-05-01 13:24:56 +02:00
|
|
|
# MANAGE SCRIPT FAILURE
|
2017-06-13 23:37:51 +02:00
|
|
|
#=================================================
|
|
|
|
|
2019-05-01 13:24:56 +02:00
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
2017-06-13 23:37:51 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
2019-05-01 13:24:56 +02:00
|
|
|
ynh_script_progression --message="Loading settings..."
|
2016-05-14 10:06:20 +02:00
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
2019-05-01 13:24:56 +02:00
|
|
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
|
|
|
path_url=$(ynh_app_setting_get --app=$app --key=path)
|
|
|
|
port=$(ynh_app_setting_get --app=$app --key=port)
|
|
|
|
peer_port=$(ynh_app_setting_get --app=$app --key=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
|
|
|
|
#=================================================
|
2019-05-01 13:24:56 +02:00
|
|
|
ynh_script_progression --message="Validating restoration parameters..."
|
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
|
|
|
|
#=================================================
|
2019-05-01 13:24:56 +02:00
|
|
|
# RESTORE THE NGINX CONFIGURATION
|
2017-06-13 23:37:51 +02:00
|
|
|
#=================================================
|
|
|
|
|
2019-05-01 13:24:56 +02:00
|
|
|
ynh_restore_file --origin_path="/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
|
|
|
|
#=================================================
|
2019-05-01 13:24:56 +02:00
|
|
|
ynh_script_progression --message="Configuring firewall..." --weight=13
|
2016-05-14 10:06:20 +02:00
|
|
|
|
2019-05-01 13:24:56 +02:00
|
|
|
ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $port
|
|
|
|
ynh_exec_warn_less yunohost firewall allow Both $peer_port
|
2016-05-14 10:06:20 +02:00
|
|
|
|
2017-06-13 23:37:51 +02:00
|
|
|
#=================================================
|
|
|
|
# SPECIFIC RESTORE
|
|
|
|
#=================================================
|
|
|
|
# REINSTALL TRANSMISSION
|
|
|
|
#=================================================
|
2020-12-14 11:36:02 +01:00
|
|
|
ynh_script_progression --message="Reinstalling Transmission..." --weight=16
|
2016-05-14 10:06:20 +02:00
|
|
|
|
2019-05-01 13:24:56 +02:00
|
|
|
# Define and install dependencies
|
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
2016-05-14 10:06:20 +02:00
|
|
|
|
2017-06-13 23:37:51 +02:00
|
|
|
#=================================================
|
|
|
|
# RESTORE TRANSMISSION CONFIGURATION
|
|
|
|
#=================================================
|
2020-12-14 11:36:02 +01:00
|
|
|
ynh_script_progression --message="Restoring Transmission configuration..." --weight=2
|
2017-06-13 23:37:51 +02:00
|
|
|
|
|
|
|
# Transmission has to be stopped before modifying its config
|
2019-05-01 13:24:56 +02:00
|
|
|
ynh_systemd_action --service_name=transmission-daemon --action=stop
|
2017-06-13 23:37:51 +02:00
|
|
|
|
2019-05-01 13:24:56 +02:00
|
|
|
ynh_secure_remove --file=/etc/transmission-daemon/settings.json
|
|
|
|
ynh_restore_file --origin_path=/etc/transmission-daemon/settings.json
|
2017-06-13 23:37:51 +02:00
|
|
|
|
2020-03-03 19:06:26 +01:00
|
|
|
if [ -e /proc/sys/net/core/rmem_max ]
|
|
|
|
then
|
|
|
|
ynh_restore_file --origin_path="/etc/sysctl.d/90-transmission.conf"
|
2019-05-09 12:25:08 +02:00
|
|
|
sysctl --load=/etc/sysctl.d/90-transmission.conf
|
2019-05-09 11:44:17 +02:00
|
|
|
fi
|
2019-05-09 11:07:57 +02:00
|
|
|
|
2017-06-13 23:37:51 +02:00
|
|
|
#=================================================
|
|
|
|
# RESTORE DATA
|
|
|
|
#=================================================
|
2019-05-01 13:24:56 +02:00
|
|
|
ynh_script_progression --message="Restoring transmission data..."
|
2017-06-13 23:37:51 +02:00
|
|
|
|
2019-05-01 13:24:56 +02:00
|
|
|
ynh_secure_remove --file=/usr/share/transmission
|
|
|
|
ynh_restore_file --origin_path=/usr/share/transmission
|
2017-06-16 20:38:31 +02:00
|
|
|
|
2019-05-01 13:24:56 +02:00
|
|
|
ynh_secure_remove --file=/var/lib/transmission-daemon
|
|
|
|
ynh_restore_file --origin_path=/var/lib/transmission-daemon
|
|
|
|
|
|
|
|
# Use --not_mandatory for the data directory, because if the backup has been made with BACKUP_CORE_ONLY, there's no data into the backup.
|
|
|
|
ynh_restore_file --origin_path="/home/yunohost.transmission" --not_mandatory
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RESTORE USER RIGHTS
|
|
|
|
#=================================================
|
2017-06-13 23:37:51 +02:00
|
|
|
|
2019-05-01 13:24:56 +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
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# YUNOHOST MULTIMEDIA INTEGRATION
|
|
|
|
#=================================================
|
2019-05-01 13:24:56 +02:00
|
|
|
ynh_script_progression --message="Adding multimedia directories..." --weight=4
|
2017-06-13 23:37:51 +02:00
|
|
|
|
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)
|
2019-05-01 13:24:56 +02:00
|
|
|
ynh_multimedia_addfolder --source_dir="/home/yunohost.transmission" --dest_dir="share/Torrents"
|
2017-06-13 23:37:51 +02:00
|
|
|
# And share completed directory
|
2019-05-01 13:24:56 +02:00
|
|
|
ynh_multimedia_addfolder --source_dir="/home/yunohost.transmission/completed" --dest_dir="share/Torrents"
|
2017-06-13 23:37:51 +02:00
|
|
|
# Share also watched directory, to allow to use it easily
|
2019-05-01 13:24:56 +02:00
|
|
|
ynh_multimedia_addfolder --source_dir="/home/yunohost.transmission/watched" --dest_dir="share/Torrent to download"
|
2017-06-13 23:37:51 +02:00
|
|
|
|
|
|
|
#=================================================
|
2019-05-01 13:24:56 +02:00
|
|
|
# START TRANSMISSION
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Starting transmission..."
|
|
|
|
|
|
|
|
ynh_systemd_action --service_name=transmission-daemon --action=start
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# ADVERTISE SERVICE IN ADMIN PANEL
|
2017-06-13 23:37:51 +02:00
|
|
|
#=================================================
|
2016-05-14 10:06:20 +02:00
|
|
|
|
2021-04-17 19:32:05 +02:00
|
|
|
yunohost service add transmission-daemon --description="BitTorrent Client" --log="/var/log/syslog" --needs_exposed_ports="$peer_port"
|
2016-05-14 10:06:20 +02:00
|
|
|
|
2017-06-13 23:37:51 +02:00
|
|
|
#=================================================
|
2019-05-01 13:24:56 +02:00
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX AND PHP-FPM
|
2017-06-13 23:37:51 +02:00
|
|
|
#=================================================
|
2020-12-14 11:36:02 +01:00
|
|
|
ynh_script_progression --message="Reloading NGINX web server..." --weight=2
|
2017-06-13 23:37:51 +02:00
|
|
|
|
2019-05-01 13:24:56 +02:00
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
2016-05-14 10:06:20 +02:00
|
|
|
|
2017-06-13 23:37:51 +02:00
|
|
|
#=================================================
|
2019-05-01 13:24:56 +02:00
|
|
|
# END OF SCRIPT
|
2017-06-13 23:37:51 +02:00
|
|
|
#=================================================
|
2016-05-14 10:06:20 +02:00
|
|
|
|
2019-05-01 13:24:56 +02:00
|
|
|
ynh_script_progression --message="Restoration completed for $app" --last
|