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
baximus
Posts: 11
Joined: Wed Jan 04, 2017 1:16 am

Re: RAR Unpack in Version 2.92

Post by baximus »

I checked my log. It is fine.
I did not test script with blank DECOMPRESS_TO_DIR so change it to something like I did.
If it works I will fix script for blank DECOMPRESS_TO_DIR.
baximus
Posts: 11
Joined: Wed Jan 04, 2017 1:16 am

Re: RAR Unpack in Version 2.92

Post by baximus »

Trasmission app sets these variables for script to use.
That are torrent folder and name.
baximus
Posts: 11
Joined: Wed Jan 04, 2017 1:16 am

Re: RAR Unpack in Version 2.92

Post by baximus »

You can not run it manually!!!
You have to download new torrent.
sallysensation
Posts: 16
Joined: Wed Nov 30, 2016 1:41 pm

Re: RAR Unpack in Version 2.92

Post by sallysensation »

ok, that's probably it. I could not understand how it would work if I ran it manually. I'll have to test it through transmission.
sallysensation
Posts: 16
Joined: Wed Nov 30, 2016 1:41 pm

Re: RAR Unpack in Version 2.92

Post by sallysensation »

Still not working at all. I'm still not sure where TR_TORRENT_DIR is set. Is it looking at the "download-dir" variable in the settings.json file?
baximus
Posts: 11
Joined: Wed Jan 04, 2017 1:16 am

Re: RAR Unpack in Version 2.92

Post by baximus »

No, it is dynamic and related to one torrent job.
You are missing something.
Undesirable
Posts: 3
Joined: Sat Jan 21, 2017 7:38 am

Re: RAR Unpack in Version 2.92

Post by Undesirable »

I have the same issue... I've pointed the script to the QPKG directory (on mine it's QPKG_DIR="/share/CACHEDEV1_DATA/.qpkg/Entware-ng/etc/transmission"), verified the correct files are present in "/usr/bin" and "usr/local/sbin" also changed the settings.json file settings to:

"script-torrent-done-enabled": true,
"script-torrent-done-filename": "/share/CACHEDEV1_DATA/.qpkg/Entware-ng/etc/transmission/bin/unrar_unzip_script.sh",


I also set the "DECOMPRESS_TO_DIR=" to something valid and ensured the script permissions are set to 0755.

No log file is created and nothing is extracted.

Here's the script in full as I have uploaded it to my NAS:

Code: Select all

#!/bin/sh

set -x

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

QPKG_DIR="/share/CACHEDEV1_DATA/.qpkg/Entware-ng/etc/transmission"
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/Public/Extracted" #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
Here's my "settings.json" file with peer port and RPC password censored.

Code: Select all

{
    "alt-speed-down": 50,
    "alt-speed-enabled": false,
    "alt-speed-time-begin": 540,
    "alt-speed-time-day": 127,
    "alt-speed-time-enabled": false,
    "alt-speed-time-end": 1020,
    "alt-speed-up": 50,
    "bind-address-ipv4": "0.0.0.0",
    "bind-address-ipv6": "::",
    "blocklist-enabled": true,
    "blocklist-url": "http://list.iblocklist.com/?list=bt_level1",
    "cache-size-mb": 2,
    "dht-enabled": true,
    "download-dir": "/share/Public/Downloads/BitTorrent",
    "download-queue-enabled": true,
    "download-queue-size": 5,
    "encryption": 0,
    "idle-seeding-limit": 30,
    "idle-seeding-limit-enabled": false,
    "incomplete-dir": "/opt/downloads/torrent/incomplete",
    "incomplete-dir-enabled": false,
    "lpd-enabled": true,
    "message-level": 1,
    "peer-congestion-algorithm": "",
    "peer-id-ttl-hours": 6,
    "peer-limit-global": 40,
    "peer-limit-per-torrent": 15,
    "peer-port": *CENSORED*,
    "peer-port-random-high": 65535,
    "peer-port-random-low": 49152,
    "peer-port-random-on-start": false,
    "peer-socket-tos": "lowcost",
    "pex-enabled": true,
    "port-forwarding-enabled": false,
    "preallocation": 1,
    "prefetch-enabled": false,
    "queue-stalled-enabled": true,
    "queue-stalled-minutes": 30,
    "ratio-limit": 2,
    "ratio-limit-enabled": false,
    "rename-partial-files": true,
    "rpc-authentication-required": false,
    "rpc-bind-address": "0.0.0.0",
    "rpc-enabled": true,
    "rpc-password": "*CENSORED*",
    "rpc-port": 9091,
    "rpc-url": "/transmission/",
    "rpc-username": "root",
    "rpc-whitelist": "127.0.0.1",
    "rpc-whitelist-enabled": false,
    "scrape-paused-torrents-enabled": false,
    "script-torrent-added-enabled": false,
    "script-torrent-added-filename": "",
    "script-torrent-done-enabled": true,
    "script-torrent-done-filename": "/share/CACHEDEV1_DATA/.qpkg/Entware-ng/etc/transmission/bin/unrar_unzip_script.sh",
    "seed-queue-enabled": false,
    "seed-queue-size": 10,
    "speed-limit-down": 100,
    "speed-limit-down-enabled": false,
    "speed-limit-up": 100,
    "speed-limit-up-enabled": false,
    "start-added-torrents": true,
    "trash-original-torrent-files": true,
    "umask": 18,
    "upload-slots-per-torrent": 14,
    "utp-enabled": true,
    "watch-dir": "/opt/etc/transmission/watchdir",
    "watch-dir-enabled": true
}
Here's images to show that the files exist in the correct directories:
unrar_unzip_script_search_results.png
unrar_unzip_script_search_results.png (12.16 KiB) Viewed 8052 times
transmission_directory_list.png
transmission_directory_list.png (24.27 KiB) Viewed 8052 times
transmission_bin_directory_list.png
transmission_bin_directory_list.png (20.43 KiB) Viewed 8052 times
transmission_bin_script_permissions.png
transmission_bin_script_permissions.png (7.51 KiB) Viewed 8052 times
Undesirable
Posts: 3
Joined: Sat Jan 21, 2017 7:38 am

