Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Unrar packed contents of torrents downloaded.
- # Just follow the instructions 1-5 and ur fine
- # Dont touch anything else!!! unless u know what u do
- # To automate script execution change this 2 lines in settings.json:
- # Transmission on Qnap path: /share/CACHEDEV1_DATA/.qpkg/QTransmission/etc/settings.json
- # "script-torrent-done-enabled": true,
- # "script-torrent-done-filename": "/share/Download/extract.sh",
- # u dont use Transmission: make a cronjob and point it to the script
- # Torrent Client Download path
- SOURCE="/share/Download/" # 1. change "path" to your liking > "/share/Download/" > is my Transsmission Download path
- # Path Script extracts rars to
- DESTINATION="/share/Download/extracted/" # 2. change "path" to your liking > "/share/Download/extracted/" > its my Sonarr Drone Factory Folder
- # Data dir
- 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
- LIST="$DATADIR/extracted.txt"
- # Log dir
- 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
- LOGFILE="${LOGDIR}/extracted.log"
- # Create required directories if does not exist.
- DIRECTORIES=($DATADIR $LOGDIR)
- for DIR in ${DIRECTORIES[*]}
- do
- if [ ! -d "$DIR" ]; then
- echo "Creating dir: $DIR"
- mkdir -p $DIR
- fi
- done
- # Log content to log file
- function log {
- LINE="`date +'%F %H:%M:%S'` $1"
- echo $LINE
- echo $LINE >> $LOGFILE
- }
- # Backup space symbol
- SAVEIFS=$IFS
- IFS=$(echo -en "\n\b")
- log "Starting job"
- # Find all RARs in working directory.
- for MYRAR in `find "$SOURCE" -name *.rar`
- do
- # Check if it's been decompressed before
- if grep -q $MYRAR $LIST
- then
- # Do nothing.
- echo "Already decompressed" > /dev/null
- # If it hasn't be decompressed before, make a new folder and decompress it
- else
- # Add the name to the list so it will be skipped in the future
- echo $MYRAR >> $LIST
- log "Decompressing $MYRAR"
- FOLDERNAME=`echo "${MYRAR:${#SOURCE}}"`
- FOLDERNAME=`echo $FOLDERNAME | sed 's:[^/]*$::'`
- FINALADDRESS=$DESTINATION$FOLDERNAME
- # Create directory only if it does not exist.
- if [ ! -d "$FINALADDRESS" ]; then
- mkdir $FINALADDRESS
- fi
- /usr/local/sbin/unrar x -o- -inul "$MYRAR" "$FINALADDRESS" # 5. change unrar path > on Qnap it is /usr/local/sbin/unrar
- fi
- done
- # Restore space symbol
- IFS=$SAVEIFS
- log "Job ended"
- exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement