-
Notifications
You must be signed in to change notification settings - Fork 0
/
torGen.sh
executable file
·149 lines (139 loc) · 4.03 KB
/
torGen.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/bin/bash
#
# torGen.sh by undaunt
#
# Set environmental variables (or full static paths) for the torrent file folder
# labeled 'torrents' directly below this comment.
#
# Below that, set environmental variable values (or replace directly with text) the source
# IDs and announce URLs for each tracker. Directly below that
# set the folders where new content to be uploaded sits for each tracker.
#
# The music pieces size recommendations used below are based on suggested size values from
# a well-regarded music tracker wiki.
#
# The movie pieces size recommendations used below are based on suggested size values from
# a well-regarded movie tracker set of guidelines.
#
# When executing the script you'll need to answer three questions:
# 1 - Which tracker?, 2 - What type of content?, 3 - Where is the content for the torrent?
#
# Released under the MIT License
# Variable list
torrents="${TORRENT_FILE_ROOT}" # .torrent file destination
bin="/usr/local/bin/mktorrent"
tracker1="${TRACKER_ID_1}" # Tracker source
tracker2="${TRACKER_ID_2}"
tracker3="${TRACKER_ID_3}"
tracker4="${TRACKER_ID_4}"
tracker1_announce="${TRACKER_ANNOUNCE_1}" # Tracker personal announce URL
tracker2_announce="${TRACKER_ANNOUNCE_2}"
tracker3_announce="${TRACKER_ANNOUNCE_3}"
tracker4_announce="${TRACKER_ANNOUNCE_4}"
tracker1_data="${TRACKER_DATA_1}" # Tracker specific content parent folder
tracker2_data="${TRACKER_DATA_2}"
tracker3_data="${TRACKER_DATA_3}"
tracker4_data="${TRACKER_DATA_4}"
# Source tag array - add more if required
sources=( "$tracker1" "$tracker2" "$tracker3" "$tracker4" )
# Choose source flag and associated announce URL - set variables or modify, add/remove as needed
echo
echo "Choose your tracker:"
select source in "${sources[@]}"
do
case "$source" in
"$tracker1") announce="$tracker1_announce" data="$tracker1_data"
;;
"$tracker2") announce="$tracker2_announce" data="$tracker2_data"
;;
"$tracker3") announce="$tracker3_announce" data="$tracker3_data"
;;
"$tracker4") announce="$tracker4_announce" data="$tracker4_data"
;;
esac
break
done
echo
# Get content type for pieze sizing
echo "What type of content is this?"
select content in "music" "movie"
do
case "$content" in
music) type="music"
;;
movie) type="movie"
;;
esac
break
done
echo
cd "$data"
# Print current subfolders of data path as menu choices
printf "Select the torrent content folder:\n"
select d in */; do test -n "$d" && break; echo ">>> Invalid Folder Selection"; done
# Set the full torrent content directory and output file location
content="$PWD"/"${d%/}"
file="${torrents%/}"/"${d%/}".torrent
echo
# Capture the size for torrent
size=$(du -shm "$d" | awk '{ print $1 }')
# Set the piece size based on content size and type
if [ "$type" == "music" ]
then
if [ "$size" -le 50 ]
then
piece=15
elif [ "$size" -gt 50 ] && [ "$size" -le 150 ]
then
piece=16
elif [ "$size" -gt 150 ] && [ "$size" -le 350 ]
then
piece=17
elif [ "$size" -gt 350 ] && [ "$size" -le 512 ]
then
piece=18
elif [ "$size" -gt 512 ] && [ "$size" -le 1024 ]
then
piece=19
elif [ "$size" -gt 1024 ] && [ "$size" -le 2048 ]
then
piece=20
elif [ "$size" -gt 2048 ]
then
piece=21
fi
elif [ "$type" == "movie" ]
then
if [ "$size" -le 70 ]
then
piece=16
elif [ "$size" -gt 70 ] && [ "$size" -le 147 ]
then
piece=17
elif [ "$size" -gt 147 ] && [ "$size" -le 256 ]
then
piece=18
elif [ "$size" -gt 256 ] && [ "$size" -le 533 ]
then
piece=19
elif [ "$size" -gt 533 ] && [ "$size" -le 1106 ]
then
piece=20
elif [ "$size" -gt 1106 ] && [ "$size" -le 2294 ]
then
piece=21
elif [ "$size" -gt 2294 ] && [ "$size" -le 4762 ]
then
piece=22
elif [ "$size" -gt 4762 ] && [ "$size" -le 8233 ]
then
piece=23
elif [ "$size" -gt 8233 ]
then
piece=24
fi
fi
# Create the torrent file
$bin -l $piece -p -s $source -a "$announce" "$content" -o "$file"
echo
echo Torrent file created at $file from $content.