Commit c9fe1601 authored by Jean-Claude BAU's avatar Jean-Claude BAU

dot-config script: new behavior

When the dot-config file is read at startup using the DHCP service to
get the server IP address, the script waits forever the availability of
DHCP service in the following case :
- CONFIG_DOTCONF_SOURCE_FORCE_DHCP=y AND CONFIG_ETH0_DHCP=y

CONFIG_ETH0_DHCP: Set to indicate that the network is forced to use DHCP
for its setup.

In the other cases, the behavior stay unchanged.
parent c21ed26c
...@@ -10,12 +10,28 @@ dotconfig=/wr/etc/dot-config ...@@ -10,12 +10,28 @@ dotconfig=/wr/etc/dot-config
tmpconfig=/tmp/dot-config tmpconfig=/tmp/dot-config
tmpdir=/tmp tmpdir=/tmp
log_output=/dev/kmsg log_output=/dev/kmsg
management_port=eth0
me=`basename "$0"`
set -o pipefail # The return value of a pipeline is the status of set -o pipefail # The return value of a pipeline is the status of
# the last command to exit with a non-zero status, # the last command to exit with a non-zero status,
# or zero if no command exited with a non-zero status # or zero if no command exited with a non-zero status
# Needed for return value ($?) of xxx in "xxx | tee yyy" # Needed for return value ($?) of xxx in "xxx | tee yyy"
#
# This function is looping forever until DHCP is reachable
#
wait_dhcp_forever()
{
while : ; do
udhcpc -n -q -i $management_port
if [ "$?" -eq "0" ]; then
break
fi
echo "$me: waiting DHCP service...."
sleep 5
done
}
rm -f "$tmpdir"/dot-config_source rm -f "$tmpdir"/dot-config_source
...@@ -58,40 +74,44 @@ if [ "$CONFIG_DOTCONF_SOURCE_REMOTE" = "y" ] || [ "$CONFIG_DOTCONF_SOURCE_TRY_DH ...@@ -58,40 +74,44 @@ if [ "$CONFIG_DOTCONF_SOURCE_REMOTE" = "y" ] || [ "$CONFIG_DOTCONF_SOURCE_TRY_DH
# get URL via DHCP # get URL via DHCP
if [ "$CONFIG_DOTCONF_SOURCE_TRY_DHCP" = "y" ] \ if [ "$CONFIG_DOTCONF_SOURCE_TRY_DHCP" = "y" ] \
|| [ "$CONFIG_DOTCONF_SOURCE_FORCE_DHCP" = "y" ]; then || [ "$CONFIG_DOTCONF_SOURCE_FORCE_DHCP" = "y" ]; then
if [ "$CONFIG_DOTCONF_SOURCE_TRY_DHCP" = "y" ]; then if [ "$CONFIG_DOTCONF_SOURCE_TRY_DHCP" = "y" ]; then
echo "try_dhcp" > "$tmpdir"/dot-config_source echo "try_dhcp" > "$tmpdir"/dot-config_source
fi fi
if [ "$CONFIG_DOTCONF_SOURCE_FORCE_DHCP" = "y" ]; then if [ "$CONFIG_DOTCONF_SOURCE_FORCE_DHCP" = "y" ]; then
echo "force_dhcp" > "$tmpdir"/dot-config_source echo "force_dhcp" > "$tmpdir"/dot-config_source
fi fi
# up eth0 to allow dhcp requests # up management port to allow dhcp requests
ifconfig eth0 up ifconfig $management_port up
# let udhcpc run /wr/bin/dhcp_get_filename.sh script to get "filename" if [ "$CONFIG_DOTCONF_SOURCE_FORCE_DHCP" = "y" ] && [ "$CONFIG_ETH0_DHCP" = "y" ]; then
# from DHCP (which contain url with dot-config). # Wait DHCP forever only if DHCP is also forced on management port
/sbin/udhcpc -i eth0 -s /wr/bin/dhcp_get_filename.sh -O bootfile -o \ wait_dhcp_forever
-n -q -f -t 5 &>/dev/null fi
if [ -f "$tmpdir"/dot-config_source_url ]; then # let udhcpc run /wr/bin/dhcp_get_filename.sh script to get "filename"
# replace CONFIG_DOTCONF_URL with one gotten from dhcp # from DHCP (which contain url with dot-config).
CONFIG_DOTCONF_URL=`cat "$tmpdir"/dot-config_source_url` /sbin/udhcpc -i $management_port -s /wr/bin/dhcp_get_filename.sh -O bootfile -o \
echo "Got dot-config's URL ("$CONFIG_DOTCONF_URL") via DHCP" | tee $log_output >& 2 -n -q -f -t 5 &>/dev/null
else if [ -f "$tmpdir"/dot-config_source_url ]; then
echo "dhcp_error" > "$tmpdir"/dot-config_status # replace CONFIG_DOTCONF_URL with one gotten from dhcp
echo "Unable to get dot-config's URL via DHCP, using old dot-config" | tee $log_output >& 2 CONFIG_DOTCONF_URL=`cat "$tmpdir"/dot-config_source_url`
# apply old dot-config echo "Got dot-config's URL ("$CONFIG_DOTCONF_URL") via DHCP" | tee $log_output >& 2
/wr/bin/apply_dot-config else
exit echo "dhcp_error" > "$tmpdir"/dot-config_status
fi echo "Unable to get dot-config's URL via DHCP, using old dot-config" | tee $log_output >& 2
# apply old dot-config
/wr/bin/apply_dot-config
exit
fi
fi fi
# replace IPADDR and MACADDR, to have a device-specific name # replace IPADDR and MACADDR, to have a device-specific name
macaddr=$(cat /sys/class/net/eth0/address) macaddr=$(cat /sys/class/net/${management_port}/address)
ipaddr=$(ifconfig eth0 | grep inet | cut -d: -f 2 | cut '-d ' -f 1) ipaddr=$(ifconfig ${management_port} | grep inet | cut -d: -f 2 | cut '-d ' -f 1)
if [ -z "$ipaddr" ]; then if [ -z "$ipaddr" ]; then
# if no IP address available from barebox try to get IP from old dot-config # if no IP address available from barebox try to get IP from old dot-config
# /etc/init.d/network will run later again # /etc/init.d/network will run later again
/etc/init.d/network /etc/init.d/network
ipaddr=$(ifconfig eth0 | grep inet | cut -d: -f 2 | cut '-d ' -f 1) ipaddr=$(ifconfig ${management_port} | grep inet | cut -d: -f 2 | cut '-d ' -f 1)
fi fi
host_name=`hostname` host_name=`hostname`
URL=$(echo $CONFIG_DOTCONF_URL | \ URL=$(echo $CONFIG_DOTCONF_URL | \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment