Last active
August 29, 2015 13:57
-
-
Save rdark/9394553 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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