Advertisement
Guest User

Transmission or Cron Unrar script 4 Sonarr

a guest
Feb 24th, 2017
402
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.56 KB | None | 0 0
  1. #!/bin/bash
  2. # Unrar packed contents of torrents downloaded.
  3. # Just follow the instructions 1-5 and ur fine
  4. # Dont touch anything else!!! unless u know what u do
  5.  
  6. # To automate script execution change this 2 lines in settings.json:
  7. # Transmission on Qnap path: /share/CACHEDEV1_DATA/.qpkg/QTransmission/etc/settings.json
  8. #    "script-torrent-done-enabled": true,
  9. #    "script-torrent-done-filename": "/share/Download/extract.sh",
  10.  
  11. # u dont use Transmission: make a cronjob and point it to the script
  12.  
  13. # Torrent Client Download path
  14. SOURCE="/share/Download/"                           # 1. change "path" to your liking > "/share/Download/" > is my Transsmission Download path
  15.  
  16. # Path Script extracts rars to
  17. DESTINATION="/share/Download/extracted/"            # 2. change "path" to your liking > "/share/Download/extracted/" > its my Sonarr Drone Factory Folder
  18.  
  19. # Data dir
  20. DATADIR="`dirname $0`/extracted/0-extracted-0"      # 3. change "dir" to your liking > "0-extracted-0" > just 4 script to work and a list of the rars extracted
  21. LIST="$DATADIR/extracted.txt"
  22.  
  23. # Log dir
  24. LOGDIR="`dirname $0`/extracted/0-extracted-0"       # 4. change "dir" to your liking > "0-extracted-0" > just 4 script to work and a script log
  25. LOGFILE="${LOGDIR}/extracted.log"
  26.  
  27.  
  28. # Create required directories if does not exist.
  29. DIRECTORIES=($DATADIR $LOGDIR)
  30. for DIR in ${DIRECTORIES[*]}
  31. do
  32.     if [ ! -d "$DIR" ]; then
  33.       echo "Creating dir: $DIR"
  34.       mkdir -p $DIR
  35.     fi
  36. done
  37.  
  38.  
  39. # Log content to log file
  40. function log {
  41.   LINE="`date +'%F %H:%M:%S'` $1"
  42.   echo $LINE
  43.   echo $LINE >> $LOGFILE
  44. }
  45.  
  46. # Backup space symbol
  47. SAVEIFS=$IFS
  48. IFS=$(echo -en "\n\b")
  49.  
  50. log "Starting job"
  51. # Find all RARs in working directory.
  52. for MYRAR in `find "$SOURCE" -name *.rar`
  53. do
  54.    # Check if it's been decompressed before
  55.    if grep -q $MYRAR $LIST
  56.    then
  57.       # Do nothing.
  58.       echo "Already decompressed" > /dev/null
  59.  
  60.    # If it hasn't be decompressed before, make a new folder and decompress it
  61.    else
  62.       # Add the name to the list so it will be skipped in the future
  63.       echo $MYRAR >> $LIST
  64.      
  65.       log "Decompressing $MYRAR"
  66.       FOLDERNAME=`echo "${MYRAR:${#SOURCE}}"`
  67.       FOLDERNAME=`echo $FOLDERNAME | sed 's:[^/]*$::'`
  68.       FINALADDRESS=$DESTINATION$FOLDERNAME
  69.  
  70.       # Create directory only if it does not exist.
  71.       if [ ! -d "$FINALADDRESS" ]; then
  72.         mkdir $FINALADDRESS
  73.       fi
  74.       /usr/local/sbin/unrar x -o- -inul "$MYRAR" "$FINALADDRESS"        # 5. change unrar path > on Qnap it is /usr/local/sbin/unrar
  75.    fi
  76. done
  77.  
  78. # Restore space symbol
  79. IFS=$SAVEIFS
  80.  
  81. log "Job ended"
  82. exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement