-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunrar_all_files.sh
46 lines (46 loc) · 3.02 KB
/
unrar_all_files.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/bash
#Variabel $1 is the folder sent
# used with rtorrent to automatically unrar torrents on completion (for jellyfin / sonarr / radarr automation)
# add to .rtorrent.rc: method.set_key = event.download.finished,unpack_rar,"execute=~/unrar_files.sh,$d.base_path="
# see .rtorrent.rc in this repo for other custom rtorrent configurations
#Start to check if we're in the right folder (rTorrent seems to bug sometimes)
echo "ls -d $1 | grep -F /disk2/rtorrent/download/)";
if [ "$(ls -d $1 | grep -F /disk2/rtorrent/download/)" ] || [ "$(ls -d $1 | grep -F /disk1/rtorrent/download/)" ]; then
#Create only 1 instance of this script to avoid rTorrent crashing
if [ ! "$(ls /home/rtorrent/ | fgrep -i pidfile)" ]; then
yes no | nice -n 15 touch /home/rtorrent/pidfile
#Find and repeat for all folders and subfolders
for directory in $(find $1 -type d); do
#Check for .rar files and unpack them if found
if [ "$(ls $directory | fgrep -i .rar)" ]; then
rarFile=`ls $directory | fgrep -i .rar`;
searchPath="$directory/$rarFile"
yes no | nice -n 15 unrar x -o+ $searchPath $directory
#Check for .001 files and unpack them if found
elif [ "$(ls $directory | fgrep -i .001)" ]; then
rarFile=`ls $directory | fgrep -i .001`;
searchPath="$directory/$rarFile"
yes no | nice -n 15 unrar x -o+ $searchPath $directory
#Check for .zip files and unpack them if found
elif [ "$(ls $directory | fgrep -i .zip)" ]; then
for zipFiles in `ls $directory | fgrep -i .zip`; do
searchPath="$directory/$zipFiles"
yes no | nice -n 15 unzip -n $searchPath -d $directory
done
#When there is .zip files there is often .rar/.001 in them. Check and unpack if so
if [ "$(ls $directory | fgrep -i .rar)" ]; then
rarFile=`ls $directory | fgrep -i .rar`;
searchPath="$directory/$rarFile"
yes no | nice -n 15 unrar x -o+ $searchPath $directory
#Check for .001 files and unpack them if found
elif [ "$(ls $directory | fgrep -i .001)" ]; then
rarFile=`ls $directory | fgrep -i .001`;
searchPath="$directory/$rarFile"
yes no | nice -n 15 unrar x -o+ $searchPath $directory
fi
fi
chmod -R 0777 $directory
done
yes no | nice -n 15 rm -f /home/rtorrent/pidfile
fi
fi