RAR Unpack in Version 2.92

Ask for help and report issues not specific to either the Mac OS X or GTK+ versions of Transmission
sallysensation
Posts: 16
Joined: Wed Nov 30, 2016 1:41 pm

RAR Unpack in Version 2.92

Post by sallysensation »

Can anyone help me set up RAR unpacking in version 2.92? I had it working in the previous version, but with this upgrade the configuration interface and scripts seem to have been removed. I am using it on a QNAP NAS. Thanks!
baximus
Posts: 11
Joined: Wed Jan 04, 2017 1:16 am

Re: RAR Unpack in Version 2.92

Post by baximus »

I just installed 2.92 and had same problem.
So I adjusted the script a bit and it works.
I copied script to /share/CACHEDEV1_DATA/.qpkg/QTransmission/bin/unrar_unzip_script.sh
Change settings.json in /share/CACHEDEV1_DATA/.qpkg/QTransmission/etc as follows:
"script-torrent-done-enabled": true,
"script-torrent-done-filename": "/share/CACHEDEV1_DATA/.qpkg/QTransmission/bin/unrar_unzip_script.sh",

Have a look at script and set DECOMPRESS_TO_DIR.
Check BIN_DIR folder that it holds apps "find" and "basename".
Also folder /usr/local/sbin should hold "unrar" and "unzip" apps.
Adjust if needed.
Hope it helps.

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#!/bin/sh

set -x

TR_DIR="${TR_TORRENT_DIR}"
TR_NAME="${TR_TORRENT_NAME}"

QPKG_DIR="/share/CACHEDEV1_DATA/.qpkg/QTransmission"
BIN_DIR="/usr/bin"
FIND_PATH="${BIN_DIR}/find"
LOG_FILE_PATH="${QPKG_DIR}/unpack.log" #PATH to store the log file, blank to disable
UNRAR_TRIGGERS="x -y -o+ -idp" #triggers for unrar operation, use this to control the info logged (see unrar command manual)
UNZIP_TRIGGERS="-o" #same as unrar but for zip.
DECOMPRESS_TO_DIR="/share/CACHEDEV1_DATA/Download" #If blank will unpack in its own directory, else will unpack to a fixed directory
ACTION_TIME=$(date +%d-%m-%Y\ %H:%M:%S)

if [ -z $DECOMPRESS_TO_DIR ]; then
DESTINATION_DIR="$TR_DIR/$TR_NAME"
else
DESTINATION_DIR="$DECOMPRESS_TO_DIR"
fi

cd "$TR_DIR"
if [ -d "$TR_NAME" ]; then
cd "$TR_NAME"
IFS=$'\n'
unset RAR_FILES i
FIND_RESULTS=`$FIND_PATH -maxdepth 1 -iname "*.rar"`
for RAR_FILE in $FIND_RESULTS; do
if [[ $RAR_FILE =~ .*part.*.rar ]]; then
if [[ $RAR_FILE =~ .*part0*1.rar ]]; then
RAR_FILES[i++]=$RAR_FILE
fi
else
RAR_FILES[i++]=$RAR_FILE
fi
done
unset IFS
unset FIND_RESULTS

