From 56d92c2f3148f7d6117bd864790d1b40247b7e68 Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Mon, 28 Dec 2020 13:16:47 -0300 Subject: generate-torrent.rb: Assert torrent is in sync with media file --- _plugins/generate-torrent.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to '_plugins') 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 -- cgit v1.2.3