summaryrefslogtreecommitdiffstats
path: root/tools/scripts/sign.exp
blob: 56c4da4b52f928f114f2c0e08b230c9a4d0a91aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/expect -f
#
# Helper script to respond to passphrase prompts from the gpg command.
#

# Disable timeout
set timeout -1

# Optionally print usage message
if {[llength $argv] <= 0} {
  puts "Usage: sign.exp <command>"
  exit 1
}

# Process arguments
set command [join $argv]

if { [info exists env(PASSPHRASE) ] } {
   set passphrase $env(PASSPHRASE)
} else {
   set passphrase ""
}

# Run the desired command
spawn {*}$command
expect {
    -nocase "enter passphrase:" {
        send -- "$passphrase\r"
        exp_continue
    }
    -nocase "enter pass phrase:" {
        send -- "$passphrase\r"
        exp_continue
    }
    timeout {
        puts "expect timeout"
        exit 1
    }
    eof { }
}

lassign [wait] pid spawnid os_error_flag retval

if {$os_error_flag == 0} {
    puts "exit status: $retval"
} else {
    puts "errno: $retval"
}
exit $retval