torrentにWebseedを追加するスクリプト
UbuntuなどのCD/DVDイメージをダウンロードするときに、torrentがサポートされているケースがよくありますが、なぜかWebseedが有効になっていないことが多いです。
こういったときは次の手順で簡単にWebseedを追加することができます。(Rubyが必要です。)
まずは礼儀正しく、bundleを使います。
$ bundle init
$ vi Gemfile
次に使用するgemを指定します。
source "https://rubygems.org"
gem 'bencode'
addwebseed.rbというファイルを以下のように作成します。
require 'bencode'
a = ARGV
t = a.shift
tr = BEncode.load(File.open(t, 'rb', &:read))
tr["url-list"] = ((tr["url-list"] || []) + a).uniq
File.open(t + '.new', 'wb'){|fd|fd.write(BEncode.dump(tr))}
puts tr["url-list"].join("\n")
以上で完成。
使い方は次の例を参考にしてください。Ubuntu 15.10 Serverでの例です。
$ wget http://releases.ubuntu.com/15.10/ubuntu-15.10-server-amd64.iso.torrent
$ bundle exec ruby addwebseed.rb ubuntu-15.10-server-amd64.iso.torrent \
http://releases.ubuntu.com/15.10/ubuntu-15.10-server-amd64.iso