Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # first save off the positional parameters
- OPTIONS=("$@")
- # then find the last one, presumably the file or dir being dot torrented
- while [[ $# -gt 1 ]]; do
- shift
- done
- target="$1"
- # the max size for a given piece length in KB, or KiB if you prefer
- #
- PLMAXES=([15]=51200 [16]=102400 [17]=204800 [18]=409600 \
- [19]=819200 [20]=1638400 [21]=3276800 [22]=6553600)
- pl="0"
- # if the target exists, get the size of it and use that size to find the right
- # piece length by comparing to the max size for a given piece length. if it is
- # not smaller than any max size, use the piece length one larger than the
- # highest one with a max size.
- #
- # if the target doesn't seem to exist, call mktorrent with the original options
- # and let mktorrent give the error message as if the wrapper wasn't even here.
- #
- if [ -e "$target" ]; then
- tsize=`du -sk "$target" | cut -f1`
- for ((i = 15; i < 23 && pl == 0; i++)); do
- if [[ $tsize -le ${PLMAXES[$i]} ]]; then
- pl=$i
- fi
- done
- if [[ $pl -eq 0 ]]; then
- pl=$i
- fi
- mktorrent --piece-length=${pl} "${OPTIONS[@]}"
- else
- mktorrent "${OPTIONS[@]}"
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement