Last active
November 18, 2022 10:04
-
-
Save RobertDeRose/9391f5da6273eab26f00d2e7c3c945d3 to your computer and use it in GitHub Desktop.
Transmission unrar script to handle Sonarr from prematurely moving files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# The script could use more tesing, but it works well for my needs | |
function extract_rar() { | |
isRar=$(ls | grep *.rar) | |
if [ -n "$isRar" ]; then | |
# Handle an edge case with some distributors | |
isPart01="$(ls *.rar | egrep -i 'part01.rar|part1.rar')" | |
if [ -n "$isPart01" ]; then | |
isRar=$isPart01 | |
fi | |
toUnrar="$(pwd)/$isRar" | |
# we need to move to new location so sonarr doesn't try to mv before its done | |
# also, unrar doesn't support changing the filename on extracting, makes sense a little bit | |
pushd /mnt/media/Bittorrent/unrar_staging | |
fileName="$(unrar e -y $toUnrar | egrep "^\.\.\..*OK" | awk '{ print $2 }')" | |
# put it back so sonarr can now find it | |
mv $fileName $(dirname $toUnrar) | |
popd | |
fi | |
} | |
echo "Starting - $(date)" | |
cd "$TR_TORRENT_DIR" | |
if [ -d "$TR_TORRENT_NAME" ]; then | |
cd "$TR_TORRENT_NAME" | |
#handle multiple episode packs, like those that contain a whole season, or just a single episode | |
for rar in $(find . -name '*.rar' -exec dirname {} \; | sort -u); | |
do | |
pushd $rar | |
extract_rar | |
popd | |
done | |
fi |
Sorry @peelos, I am just seeing this comment. I have it set to 755 owned by the same user that Transmission runs under.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is exactly what I was looking for, unfortunately cannot get it to run - what permissions should the unrarer.sh file have?