-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvectix_netcfg
executable file
·122 lines (116 loc) · 3.47 KB
/
convectix_netcfg
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/local/bin/cbsd
#v10.0.2
# cbsd wb_netcfg mode=update nic=re0 ip4="10.0.0.2" mask4="255.255.255.0"
CBSDMODULE="convectix"
MYARG="mode"
MYOPTARG="nic out firststart ip4 mask4 ip6 mask6 gw4 gw6"
MYDESC="convectix network helper"
ADDHELP="possible mode:\n\
dhclient - execute dhclient on specified interface, apply and save in ${tmpdir}/networks.txt\n\
trydhcp - try dhclient and save in ${tmpdir}/networks.txt, without applying\n\
nictest - test dhcp and save params in ${tmpdir}\n\
out= alternative save path instead of ${tmpdir}/networks.nic.txt\n\
ip4/ip6= is ip or 'DHCP' for DHCP\n"
. ${subr}
. ${cbsdinit}
#defines
_MYDIR=$(dirname `realpath $0`)
### MAIN Route ###
set -e
. ${_MYDIR}/convectix_netcfg.subr
set +e
[ -z "${1}" ] && usage
[ -z "${firststart}" ] && firststart=1
case "${mode}" in
"dhclient")
[ -z "${nic}" ] && err 1 "nic= is mandatory"
DHCP_TRY_MODE=0
if [ "${nic}" = "all" ]; then
for nic in $( ${miscdir}/nics-list -s lo ); do
${IFCONFIG_CMD} ${nic} up
remove_dhcp_lease ${nic}
MYNIC="${nic}"
dhcp_client "${MYNIC}"
collect_net_data
save_settings
done
exit 0
else
MYNIC="${nic}"
dhcp_client "${MYNIC}"
collect_net_data
save_settings
fi
exit 0
;;
"trydhcp")
[ -z "${nic}" ] && err 1 "nic= is mandatory"
MYNIC="${nic}"
DHCP_TRY_MODE=1
dhcp_client "${MYNIC}"
exit 0
;;
"nictest")
nic_test
exit 0
;;
"update")
[ -z "${nic}" ] && err 1 "nic= is mandatory"
if [ "${ip4}" = "DHCP" ]; then
set_ip4 "DHCP"
exit 0
elif [ "${ip6}" = "DHCP" ]; then
set_ip6 "DHCP"
exit 0
fi
[ -z "${ip4}" -a -z "${ip6}" ] && err 1 "ip4/mask4 or ip6/mask6 pair is mandatory"
[ -z "${mask4}" -a -z "${mask6}" ] && err 1 "ip4/mask4 or ip6/mask6 pair is mandatory"
validate_nic
# kill_dhclient ${nic}
if [ -n "${ip4}" -a -n "${mask4}" ]; then
validate_ip4
set_ip4
elif [ -n "${ip6}" -a -n "${mask6}" ]; then
validate_ip6
set_ip6
else
err 1 "ip4/mask4 or ip6/mask6 pair is mandatory"
fi
[ -n "${gw4}" ] && set_gw4
[ -n "${gw6}" ] && set_gw6
;;
"save")
[ -z "${nic}" ] && err 1 "nic= is mandatory"
truncate -s0 ${STORE_FILE}
if [ "${ip4}" = "DHCP" ]; then
sysrc -qf ${STORE_FILE} "ifconfig_${nic}=\"DHCP\"" >/dev/null 2>&1
ip4=$(ifconfig ${nic} 2>/dev/null| ${AWK_CMD} '/inet [0-9]+/ { print $2}' | /usr/bin/head -n 1)
[ -z "${ip4}" -o "${ip4}" = "0.0.0.0" ] && ip4="127.0.0.1"
echo ${ip4} > ${CBSD_IP}
exit 0
elif [ "${ip6}" = "DHCP" ]; then
sysrc -qf ${STORE_FILE} "ifconfig_${nic}=\"DHCP\"" >/dev/null 2>&1
sysrc -qf ${STORE_FILE} "ipv6_activate_all_interfaces=\"YES\"" >/dev/null 2>&1
exit 0
fi
[ -z "${ip4}" -a -z "${ip6}" ] && err 1 "ip4/mask4 or ip6/mask6 pair is mandatory" > /dev/null
[ -z "${mask4}" -a -z "${mask6}" ] && err 1 "ip4/mask4 or ip6/mask6 pair is mandatory" > /dev/null
validate_nic
# kill_dhclient ${nic}
if [ -n "${ip4}" -a -n "${mask4}" ]; then
sysrc -qf ${STORE_FILE} ifconfig_${nic}="inet ${ip4} mask ${mask4}" >/dev/null 2>&1
echo "${ip4}" > ${CBSD_IP}
elif [ -n "${ip6}" -a -n "${mask6}" ]; then
sysrc -qf ${STORE_FILE} ifconfig_${nic}_ipv6="inet ${ip4} mask ${mask4}" >/dev/null 2>&1
sysrc -qf ${STORE_FILE} ipv6_activate_all_interfaces="YES" > /dev/null 2>&1
else
err 1 "ip4/mask4 or ip6/mask6 pair is mandatory"
fi
[ -n "${gw4}" ] && sysrc -qf ${STORE_FILE} defaultrouter="${gw4}" >/dev/null 2>&1
[ -n "${gw6}" ] && sysrc -qf ${STORE_FILE} ipv6_defaultrouter="${gw4}" >/dev/null 2>&1
;;
*)
usage
;;
esac
exit 0