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

144 lines
5.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
#=================================================
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
#=================================================
2022-07-03 20:36:04 +02:00
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
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
#=================================================
2022-07-03 20:36:04 +02:00
ynh_clean_setup () {
ynh_clean_check_starting
}
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
#=================================================
2022-07-03 20:36:04 +02:00
ynh_script_progression --message="Loading installation 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)
2022-07-03 20:36:04 +02:00
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
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-06-13 23:37:51 +02:00
#=================================================
2022-07-03 23:39:54 +02:00
# SPECIFIC RESTORATION
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Reinstalling dependencies..." --weight=16
# Define and install dependencies
ynh_install_app_dependencies $pkg_dependencies
2017-06-13 23:37:51 +02:00
#=================================================
2022-07-03 20:36:04 +02:00
# RESTORE THE DATA DIRECTORY
2017-06-13 23:37:51 +02:00
#=================================================
2022-07-03 20:36:04 +02:00
ynh_script_progression --message="Restoring the data directory..."
2017-06-13 23:37:51 +02:00
2022-07-03 20:36:04 +02:00
ynh_restore_file --origin_path="$datadir" --not_mandatory
2016-05-14 10:06:20 +02:00
2022-07-03 20:36:04 +02:00
mkdir -p $datadir/{progress,completed,watched}
2016-05-14 10:06:20 +02:00
2022-07-03 20:36:04 +02:00
chmod -R 764 $datadir
chmod -R 777 $datadir/watched
chown -R debian-transmission:www-data "$datadir"
chown -R debian-transmission: $datadir/{progress,watched}
2016-05-14 10:06:20 +02:00
2017-06-13 23:37:51 +02:00
#=================================================
2022-07-03 20:36:04 +02:00
# RESTORE THE NGINX CONFIGURATION
2017-06-13 23:37:51 +02:00
#=================================================
2022-07-03 20:36:04 +02:00
ynh_script_progression --message="Restoring the NGINX web server configuration..."
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RESTORE VARIOUS FILES
#=================================================
ynh_script_progression --message="Restoring various files..." --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
2022-07-03 20:36:04 +02:00
ynh_restore_file --origin_path="/etc/sysctl.d/90-transmission.conf"
sysctl --load=/etc/sysctl.d/90-transmission.conf
fi
2019-05-09 11:07:57 +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
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
#=================================================
2022-07-03 20:36:04 +02:00
# OPEN PORTS
2019-05-01 13:24:56 +02:00
#=================================================
2022-07-03 20:36:04 +02:00
ynh_script_progression --message="Configuring firewall..." --weight=13
2017-06-13 23:37:51 +02:00
2022-07-03 20:36:04 +02:00
ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $port
ynh_exec_warn_less yunohost firewall allow Both $peer_port
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)
2022-07-03 20:36:04 +02:00
ynh_multimedia_addfolder --source_dir="$datadir" --dest_dir="share/Torrents"
2017-06-13 23:37:51 +02:00
# And share completed directory
2022-07-03 20:36:04 +02:00
ynh_multimedia_addfolder --source_dir="$datadir/completed" --dest_dir="share/Torrents"
2017-06-13 23:37:51 +02:00
# Share also watched directory, to allow to use it easily
2022-07-03 20:36:04 +02:00
ynh_multimedia_addfolder --source_dir="$datadir/watched" --dest_dir="share/Torrent to download"
2017-06-13 23:37:51 +02:00
#=================================================
2022-07-03 20:36:04 +02:00
# INTEGRATE SERVICE IN YUNOHOST
2019-05-01 13:24:56 +02:00
#=================================================
2022-07-03 20:36:04 +02:00
ynh_script_progression --message="Integrating service in YunoHost..."
2019-05-01 13:24:56 +02:00
2022-07-03 20:36:04 +02:00
yunohost service add transmission-daemon --description="BitTorrent Client" --log="/var/log/syslog" --needs_exposed_ports="$peer_port"
2019-05-01 13:24:56 +02:00
#=================================================
2022-07-03 20:36:04 +02:00
# START SYSTEMD SERVICE
2017-06-13 23:37:51 +02:00
#=================================================
2022-07-03 20:36:04 +02:00
ynh_script_progression --message="Starting a systemd service..."
2016-05-14 10:06:20 +02:00
2022-07-03 20:36:04 +02:00
ynh_systemd_action --service_name=transmission-daemon --action=start
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