Re: RAR Unpack in Version 2.92

Post by Undesirable »

OK, got it to work with Entware-ng on my QNAP NAS.

I pointed the script to the bin folder of Entware-ng, rather than the one in "usr/bin", so it now reads: "BIN_DIR="/share/CACHEDEV1_DATA/.qpkg/Entware-ng/bin".

I also installed the "unrar", "unzip" and "coreutils-basename" packages on Entware instead of using the ones in the "/usr/bin" or "/usr/local/sbin" folders. "Find" was already installed.

In the script, the unrar and unzip packages also have to be pointed to the Entware-ng bin folder, so one example of a command that calls unrar is: "/share/CACHEDEV1_DATA/.qpkg/Entware-ng/bin/unrar $UNRAR_TRIGGERS "$RAR_FILE" "$DESTINATION_DIR/$TR_NAME" >> $LOG_FILE_PATH.

I also created the log file manually in the location specified by the script and gave it read and write permissions (0666) and I moved the location of the script file itself to "/share/CACHEDEV1_DATA/.qpkg/Entware-ng/bin/unrar_unzip_script.sh", ensuring it still had permissions of "rwxr-xr-x" (0755) and pointed to that in my transmission "settings.json" file instead.

The full script now looks like this:

Code: Select all

#!/bin/sh

set -x

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

QPKG_DIR="/share/CACHEDEV1_DATA/.qpkg/Entware-ng/etc/transmission"
BIN_DIR="/share/CACHEDEV1_DATA/.qpkg/Entware-ng/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/Public/Extracted" #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
/share/CACHEDEV1_DATA/.qpkg/Entware-ng/bin/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
/share/CACHEDEV1_DATA/.qpkg/Entware-ng/bin/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"

/share/CACHEDEV1_DATA/.qpkg/Entware-ng/bin/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"
/share/CACHEDEV1_DATA/.qpkg/Entware-ng/bin/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"
/share/CACHEDEV1_DATA/.qpkg/Entware-ng/bin/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"
/share/CACHEDEV1_DATA/.qpkg/Entware-ng/bin/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 »

For anyone still having trouble. I finally got mine working. I installed Unrar 5.1.2 qpkg.

http://www.qnapclub.eu/provider.php/qpk ... 2_x86.qpkg

Hope that helps.
bd2000
Posts: 1
Joined: Fri May 05, 2017 5:34 pm

Re: RAR Unpack in Version 2.92

Post by bd2000 »

Hi, sorry to revive a relatively old thread, just wanted to say the script works really well on my qnap. But i was wondering if there was a way for the original rar file to remain for seeding, at the moment its unpacking and deleting the original.
killemov
Posts: 535
Joined: Sat Jul 31, 2010 5:04 pm

Re: RAR Unpack in Version 2.92

Post by killemov »

bd2000 wrote:Hi, sorry to revive a relatively old thread, just wanted to say the script works really well on my qnap. But i was wondering if there was a way for the original rar file to remain for seeding, at the moment its unpacking and deleting the original.
Sure, just remove the line removing the torrent. If you want different behavior for different torrents check Unrar and cleanup script. It uses a file "keep" to keep the torrent.
kennethfranz
Posts: 1
Joined: Tue Jun 20, 2017 8:51 am

Re: RAR Unpack in Version 2.92

Post by kennethfranz »

I've never worried about such things. You can always find the right software in the format you need and even the right version. The main thing to know where to look. Often, all the software and not only I download on these resources https://yumdownload.com/utorrent. This is for those who like to play a little bit.
Post Reply