aboutsummaryrefslogtreecommitdiff
path: root/_plugins
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2020-12-28 13:16:47 -0300
committerEuAndreh <eu@euandre.org>2020-12-28 13:16:47 -0300
commit56d92c2f3148f7d6117bd864790d1b40247b7e68 (patch)
tree7b9296f59d1401190a99493ee214cc565d12d911 /_plugins
parentTODOs.org: Add comment to 9d75fe3a-b7e5-4cc5-9300-1054c7e981c0 (diff)
downloadeuandre.org-56d92c2f3148f7d6117bd864790d1b40247b7e68.tar.gz
euandre.org-56d92c2f3148f7d6117bd864790d1b40247b7e68.tar.xz
generate-torrent.rb: Assert torrent is in sync with media file
Diffstat (limited to '')
-rw-r--r--_plugins/generate-torrent.rb14
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