-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathimport_key.expect
More file actions
executable file
·46 lines (39 loc) · 1 KB
/
import_key.expect
File metadata and controls
executable file
·46 lines (39 loc) · 1 KB
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
#!/usr/bin/expect -f
set timeout -1
# Read arguments
set moniker [lindex $argv 0]
set priv_key [lindex $argv 1]
set docker_image [lindex $argv 2]
set password [lindex $argv 3]
# Check the values of the variables
if { $moniker == "" || $priv_key == "" || $docker_image == "" } {
puts "Error: One or more required variables are empty."
exit 1
}
spawn docker run -it --entrypoint nesad -v nesachain-data:/app/.nesachain $docker_image keys import-hex $moniker $priv_key
# Handle the first passphrase prompt
expect {
"*passphrase*" {
send -- "$password\r"
}
eof {
puts "Unexpected EOF encountered"
exit 1
}
}
# Handle the re-enter passphrase prompt
expect {
"*Re-enter keyring passphrase*" {
send -- "$password\r"
}
eof {
puts "Unexpected EOF encountered"
exit 1
}
"*cannot overwrite key*" {
puts "Private key exists in keyring already."
exit 0
}
}
expect eof
puts "Key import process completed successfully."