diff options
-rw-r--r-- | _plugins/generate-torrent.rb | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/_plugins/generate-torrent.rb b/_plugins/generate-torrent.rb index a2077bc..16779b9 100644 --- a/_plugins/generate-torrent.rb +++ b/_plugins/generate-torrent.rb @@ -19,11 +19,23 @@ module Jekyll file = "#{date}-#{slug}.#{extension}" media = "resources/#{name}/#{file}" torrent = "#{media}.torrent" - webseed = "#{site.config['url']}/#{media}" + unless File.exist? torrent then + webseed = "#{site.config['url']}/#{media}" puts "Missing '#{torrent}' file, generating..." puts `mktorrent #{TRACKERS} -f -v -d -c '#{document.content}' -n #{file} -w #{webseed} -o #{torrent} #{media}` end + + checksum_file = "resources/#{name}/#{file}.checksum" + checksum = `sha256sum #{media} #{torrent} | sha256sum | awk '{ print $1 }'` + if File.exist? checksum_file + unless checksum == File.read(checksum_file) + raise "Checksum mismatch for '#{media}'.\nRe-generate the torrent files and checksums with:\n\nfind . -type f -name '*.torrent' -or -name '*.checksum' -delete" + end + else + puts "Missing checksum for '#{media}', generating..." + File.write(checksum_file, checksum) + end end end end |