1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-11-21 10:12:35 +01:00
2 Reverse symlink script for Connect
a10kiloham edited this page 2020-04-28 08:21:38 +01:00

Slightly updated from the Radarr version this works well if you wish to keep seeding torrents however archive them on a device across the network like a NAS. Copy this to a folder reachable in your Docker config if necessary (i.e., create a config/connect folder) name whatever you like and ensure you chmod 777 so no issues running. For those running with combined Torrent and Usenet downloaders it's helpful to create a 'torrent' tag for this script and also shows that are torrent eligible - this works for more obscure shows where you'd wan to minimize torrent use.

#!/bin/bash
# reverse-symlink.py
# thanks to Radarr wiki poster!

PERMPATH="$sonarr_episodefile_path"
LINKPATH="$sonarr_episodefile_sourcepath"

if [[ -f "$LINKPATH" ]]; then
    sleep 1
else
    exit 0
    # changed from Radarr as Sonarr fails on test unless exit normally
fi

ORIGFILESIZE=$(stat -c%s "$LINKPATH")
PERMFILESIZE=$(stat -c%s "$PERMPATH")

sleep 30

while [[ $PERMFILESIZE != $ORIGFILESIZE ]]; do
    sleep 60
    PERMFILESIZE=$(stat -c%s "$PERMPATH")
done

if [[ $PERMFILESIZE == $ORIGFILESIZE ]]; then
    # Save current time stamps to prevent radarr from identifying our simlink as new, and double-processing it
    LINKDIR=$(dirname "$LINKPATH")
    FOLDER_DATE=$(date -r "$LINKDIR" +@%s.%N)
    FILE_DATE=$(date -r "$LINKPATH" +@%s.%N)

    rm "$LINKPATH"
    ln -s "$PERMPATH" "$LINKPATH"

    touch --no-create --no-dereference  --date "$FILE_DATE" "$LINKPATH"
    touch --no-create --no-dereference  --date "$FILE_DATE" "$PERMPATH"
    touch --no-create --no-dereference  --date "$FOLDER_DATE" "$LINKDIR"
fi