Created
March 26, 2018 22:35
-
-
Save Ardakilic/f9670cfa90522509c80ed3f390d5b661 to your computer and use it in GitHub Desktop.
Sonarr symlink script
This file contains 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 | |
# Sonarr symlink post-process script | |
# Based on https://github.com/Sonarr/Sonarr/issues/967#issuecomment-228599878 | |
# With some tint modifications | |
# make syre Logs folder and file exists | |
LOGFILE="/opt/NzbDrone/Logs/sonarrsymlink.log" | |
PERMPATH="$sonarr_episodefile_path" | |
SOURCEPATH="$sonarr_episodefile_sourcepath" | |
if [ -f "$SOURCEPATH" ]; | |
then | |
echo "Normal Queued Import Invoked, Continuing Script" >> $LOGFILE | |
else | |
echo "Manual Import Invoked, Exiting Script" >> $LOGFILE | |
exit 1 | |
fi | |
# Usenet-specific download folder to ignore symlink process because usenet files are moved | |
USENET_PATH="nzbget" #a bunch of string, which usenet download folder contains but bittorrent folder doesn't | |
if [[ $SOURCEPATH = *$USENET_PATH* ]]; | |
then | |
echo "Import ignored, because download source is Usenet and file will be moved" >> $LOGFILE | |
exit 1; | |
fi | |
# Usenet-specific download folder to ignore symlink process because usenet files are moved | |
ORIGFILESIZE=$(stat -c%s "$SOURCEPATH") | |
PERMFILESIZE=$(stat -c%s "$PERMPATH") | |
#env > /opt/NzbDrone/Logs/env.log | |
echo "Hello. I am going for sleepy time for 15 seconds" >> $LOGFILE | |
sleep 15 | |
echo "Checking if Sonarr is still copying the file" >> $LOGFILE | |
while [ $PERMFILESIZE != $ORIGFILESIZE ] | |
do | |
echo "Sonarr is still copying the file, wait for 30 seconds and try again" >> $LOGFILE | |
sleep 30 | |
PERMFILESIZE=$(stat -c%s "$PERMPATH") | |
done | |
echo "Entering Final File Size Check Phase" >> $LOGFILE | |
if [ $PERMFILESIZE == $ORIGFILESIZE ] | |
then | |
echo "Removing Hardlinked File" >> $LOGFILE | |
rm "$PERMPATH" | |
echo "Creating symlink" >> $LOGFILE | |
ln -s "$SOURCEPATH" "$PERMPATH" | |
fi | |
echo "Created symlink from source location: $SOURCEPATH to symlink location $PERMPATH" >> $LOGFILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment