From df6884437fb6d5cf96890bfe7506c4053744ba5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Tue, 5 Dec 2023 15:38:33 +0100 Subject: [PATCH] Patch download location after move from /home/yunohost.transmission to /home/yunohost.app --- manifest.toml | 1 + scripts/_common.sh | 27 +++++++++++++++++++++++++++ scripts/upgrade | 7 +++++++ 3 files changed, 35 insertions(+) diff --git a/manifest.toml b/manifest.toml index 06d3eaf..3a115d3 100644 --- a/manifest.toml +++ b/manifest.toml @@ -49,6 +49,7 @@ ram.runtime = "50M" [resources.permissions] main.url = "/" + rpc.url = "/transmission/rpc" rpc.allowed = "visitors" rpc.show_tile = false diff --git a/scripts/_common.sh b/scripts/_common.sh index dfb9f1c..71bc4ff 100755 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -51,6 +51,33 @@ _save_and_revert_rpc_password_hash_to_password() { } +_patch_download_locations() { + # First check if patching is required... + if ! grep -R /home/yunohost.transmission /var/lib/transmission-daemon/info/resume >/dev/null; then + return + fi + + rpc_url="http://127.0.0.1:${port}${path_less}transmission/rpc" + + mapfile -t stopped_torrents < <( + transmission-remote "$rpc_url" -l \ + | awk -F '[[:space:]][[:space:]]+' '{if ($9 == "Stopped") print $2;}' + ) + + for torrent in "${stopped_torrents[@]}"; do + # Remove trailing '*' error marker + torrent="${torrent%\*}" + location=$( + transmission-remote "$rpc_url" -t $torrent -i | grep Location: | awk -F ': ' '{print $2}' + ) + newlocation=$( + echo "$location" | sed -e 's|yunohost.transmission|yunohost.app/transmission|' + ) + transmission-remote "$rpc_url" -t "$torrent" --find "$newlocation" + transmission-remote "$rpc_url" -t "$torrent" --verify + done +} + #================================================= # EXPERIMENTAL HELPERS #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 4e94bb5..f291232 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -120,6 +120,13 @@ ynh_script_progression --message="Starting a systemd service..." --weight=2 ynh_systemd_action --service_name=transmission-daemon --action="start" --log_path="systemd" +#================================================= +# PATCH DOWNLOAD LOCATION IF DOWNLOAD PATH CHANGED +#================================================= +ynh_script_progression --message="Patching download locations..." --weight=1 + +_patch_download_locations + #================================================= # END OF SCRIPT #=================================================