OpenWrt Forum Archive

Topic: strange hex characters in uci output

The content of this topic has been archived on 15 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

I am working with a fairly recent update of the trunk (11415). When I load it up and run any uci show command that has unnamed sections in the file it spits out strange hex codes instead of logical numbers for example part of a uci show wireless output:

...
wireless.cfg03c014.ssid=ssid
wireless.cfg03c014.mode=ap
wireless.cfg03c014.device=wl0
...

When I have worked with all previous versions of Kamikaze up through 7.09 it would have been cfg2 instead of cfg03c014.  The cfg2 makes sense since this is the second config section in the wireless config file (the first being the wireless.wl0 section).

Is this a bug or is this a planned change? If it is a planned change is there any way to predict what that hex value will be?

Thanks,

This is if the config file contains an unnamed section.

Right. I know when it happens. My question is: is it still supposed to be a 2 and the hex value showing up is a bug or did someone make a decision at some point that the hex value would be better than the integer?

The reason I need to know is I built a couple of shell scripts to manage a few things and I utilized the uci tools to manage the config files. These hex values are breaking all of my scripts though. I need to know if I can wait for a fix (or fix it myself) or if I should abandon the uci scripts and build my own configuration management tools.

Here is a quick little wrapper script I wrote to provide the same get/set behaviour as the kamikaze 7.09 and earlier versions of the uci command. Hope this helps anyone else who had trouble with the hex values that crept into the uci's unnamed configuration sections since 7.09. Please let me know if there are any better/easier ways of accomplishing the same thing.

#!/bin/sh

# A wrapper for the uci command
# This wrapper will have the same syntax as the uci command but it will only
#  implement get, set, show, and commit.
# The unnamed configuration sections went from being auto-named cfg1, cfg2, ...
#  to cfg<hex> ... so this wrapper attempts to work around this
#  by translating a number to the appropriate hex string.

. /etc/functions.sh

# Parse the command line
BCI_ACTION=$1
shift

# Deal with a commit command
if [ $BCI_ACTION == "commit" ]; then
        uci commit
        exit 0
fi

# Deal with a show command
if [ $BCI_ACTION == "show" ]; then
        uci show $*
        exit 0
fi

strtok "$*" BCI_FILE "." BCI_SEC "." BCI_ELEM "=" BCI_VALUE

# assume we either have a number or a cfg# syntax
# This sed command strips the input down to just the number at the end
BCI_SEC=$(echo $BCI_SEC | sed 's/[a-zA-Z]*\([0-9]*\)/\1/')

# Load the appropriate config
config_load $BCI_FILE

# Start searching for the configuration section we are looking for
BCI_CFGNUM=1
for cfgsec in $CONFIG_SECTIONS; do
        if [ $BCI_CFGNUM -eq $BCI_SEC ]; then # Found it!
                if [ $BCI_ACTION == "set" ]; then
                        uci set ${BCI_FILE}.${cfgsec}.${BCI_ELEM}=$BCI_VALUE
                else
                        uci get ${BCI_FILE}.${cfgsec}.${BCI_ELEM}
                fi
        fi
        BCI_CFGNUM=$(expr $BCI_CFGNUM "+" 1)
done

exit 0

The discussion might have continued from here.