Commit 80663297 authored by Adam Wujek's avatar Adam Wujek 💬

rootfs: add checking of local dot-config

In some rare cases it can happen that locally stored dot-config is not valid.
For example, when firmware on the switch was updated, but the old dot-config is
still used. However, such scenario is unlikely because new firmware should
contain new dot-config.

--check whether sourcing was successful
--Replace "." with "source" when sourcing dot-config.
--Redirect errors to the stderr.
Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent 3da5579a
......@@ -13,10 +13,19 @@ tmpdir=/tmp
rm -f "$tmpdir"/dot-config_source
if [ -f $dotconfig ]; then
. $dotconfig
#assume that local config is always ok
echo "config_ok" > "$tmpdir"/dot-config_status
source $dotconfig
ret_source=$?
/wr/bin/wrs_checkcfg $dotconfig /wr/etc/Kconfig
ret_check=$?
if [ $ret_source != 0 ] || [ $ret_check != 0 ]; then
# errors in local dot-config
echo "check_error" > "$tmpdir"/dot-config_status
echo "Errors found in local dot-config!!!" >& 2
else
echo "config_ok" > "$tmpdir"/dot-config_status
fi
else
echo "No /wr/etc/dot-config to use" >& 2
echo "no_config" > "$tmpdir"/dot-config_source
echo "config_error" > "$tmpdir"/dot-config_status
fi
......@@ -57,10 +66,10 @@ if [ "$CONFIG_DOTCONF_SOURCE_REMOTE" = "y" ] || [ "$CONFIG_DOTCONF_SOURCE_TRY_DH
if [ -f "$tmpdir"/dot-config_source_url ]; then
# replace CONFIG_DOTCONF_URL with one gotten from dhcp
CONFIG_DOTCONF_URL=`cat "$tmpdir"/dot-config_source_url`
echo "Got dot-config's URL ("$CONFIG_DOTCONF_URL") via DHCP"
echo "Got dot-config's URL ("$CONFIG_DOTCONF_URL") via DHCP" >& 2
else
echo "dhcp_error" > "$tmpdir"/dot-config_status
echo "Unable to get dot-config's URL via DHCP, using old dot-config"
echo "Unable to get dot-config's URL via DHCP, using old dot-config" >& 2
# apply old dot-config
/wr/bin/apply_dot-config
exit
......@@ -101,24 +110,24 @@ if [ "$CONFIG_DOTCONF_SOURCE_REMOTE" = "y" ] || [ "$CONFIG_DOTCONF_SOURCE_TRY_DH
# If it exists, it is not empty or too small, and the checker is happy
if [ $(cat $tmpconfig | wc -c) -gt 200 ] &&
/wr/bin/wrs_checkcfg $tmpconfig /wr/etc/Kconfig; then
echo "Using newly-downloaded dot-config from $URL"
echo "Using newly-downloaded dot-config from $URL" >& 2
# copy it in place to use the new file (unless it is identical)
cmp -s $tmpconfig $dotconfig || cp $tmpconfig $dotconfig
# info for SNMP that downloading was successful and checker is happy
echo "config_ok" > "$tmpdir"/dot-config_status
else
echo "check_error" > "$tmpdir"/dot-config_status
echo "Errors found in downloaded dot-config \"$URL\", using old"
echo "Errors found in downloaded dot-config \"$URL\", using old" >& 2
fi
else
echo "download_error" > "$tmpdir"/dot-config_status
echo "Download error for dot-config \"$URL\", using old"
echo "Download error for dot-config \"$URL\", using old" >& 2
fi
elif [ "$CONFIG_DOTCONF_SOURCE_LOCAL" = "y" ]; then
echo "local" > "$tmpdir"/dot-config_source
echo "Using local dot-config"
echo "Using local dot-config" >& 2
else
echo "Unknown dot-config source. Using local dot-config"
echo "Unknown dot-config source. Using local dot-config" >& 2
fi
# Finally, apply what we have, be it old or new
......
......@@ -12,7 +12,8 @@
# We create a temporary file in /tmp, to avoid wearing flash if not
# needed. Then we replace the real file if different.
T=$(mktemp /tmp/config-XXXXXX)
tmpdir=/tmp
T=$(mktemp "$tmpdir"/config-XXXXXX)
copy_conf() {
# busybox cmp exits 1 or 2 according to GNU man page
......@@ -25,18 +26,28 @@ copy_conf() {
if [ "$1" == "local_config" ]; then
# remove source information in case previous config was received from
# network
rm /tmp/dot-config_*
echo "local" > /tmp/dot-config_source
#assume that local config is always ok
echo "config_ok" > /tmp/dot-config_status
rm "$tmpdir"/dot-config_*
echo "local" > "$tmpdir"/dot-config_source
fi
# Check and complain, but we need to edit some files even if unconfigured.
if [ -f /wr/etc/dot-config ]; then
. /wr/etc/dot-config
source /wr/etc/dot-config
ret_source=$?
/wr/bin/wrs_checkcfg /wr/etc/dot-config /wr/etc/Kconfig
ret_check=$?
configured=true
if [ $ret_source != 0 ] || [ $ret_check != 0 ]; then
# errors in local dot-config
echo "check_error" > "$tmpdir"/dot-config_status
echo "Errors found in local dot-config!!!" >& 2
else
echo "config_ok" > "$tmpdir"/dot-config_status
fi
else
echo "No /wr/etc/dot-config to use" >& 2
echo "no_config" > "$tmpdir"/dot-config_source
echo "config_error" > "$tmpdir"/dot-config_status
configured=false
fi
......@@ -99,7 +110,7 @@ elif [ "$CONFIG_PTP_REMOTE_CONF" = "y" ]; then
# Warning: code below copied from /etc/init.d/dot-config.
tmpconfig=/tmp/ppsi-config
tmpconfig="$tmpdir"/ppsi-config
# replace IPADDR and MACADDR, to have a device-specific name
macaddr=$(cat /sys/class/net/eth0/address)
......@@ -136,7 +147,7 @@ elif [ "$CONFIG_PTP_REMOTE_CONF" = "y" ]; then
fi
else
# no valid PTP option keep ppsi.conf with old postfix
echo "No valid PTP option in dot-config!"
echo "No valid PTP option in dot-config!" >& 2
if [ -f /wr/etc/ppsi.conf ]; then
mv -f /wr/etc/ppsi.conf /wr/etc/ppsi.conf.old
fi
......
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