Skip to content

Instantly share code, notes, and snippets.

@rdark
Last active August 29, 2015 13:57
Show Gist options
  • Save rdark/9394553 to your computer and use it in GitHub Desktop.
Save rdark/9394553 to your computer and use it in GitHub Desktop.
def sign(gpg_passphrase="")
rpm_cmd = "rpm --resign " + self.filename
rpm_cmd += " 2> /dev/null"
PTY.spawn(rpm_cmd) do |r,w,pid|
prompt = r.read(19)
# match the expected prompt exactly, since that's the only way we know if
# something went wrong.
unless prompt == "Enter pass phrase: "
log_msg = "Unexpected output from `#{rpm_cmd}`: '#{prompt}'"
log.fatal(log_msg)
Process.kill(:KILL, pid)
raise log_msg
end
w.write("#{gpg_passphrase}\n")
# Keep printing output unti the command exits
loop do
begin
line = r.gets
if line =~ /failed/
log_msg = "RPM signing failure"
log.fatal(log_msg)
raise log_msg
end
rescue Errno::EIO
break
end
end
end
true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment