zbatery: unlink pid file during graceful shutdown
[zbatery.git] / t / bin / sha1sum.rb
blobb602e79ebfb33d598f7189d175edc1aac7fe70ad
1 #!/usr/bin/env ruby
2 # -*- encoding: binary -*-
4 # Reads from stdin and outputs the SHA1 hex digest of the input this is
5 # ONLY used as a last resort, our test code will try to use sha1sum(1),
6 # openssl(1), or gsha1sum(1) before falling back to using this.  We try
7 # all options first because we have a strong and healthy distrust of our
8 # Ruby abilities in general, and *especially* when it comes to
9 # understanding (and trusting the implementation of) Ruby 1.9 encoding.
11 require 'digest/sha1'
12 $stdout.sync = $stderr.sync = true
13 $stdout.binmode
14 $stdin.binmode
15 bs = 16384
16 digest = Digest::SHA1.new
17 if buf = $stdin.read(bs)
18   begin
19     digest.update(buf)
20   end while $stdin.read(bs, buf)
21 end
23 $stdout.syswrite("#{digest.hexdigest}\n")