Advertisement
mathieugfortin

sonarr symlink script

Dec 28th, 2019
989
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.17 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. LOGFILE="/config/logs/symlink.log"
  4. PERMPATH="$sonarr_episodefile_path"
  5. LINKPATH="$sonarr_episodefile_sourcepath"
  6.  
  7. if [ -f "$LINKPATH" ];
  8. then
  9.         echo "Normal Queued Import Invoked, Continuing Script" >> $LOGFILE
  10. else
  11.         echo "Manual Import Invoked, Exiting Script" >> $LOGFILE
  12.         exit 1
  13. fi
  14.  
  15. ORIGFILESIZE=$(stat -c%s "$LINKPATH")
  16. PERMFILESIZE=$(stat -c%s "$PERMPATH")
  17.  
  18. env > /opt/NzbDrone/Logs/env.log
  19.  
  20. echo "Hello. I am going for sleepy time for 30 seconds" >> $LOGFILE
  21. sleep 30
  22.  
  23. echo "Checking if Sonarr is still copying the file" >> $LOGFILE
  24.  
  25. while [ $PERMFILESIZE != $ORIGFILESIZE ]
  26. do
  27.         echo "Sonarr is still copying the file, wait for 1 minute and try again" >> $LOGFILE
  28.         sleep 60
  29.         PERMFILESIZE=$(stat -c%s "$PERMPATH")
  30. done
  31.  
  32. echo "Entering Final File Size Check Phase" >> $LOGFILE
  33.  
  34. if [ $PERMFILESIZE == $ORIGFILESIZE ]
  35. then
  36.         echo "Removing File" >> $LOGFILE
  37.         rm "$LINKPATH"
  38.         echo "Creating symlink" >> $LOGFILE
  39.         ln -s "$PERMPATH" "$LINKPATH"
  40.         chmod 444 "$LINKPATH"
  41. fi
  42.  
  43. echo "Created symlink from source location: $PERMPATH to symlink location $LINKPATH" >> $LOGFILE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement