#!/usr/bin/expect --

if {[llength $argv] == 0} {
    puts stderr "Usage: $argv0 <sign-file-parameter>..."
    exit 2
}

set pin $::env(KBUILD_SIGN_PIN)

log_user 0
spawn /usr/lib/linux-kbuild-5.10/scripts/sign-file {*}$argv
expect {
	"Enter PKCS#11 key PIN for SIGN key:" {
		send "$pin\n"
		exp_continue
	}
	timeout {close}
}
lassign [wait] wait_pid spawn_id exec_rc wait_code childkilled
# couldn't exec pesign
if {$exec_rc != 0} {
	exit 1
}
# killed by signal (e.g. timeout)
if {$childkilled == "CHILDKILLED"} {
	exit 1
}
# all good?
exit $wait_code
