-
Notifications
You must be signed in to change notification settings - Fork 2
/
maketorrent
executable file
·40 lines (35 loc) · 894 Bytes
/
maketorrent
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
#!/bin/sh
# DEPS: bc, mktorrent
# Make a torrent with optimal chunk size
# .torren file saves in SAVEDIR
SAVEDIR="/tmp"
size=$(du "$1" | cut -f1)
echo $size
if [ $size -gt 17000000 ]; then
leng=25
elif [ $size -gt 9000000 ]; then
leng=24
elif [ $size -gt 4300000 ]; then
leng=23
elif [ $size -gt 2200000 ]; then
leng=22
elif [ $size -gt 1100000 ]; then
leng=21
elif [ $size -gt 530000 ]; then
leng=20
elif [ $size -gt 270000 ]; then
leng=19
elif [ $size -gt 130000 ]; then
leng=18
elif [ $size -gt 70000 ]; then
leng=17
elif [ $size -gt 40000 ]; then
leng=16
else
leng=15
fi
echo "Content size: $size"
humanread=$(echo "2^$leng" | bc -ql)
humanreadkb=$(echo "$humanread/1024" | bc -ql | cut -d. -f1)
echo "Chunk size: 2^$leng = $humanread bytes ($humanreadkb KiB)"
mktorrent -l $leng -o "$SAVEDIR/$1" "$1" && echo "Torrent created: $SAVEDIR/$1"