#!/usr/bin/expect -f
set timeout 3
set PACKAGE [lindex $argv 0]
set GPG_NAME [lindex $argv 1]
set GPG_PATH [lindex $argv 2]
set GPG_PASSPHRASE $env(GPG_PASSPHRASE)

if {[llength $argv] == 0} {
  send_user "Usage: ./sign <rpm_package> <gpg_key> <gpg_binary>\n"
  exit 1
}

send_user "\nSigning $PACKAGE\n"
spawn rpmsign --resign $PACKAGE --define "_signature gpg" --define "_gpg_name $GPG_NAME" --define "_gpgbin $GPG_PATH"
expect {
  timeout { send_user "\nTimeout signing $PACKAGE\n"; exit 1 }
  "Enter pass phrase:"
}
send "$GPG_PASSPHRASE\r"
expect {
  timeout { send_user "\nTimeout signing $PACKAGE\n"; exit 1 }
  "Pass phrase is good."
}
interact
sleep 3

