forked from coppit/docker-no-ip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_config.exp
100 lines (77 loc) · 3.21 KB
/
create_config.exp
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/expect
# An expect script to automate the creation of the config file for noip2.
if {$argc != 4} {
send_error "\nERROR: Pass arguments <email> <password> <domains or group> <interval>.\n"
exit 1
}
set email [lindex $argv 0]
set password [lindex $argv 1]
# This can be a single domain name, a comma-delimited list, or a group name
set domains [split [lindex $argv 2] ","]
set interval [lindex $argv 3]
set config_file "/config/no-ip2.generated.conf"
spawn /files/noip2 -C -c $config_file
expect "Please enter the login/email string for no-ip.com"
send "$email\r"
expect "Please enter the password for user"
send "$password\r"
set number_updated 0
expect {
timeout { send_user "\nERROR: Timed out looking for host information\n"; exit 1 }
eof { send_user "\nERROR: Hit EOF looking for host information\n"; exit 1 }
# The case where there are no registered domains
"No hosts are available for this user" {
send_error "\nERROR: No domains registered to the account ($domains).\n"
send_error "Please visit the No-Ip website and create one.\n"
exit 2
}
# If there is only one group or host, verify that it's the one we want to update
-re "Only one (.*) \\\[(.*)\\\] is registered to this account" {
if {[llength $domains] != 1} {
send_error "\nThere is only one registered host or group, but more than one was provided to be updated.\n"
exit 2
} elseif {$expect_out(2,string) != [lindex $domains 0]} {
send_error "\nERROR: $expect_out(1,string) registered to the account ($expect_out(2,string)) does not match expected value ($domains).\n"
send_error "Check your local config file and No-Ip website config.\n"
send_error "If $domains is a host name, then remove the group in the No-Ip website, or change to use the group here.\n"
exit 1
} else {
send_user "\nThere is only one registered $expect_out(1,string), and it is the expected one\n"
incr number_updated
}
}
# If there are multiple hosts and groups, then we need to loop over them
"Do you wish to have them all updated?" {
send "n"
# Start looking for a matching host or group
expect {
timeout { send_user "\nERROR: Timed out processing registered hosts and groups one-by-one\n"; exit 1 }
eof { send_user "\nERROR: Hit EOF processing hosts and groups one-by-one\n"; exit 1 }
-re "Do you wish to have .* \\\[(.*)\\\] updated" {
# Matching group found, so answer "y"
if {[lsearch $domains $expect_out(1,string)] != -1} {
send "y"
incr number_updated
exp_continue
# Not a match, so answer "n"
} else {
send "n"
exp_continue
}
}
# If we don't find a match, exit. Check for errors afterward
"Nothing selected" { }
# If we do find a match, the noip2 will prompt for the update interval
"Please enter an update interval" { }
}
}
}
if {[llength $domains] != $number_updated} {
send_error "\n[llength $domains] hosts or groups were supposed to be updated, but only $number_updated were found\n"
exit 2
}
send "$interval\r"
expect "Do you wish to run something at successful update"
send "n"
send_user "\nFinished creating config file\n"
close