-
Notifications
You must be signed in to change notification settings - Fork 115
Expand file tree
/
Copy pathstatic_ip.sh
More file actions
executable file
·80 lines (68 loc) · 1.76 KB
/
Copy pathstatic_ip.sh
File metadata and controls
executable file
·80 lines (68 loc) · 1.76 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
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
#!/bin/bash
# This is a debconf-compatible script
# shellcheck disable=SC1091
. /usr/share/debconf/confmodule
valid_ip () {
# shellcheck disable=SC3043
local ip=$1
if [[ -z $ip ]]; then
return 0
fi
if expr "$ip" : '[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$' >/dev/null; then
for i in 1 2 3 4; do
if [ "$(echo "$ip" | cut -d. -f$i)" -gt 255 ]; then
return 1
fi
done
return 0
else
return 1
fi
}
# Create the template file
cat > /tmp/ip.template <<'!EOF!'
Template: ip-question/ask
Type: string
Description: If your public IP is dynamic, or you don't know, leave this field blank and continue.
DAppNode needs to know the public IP of your node.
Template: ip-question/title
Type: text
Description: Your public IP.
Template: ip-question/finished
Type: text
Description: Finished.
!EOF!
cat > /tmp/ip_fail.template <<'!EOF!'
Template: ip-fail/ask
Type: note
Description: This is not a valid IP.
Template: ip-fail/title
Type: text
Description: Wrong IP
!EOF!
db_dialog () {
debconf-loadtemplate ip-question /tmp/ip.template
db_settitle ip-question/title
db_input critical ip-question/ask
db_go
db_get ip-question/ask
if valid_ip "$RET"; then
mkdir -p /target/usr/src/dappnode/config
echo "$RET" > /target/usr/src/dappnode/config/static_ip
else
debconf-loadtemplate ip-fail /tmp/ip_fail.template
db_settitle ip-fail/title
db_input critical ip-fail/ask
db_go
db_get ip-fail/ask
# Ask again until done
db_dialog
fi
db_settitle ip-question/title
}
db_restore () {
debconf-loadtemplate ip-question /tmp/ip.template
db_settitle ip-question/restore
}
db_dialog
db_restore