tweak dhcp service example - add ntp configuration
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
c3896850f7
commit
391dd92ce2
@ -19,24 +19,12 @@
|
|||||||
#let cfg=cfg+1
|
#let cfg=cfg+1
|
||||||
#if[$cfg]=...; ip[$cfg]=...; ipmask[$cfg]=.../...; gw[$cfg]=...; net[$cfg]=... dns[$cfg]=...
|
#if[$cfg]=...; ip[$cfg]=...; ipmask[$cfg]=.../...; gw[$cfg]=...; net[$cfg]=... dns[$cfg]=...
|
||||||
|
|
||||||
exec >"$0.out" 2>&1
|
exec >/dev/null
|
||||||
|
#exec >"$0.out" # debug
|
||||||
|
exec 2>&1
|
||||||
|
|
||||||
test "$interface" || exit 1
|
test "$interface" || exit 1
|
||||||
test -f "$1" || exit 1
|
test "$ip" || exit 1
|
||||||
|
|
||||||
# Unsafe, and does not handle values with spaces:
|
|
||||||
#. "./$1" || exit 1
|
|
||||||
# Safe(r) parsing:
|
|
||||||
sq="'"
|
|
||||||
while read line; do
|
|
||||||
#echo "line: $line"
|
|
||||||
# Skip empty lines and lines with single quotes
|
|
||||||
test "${line##*$sq*}" || continue
|
|
||||||
var="${line%%=*}"
|
|
||||||
val="${line#*=}"
|
|
||||||
#echo "var:$var val:'$val'"
|
|
||||||
eval "$var='$val'"
|
|
||||||
done <"$1"
|
|
||||||
|
|
||||||
{
|
{
|
||||||
echo "let cfg=cfg+1"
|
echo "let cfg=cfg+1"
|
||||||
@ -50,4 +38,4 @@ test "$dns" && echo "dns[\$cfg]='$dns'"
|
|||||||
# which subnet(s) is/are available thru advertised router
|
# which subnet(s) is/are available thru advertised router
|
||||||
# Assume 0/0
|
# Assume 0/0
|
||||||
echo "net[\$cfg]='0/0'"
|
echo "net[\$cfg]='0/0'"
|
||||||
} >"$2"
|
} >"$1"
|
||||||
|
34
examples/var_service/dhcp_if/convert2ntpconf
Executable file
34
examples/var_service/dhcp_if/convert2ntpconf
Executable file
@ -0,0 +1,34 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# convert:
|
||||||
|
|
||||||
|
# dhcptype=5
|
||||||
|
# serverid=172.16.42.102
|
||||||
|
# lease=97200
|
||||||
|
# interface=eth0
|
||||||
|
# ip=172.16.42.177
|
||||||
|
# subnet=255.255.255.0
|
||||||
|
# mask=24
|
||||||
|
# broadcast=172.16.22.255
|
||||||
|
# router=172.16.42.98
|
||||||
|
# dns=10.34.32.125 10.32.63.5 10.34.255.7 10.11.255.27
|
||||||
|
# domain=lab.example.com example.com
|
||||||
|
# ntpsrv=10.34.32.125 10.34.255.7
|
||||||
|
|
||||||
|
# into:
|
||||||
|
|
||||||
|
#let cfg=cfg+1
|
||||||
|
#ntpip[$cfg]=...
|
||||||
|
|
||||||
|
exec >/dev/null
|
||||||
|
#exec >"$0.out" # debug
|
||||||
|
exec 2>&1
|
||||||
|
|
||||||
|
test "$interface" || exit 1
|
||||||
|
test "$ip" || exit 1
|
||||||
|
|
||||||
|
{
|
||||||
|
for n in $ntpsrv; do
|
||||||
|
echo "let cfg=cfg+1"
|
||||||
|
echo "ntpip[\$cfg]='$n'";
|
||||||
|
done
|
||||||
|
} >"$1"
|
@ -3,17 +3,29 @@
|
|||||||
# parameters: $1 and environment
|
# parameters: $1 and environment
|
||||||
#
|
#
|
||||||
# $1 is:
|
# $1 is:
|
||||||
#
|
|
||||||
# deconfig: This argument is used when udhcpc starts, and
|
# deconfig: This argument is used when udhcpc starts, and
|
||||||
# when a lease is lost. The script should put the interface in an
|
# when a leases is lost. The script should put the interface in an
|
||||||
# up, but deconfigured state, ie: ifconfig $interface 0.0.0.0.
|
# up, but deconfigured state, ie: ifconfig $interface 0.0.0.0.
|
||||||
# Environment: interface=ethN
|
|
||||||
#
|
#
|
||||||
# bound: This argument is used when udhcpc moves from an
|
# bound: This argument is used when udhcpc moves from an
|
||||||
# unbound, to a bound state. All of the paramaters are set in
|
# unbound, to a bound state. All of the paramaters are set in
|
||||||
# enviromental variables, The script should configure the interface,
|
# enviromental variables, The script should configure the interface,
|
||||||
# and set any other relavent parameters (default gateway, dns server, etc).
|
# and set any other relavent parameters (default gateway, dns server,
|
||||||
# Environment:
|
# etc).
|
||||||
|
#
|
||||||
|
# renew: This argument is used when a DHCP lease is renewed. All of
|
||||||
|
# the paramaters are set in enviromental variables. This argument is
|
||||||
|
# used when the interface is already configured, so the IP address,
|
||||||
|
# will not change, however, the other DHCP paramaters, such as the
|
||||||
|
# default gateway, subnet mask, and dns server may change.
|
||||||
|
#
|
||||||
|
# nak: This argument is used with udhcpc receives a NAK message.
|
||||||
|
# The script with the deconfig argument will be called directly
|
||||||
|
# afterwards, so no changes to the network interface are neccessary.
|
||||||
|
# This hook is provided for purely informational purposes (the
|
||||||
|
# message option may contain a reason for the NAK).
|
||||||
|
#
|
||||||
|
# env shows something like:
|
||||||
# dhcptype=5
|
# dhcptype=5
|
||||||
# serverid=172.16.42.102
|
# serverid=172.16.42.102
|
||||||
# lease=97200
|
# lease=97200
|
||||||
@ -26,33 +38,19 @@
|
|||||||
# dns=10.34.32.125 10.32.63.5 10.34.255.7 10.11.255.27
|
# dns=10.34.32.125 10.32.63.5 10.34.255.7 10.11.255.27
|
||||||
# domain=lab.example.com example.com
|
# domain=lab.example.com example.com
|
||||||
# ntpsrv=10.34.32.125 10.34.255.7
|
# ntpsrv=10.34.32.125 10.34.255.7
|
||||||
#
|
|
||||||
# renew: This argument is used when a DHCP lease is renewed. All of
|
|
||||||
# the paramaters are set in enviromental variables. This argument is
|
|
||||||
# used when the interface is already configured, so the IP address,
|
|
||||||
# will not change, however, the other DHCP paramaters, such as the
|
|
||||||
# default gateway, subnet mask, and dns server may change.
|
|
||||||
# Environment: same as for "bound".
|
|
||||||
#
|
|
||||||
# nak: This argument is used with udhcpc receives a NAK message.
|
|
||||||
# The script with the deconfig argument will be called directly
|
|
||||||
# afterwards, so no changes to the network interface are neccessary.
|
|
||||||
# This hook is provided for purely informational purposes (the
|
|
||||||
# message option may contain a reason for the NAK).
|
|
||||||
# Environment: interface=ethN, serverid=IP_ADDR
|
|
||||||
#
|
|
||||||
# leasefail: called when lease cannot be obtained
|
|
||||||
# (for example, when DHCP server is down).
|
|
||||||
# Environment: interface=ethN
|
|
||||||
|
|
||||||
# TODO: put domain into /etc/resolv.conf (thru /var/service/fw)
|
# TODO: put domain into /etc/resolv.conf (thru /var/service/fw)
|
||||||
# TODO: feed ntp IPs to /var/service/ntp
|
# TODO: feed ntp IPs to /var/service/ntp
|
||||||
|
|
||||||
service=`basename $PWD`
|
service=${PWD##*/}
|
||||||
outfile="$service.ipconf"
|
file_ipconf="$service.ipconf"
|
||||||
dir="/var/run/service/fw"
|
file_ntpconf="$service.ntpconf"
|
||||||
|
dir_ipconf="/var/run/service/fw"
|
||||||
|
dir_ntpconf="/var/run/service/ntp"
|
||||||
|
|
||||||
exec >>"$0.out" 2>&1
|
exec >/dev/null
|
||||||
|
#exec >>"$0.out" #debug
|
||||||
|
exec 2>&1
|
||||||
|
|
||||||
echo "`date`: Params: $*"
|
echo "`date`: Params: $*"
|
||||||
|
|
||||||
@ -60,23 +58,34 @@ if test x"$1" != x"bound" && test x"$1" != x"renew" ; then
|
|||||||
# Reconfigure network with this interface disabled
|
# Reconfigure network with this interface disabled
|
||||||
echo "Deconfiguring"
|
echo "Deconfiguring"
|
||||||
rm "$service.out"
|
rm "$service.out"
|
||||||
rm "$outfile"
|
rm "$file_ipconf"
|
||||||
rm "$dir/$outfile"
|
rm "$file_ntpconf"
|
||||||
|
rm "$dir_ipconf/$file_ipconf"
|
||||||
|
rm "$dir_ntpconf/$file_ntpconf"
|
||||||
sv u /var/service/fw
|
sv u /var/service/fw
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Bound: we've got the lease
|
# Bound: we've got the lease
|
||||||
|
#env >"$service.out" # debug
|
||||||
|
|
||||||
# Process params
|
./convert2ipconf "$file_ipconf"
|
||||||
env >"$service.out"
|
|
||||||
./convert2ipconf "$service.out" "$outfile"
|
|
||||||
|
|
||||||
# Reconfigure routing and firewall if needed
|
# Reconfigure routing and firewall if needed
|
||||||
diff --brief "$outfile" "$dir/$outfile" >/dev/null 2>&1
|
diff --brief "$file_ipconf" "$dir_ipconf/$file_ipconf" >/dev/null 2>&1
|
||||||
if test "$?" != "0"; then
|
if test "$?" != "0"; then
|
||||||
echo "Reconfiguring"
|
echo "Reconfiguring fw"
|
||||||
mkdir -p "$dir" 2>/dev/null
|
mkdir -p "$dir_ipconf" 2>/dev/null
|
||||||
cp "$outfile" "$dir/$outfile"
|
cp "$file_ipconf" "$dir_ipconf/$file_ipconf"
|
||||||
sv u /var/service/fw
|
sv u /var/service/fw
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
./convert2ntpconf "$file_ntpconf"
|
||||||
|
# Reconfigure ntp server addresses if needed
|
||||||
|
diff --brief "$file_ntpconf" "$dir_ntpconf/$file_ntpconf" >/dev/null 2>&1
|
||||||
|
if test "$?" != "0"; then
|
||||||
|
echo "Reconfiguring ntp"
|
||||||
|
mkdir -p "$dir_ntpconf" 2>/dev/null
|
||||||
|
cp "$file_ntpconf" "$dir_ntpconf/$file_ntpconf"
|
||||||
|
sv t /var/service/ntp
|
||||||
|
sv u /var/service/ntp
|
||||||
|
fi
|
||||||
|
Loading…
x
Reference in New Issue
Block a user