# Copyright (C) 2006-2014 OpenWrt.org # Copyright (C) 2006 Fokus Fraunhofer # Copyright (C) 2010 Vertical Communications debug () { ${DEBUG:-:} "$@" } # newline N=" " _C=0 NO_EXPORT=1 LOAD_STATE=1 LIST_SEP=" " # xor multiple hex values of the same length xor() { local val local ret="0x$1" local retlen=${#1} shift while [ -n "$1" ]; do val="0x$1" ret=$((ret ^ val)) shift done printf "%0${retlen}x" "$ret" } append() { local var="$1" local value="$2" local sep="${3:- }" eval "export ${NO_EXPORT:+-n} -- \"$var=\${$var:+\${$var}\${value:+\$sep}}\$value\"" } prepend() { local var="$1" local value="$2" local sep="${3:- }" eval "export ${NO_EXPORT:+-n} -- \"$var=\$value\${$var:+\${sep}\${$var}}\"" } list_contains() { local var="$1" local str="$2" local val eval "val=\" \${$var} \"" [ "${val%% $str *}" != "$val" ] } config_load() { [ -n "$IPKG_INSTROOT" ] && return 0 uci_load "$@" } reset_cb() { config_cb() { return 0; } option_cb() { return 0; } list_cb() { return 0; } } reset_cb package() { return 0 } config () { local cfgtype="$1" local name="$2" export ${NO_EXPORT:+-n} CONFIG_NUM_SECTIONS=$((CONFIG_NUM_SECTIONS + 1)) name="${name:-cfg$CONFIG_NUM_SECTIONS}" append CONFIG_SECTIONS "$name" export ${NO_EXPORT:+-n} CONFIG_SECTION="$name" config_set "$CONFIG_SECTION" "TYPE" "${cfgtype}" [ -n "$NO_CALLBACK" ] || config_cb "$cfgtype" "$name" } option () { local varname="$1"; shift local value="$*" config_set "$CONFIG_SECTION" "${varname}" "${value}" [ -n "$NO_CALLBACK" ] || option_cb "$varname" "$*" } list() { local varname="$1"; shift local value="$*" local len config_get len "$CONFIG_SECTION" "${varname}_LENGTH" 0 [ $len = 0 ] && append CONFIG_LIST_STATE "${CONFIG_SECTION}_${varname}" len=$((len + 1)) config_set "$CONFIG_SECTION" "${varname}_ITEM$len" "$value" config_set "$CONFIG_SECTION" "${varname}_LENGTH" "$len" append "CONFIG_${CONFIG_SECTION}_${varname}" "$value" "$LIST_SEP" [ -n "$NO_CALLBACK" ] || list_cb "$varname" "$*" } config_unset() { config_set "$1" "$2" "" } # config_get