if [ ${#RAR_FILES} -gt 0 ]; then
mkdir -p "$DESTINATION_DIR/$TR_NAME"
for RAR_FILE in "${RAR_FILES[@]}"; do
/usr/local/sbin/unrar $UNRAR_TRIGGERS "$RAR_FILE" "$DESTINATION_DIR/$TR_NAME" >> $LOG_FILE_PATH
if [ $? -gt 0 ]; then
echo $ACTION_TIME "Error unrarring $TR_NAME torrent" >> $LOG_FILE_PATH
exit 0
else
echo $ACTION_TIME "Unrarred $TR_NAME torrent" >> $LOG_FILE_PATH
fi
done
fi

IFS=$'\n'
FIND_RESULTS=`$FIND_PATH -maxdepth 1 -iname "*.zip"`
for ZIP_FILE in $FIND_RESULTS; do
ZIP_FILES[i++]=$ZIP_FILE
done
if [ ${#ZIP_FILES} -gt 0 ]; then
mkdir -p "$DESTINATION_DIR/$TR_NAME"
for ZIP_FILE in "${ZIP_FILES[@]}"; do
/usr/local/sbin/unzip $UNZIP_TRIGGERS "$ZIP_FILE" -d "$DESTINATION_DIR/$TR_NAME" >> $LOG_FILE_PATH
if [ $? -gt 0 ]; then
echo $ACTION_TIME "Error unziping $TR_NAME torrent" >> $LOG_FILE_PATH
exit 0
else
echo $ACTION_TIME "Unziped $TR_NAME torrent" >> $LOG_FILE_PATH
fi
done
fi
unset IFS

#in case the torrent is a file
else
#special case when the torrent name contains the archive extension
FILENAME=`${BIN_DIR}/basename "$TR_NAME" .rar`

if [ -f "$FILENAME.rar" ]; then
echo "Special rar archive found ..."

if [ -z "$DECOMPRESS_TO_DIR" ]; then
DESTINATION_DIR="${TR_DIR}/$FILENAME"
else
DESTINATION_DIR="$DECOMPRESS_TO_DIR/$FILENAME"
fi

mkdir -p "$DESTINATION_DIR"

/usr/local/sbin/unrar $UNRAR_TRIGGERS "$FILENAME.rar" "$DESTINATION_DIR" >> $LOG_FILE_PATH
if [ $? -gt 0 ]; then
echo $ACTION_TIME "Error unrarring $TR_NAME torrent" >> $LOG_FILE_PATH
exit 0
else
echo $ACTION_TIME "Unrarred $TR_NAME torrent" >> $LOG_FILE_PATH
fi
else
if [ -f "$TR_NAME.rar" ]; then
mkdir -p "$DESTINATION_DIR"
/usr/local/sbin/unrar $UNRAR_TRIGGERS "$TR_NAME.rar" "$DESTINATION_DIR" >> $LOG_FILE_PATH
if [ $? -gt 0 ]; then
echo $ACTION_TIME "Error unrarring $TR_NAME torrent" >> $LOG_FILE_PATH
exit 0
else
echo $ACTION_TIME "Unrarred $TR_NAME torrent" >> $LOG_FILE_PATH
fi
fi
fi

FILENAME=`${BIN_DIR}/basename "$TR_NAME" .zip`

if [ -f "$FILENAME.zip" ]; then
echo "Special zip archive found ..."
mkdir -p "$DESTINATION_DIR"
/usr/local/sbin/unzip $UNZIP_TRIGGERS "$FILENAME.zip" -d "$DESTINATION_DIR" \ >> $LOG_FILE_PATH
if [ $? -gt 0 ]; then
echo $ACTION_TIME "Error unzipping $TR_NAME torrent" >> $LOG_FILE_PATH
exit 0
else
echo $ACTION_TIME "Unziped $TR_NAME torrent" >> $LOG_FILE_PATH
fi
else
LIST_ZIP_FILE=`ls "$TR_NAME.zip" 2>/dev/null`
if [ ! -z "$LIST_ZIP_FILE" ]; then
mkdir -p "$DESTINATION_DIR"
/usr/local/sbin/unzip $UNZIP_TRIGGERS "$LIST_ZIP_FILE" -d "$DESTINATION_DIR" >> $LOG_FILE_PATH
if [ $? -gt 0 ]; then
echo $ACTION_TIME "Error unzipping $TR_NAME torrent" >> $LOG_FILE_PATH
exit 0
else
echo $ACTION_TIME "Unziped $TR_NAME torrent" >> $LOG_FILE_PATH
fi
fi
fi
fi
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
sallysensation
Posts: 16
Joined: Wed Nov 30, 2016 1:41 pm

Re: RAR Unpack in Version 2.92

Post by sallysensation »

Thanks! I do not see "find" or "basename" in the "bin" folder, or anywhere in the QTransmission directory.

I also can't find /usr/local/sbin or "unrar" and "unzip" apps.

Should these have been created with the installation, or do I need to add them myself?
baximus
Posts: 11
Joined: Wed Jan 04, 2017 1:16 am

Re: RAR Unpack in Version 2.92

Post by baximus »

These files are part of operating system.
They are not located inside QTransmission directory.
This is what I have exactly:
"basename" and "find" are links located inside /usr/bin and they point to "/bin/busybox".
"unrar" and "unzip" are inside /usr/local/sbin as I already mentioned.
Everything can be easily checked via WinSCP.
Do you have x86 based box?
You can PM me so I can help if you wish.
sallysensation
Posts: 16
Joined: Wed Nov 30, 2016 1:41 pm

Re: RAR Unpack in Version 2.92

Post by sallysensation »

Thanks so much for your willingness to help. I have the root set as a share folder for easy access and I cannot find /usr/ anywhere. I have a TS-251+ which is X86, and I have firmware version 4.3.2 installed, so it's 64bit. Maybe that has something to do with it. I have it set up how you described. I copied the script as you had it and modified the following lines to suit my needs:

QPKG_DIR="/share/CACHEDEV2_DATA/.qpkg/QTransmission"
DECOMPRESS_TO_DIR= #If blank will unpack in its own directory, else will unpack to a fixed directory (DO I NEED TO LEAVES THE QUOTES IN THERE?)

But it still isn't doing anything.
baximus
Posts: 11
Joined: Wed Jan 04, 2017 1:16 am

Re: RAR Unpack in Version 2.92

Post by baximus »

Not sure about the quotes but you should definitely connect via WinSCP and check everything.
4.3.2 is 64-bit so that is the same.
sallysensation
Posts: 16
Joined: Wed Nov 30, 2016 1:41 pm

Re: RAR Unpack in Version 2.92

Post by sallysensation »

Do you know of a way to explore those directories from within the NAS remotely? I am at work with security that won't allow me to install winscp, and most ports are blocked. I can access my NAS though.

I was able to access the directories using my phone and all the files you mentioned are in the appropriate directories.
baximus
Posts: 11
Joined: Wed Jan 04, 2017 1:16 am

Re: RAR Unpack in Version 2.92

Post by baximus »

Then it must work with provided script.
One more thing, you have to set file permissions for script to 0775.
Here is the link to script I wrote in post above https://we.tl/cWZjqpARlk
sallysensation
Posts: 16
Joined: Wed Nov 30, 2016 1:41 pm

Re: RAR Unpack in Version 2.92

Post by sallysensation »

This is what happens when i try running it manually:

[/share/CACHEDEV2_DATA/.qpkg/QTransmission/bin] # chmod +x ./unrar_unzip_script.sh
[/share/CACHEDEV2_DATA/.qpkg/QTransmission/bin] # ./unrar_unzip_script.sh
-sh: ./unrar_unzip_script.sh: /bin/sh^M: bad interpreter: No such file or directory
[/share/CACHEDEV2_DATA/.qpkg/QTransmission/bin] #

I may be doing something wrong with my commands. I'm not all that familiar with linux commands.
baximus
Posts: 11
Joined: Wed Jan 04, 2017 1:16 am

Re: RAR Unpack in Version 2.92

Post by baximus »

This should do it "chmod 775 unrar_unzip_script.sh" from within bin folder.
sallysensation
Posts: 16
Joined: Wed Nov 30, 2016 1:41 pm

Re: RAR Unpack in Version 2.92

Post by sallysensation »

I didn't get any errors, but there is no sign of it running. No log file. And no unrar'd files from rars located in my download directory. I checked the script from WinSCP and under permissions it says octal : 0755
baximus
Posts: 11
Joined: Wed Jan 04, 2017 1:16 am

Re: RAR Unpack in Version 2.92

Post by baximus »

It has to be 0775, not 0755. You can change it with WinSCP also (F9).
PM is available as the last resort :)
Actually 0755 should also work.
sallysensation
Posts: 16
Joined: Wed Nov 30, 2016 1:41 pm

Re: RAR Unpack in Version 2.92

Post by sallysensation »

oops. changed it. still not doing anything. How does it know where to look for RAR files? I can't see in the code where that occurs.
baximus
Posts: 11
Joined: Wed Jan 04, 2017 1:16 am

Re: RAR Unpack in Version 2.92

Post by baximus »

It knows through variables like ${TR_TORRENT_DIR}.
My script works fine so you should be able to fix it.
It must be something you overlooked.
Try changing destination dir just for test.
And check settings.json once more.
sallysensation
Posts: 16
Joined: Wed Nov 30, 2016 1:41 pm

Re: RAR Unpack in Version 2.92

Post by sallysensation »

When I run it manually it should not be looking at the settings.json file at all, correct? That's just to get transmission to run it after a torrent is completed.

How are these variables populated?

TR_DIR="${TR_TORRENT_DIR}"
TR_NAME="${TR_TORRENT_NAME}"

what is ${TR_TORRENT_DIR}?

Sorry for so many questions...
Post Reply