summaryrefslogtreecommitdiff
path: root/cron-jobs
diff options
context:
space:
mode:
authorJoseph Graham <joseph@fibreglass.tunachunks>2014-06-02 12:48:47 +0100
committerJoseph Graham <joseph@fibreglass.tunachunks>2014-06-02 12:48:47 +0100
commitee8da885dc5062001861e4355602a39ae972c32c (patch)
tree2578245ab04fa2c7ac8786056b9e59c493f02608 /cron-jobs
parentc9ad9623c80ddf2db2a734b4a7914ab9eebd84fb (diff)
Made it randomize the order of the webseed list for every torrent.
Diffstat (limited to 'cron-jobs')
-rw-r--r--cron-jobs/make_repo_torrents27
1 files changed, 25 insertions, 2 deletions
diff --git a/cron-jobs/make_repo_torrents b/cron-jobs/make_repo_torrents
index d3c3df6..dffd0dc 100644
--- a/cron-jobs/make_repo_torrents
+++ b/cron-jobs/make_repo_torrents
@@ -38,7 +38,25 @@ public_location='/srv/http/repo/public/'
tracker='http://t67.eu:6969/announce' # t67.eu is run by Xylon
# All mirrors go here
-declare -a url_prefixes=('http://repo.parabolagnulinux.org/' 'https://parabola.goodgnus.com.ar/' 'http://mirror.yandex.ru/mirrors/parabola/' 'http://alfplayer.com/parabola/')
+declare -a array=('http://repo.parabolagnulinux.org/' 'https://parabola.goodgnus.com.ar/' 'http://mirror.yandex.ru/mirrors/parabola/' 'http://alfplayer.com/parabola/')
+
+# I got this function from http://mywiki.wooledge.org/BashFAQ/026 . It
+# shuffles an array. Uses a global array variable. Must be compact
+# (not a sparse array). The array must be called `array'.
+shuffle() {
+ local i tmp size max rand
+
+ # $RANDOM % (i+1) is biased because of the limited range of $RANDOM
+ # Compensate by using a range which is a multiple of the array size.
+ size=${#array[*]}
+ max=$(( 32768 / size * size ))
+
+ for ((i=size-1; i>0; i--)); do
+ while (( (rand=$RANDOM) >= max )); do :; done
+ rand=$(( rand % (i+1) ))
+ tmp=${array[i]} array[i]=${array[rand]} array[rand]=$tmp
+ done
+}
cd "${torrent_location}"
@@ -62,7 +80,12 @@ do
# as a single argument to mktorrent)
webseeds=''
- for prefix in "${url_prefixes[@]}"
+ # Randomize the order of the list of webseeds because I
+ # don't know if transmission might always use the one at
+ # the top otherwize.
+ shuffle
+
+ for prefix in "${array[@]}"
do
webseeds+="${prefix}${pkg#${public_location}},"
done