Here comes the new UCI. Enjoy :)
git-svn-id: svn://svn.openwrt.org/openwrt/trunk@10367 3c298f89-4303-0410-b956-a3cf2f4a3e73master
parent
6cecfe7d32
commit
2f8b5f8c28
|
@ -10,6 +10,7 @@ N="
|
|||
|
||||
_C=0
|
||||
NO_EXPORT=1
|
||||
LOAD_STATE=1
|
||||
|
||||
hotplug_dev() {
|
||||
env -i ACTION=$1 INTERFACE=$2 /sbin/hotplug-call net
|
||||
|
@ -23,12 +24,21 @@ append() {
|
|||
eval "export ${NO_EXPORT:+-n} -- \"$var=\${$var:+\${$var}\${value:+\$sep}}\$value\""
|
||||
}
|
||||
|
||||
config_load() {
|
||||
[ -n "$IPKG_INSTROOT" ] && return 0
|
||||
uci_load "$@"
|
||||
}
|
||||
|
||||
reset_cb() {
|
||||
config_cb() { return 0; }
|
||||
option_cb() { return 0; }
|
||||
}
|
||||
reset_cb
|
||||
|
||||
package() {
|
||||
return 0
|
||||
}
|
||||
|
||||
config () {
|
||||
local cfgtype="$1"
|
||||
local name="$2"
|
||||
|
@ -84,37 +94,6 @@ config_clear() {
|
|||
done
|
||||
}
|
||||
|
||||
config_load() {
|
||||
local cfg
|
||||
local uci
|
||||
local PACKAGE="$1"
|
||||
|
||||
case "$PACKAGE" in
|
||||
/*) cfg="$PACKAGE"
|
||||
uci=""
|
||||
;;
|
||||
*) cfg="$UCI_ROOT/etc/config/$PACKAGE"
|
||||
uci="/tmp/.uci/${PACKAGE}"
|
||||
;;
|
||||
esac
|
||||
|
||||
[ -e "$cfg" ] || cfg=""
|
||||
[ -e "$uci" ] || uci=""
|
||||
|
||||
# no config
|
||||
[ -z "$cfg" -a -z "$uci" ] && return 1
|
||||
|
||||
_C=0
|
||||
export ${NO_EXPORT:+-n} CONFIG_SECTIONS=
|
||||
export ${NO_EXPORT:+-n} CONFIG_NUM_SECTIONS=0
|
||||
export ${NO_EXPORT:+-n} CONFIG_SECTION=
|
||||
|
||||
${cfg:+. "$cfg"}
|
||||
${uci:+. "$uci"}
|
||||
|
||||
${CONFIG_SECTION:+config_cb}
|
||||
}
|
||||
|
||||
config_get() {
|
||||
case "$3" in
|
||||
"") eval "echo \"\${CONFIG_${1}_${2}}\"";;
|
||||
|
@ -218,8 +197,15 @@ jffs2_mark_erase() {
|
|||
echo -e "\xde\xad\xc0\xde" | mtd -qq write - "$1"
|
||||
}
|
||||
|
||||
uci_set_default() {
|
||||
local PACKAGE="$1"
|
||||
[ -e "/etc/config/$1" ] && return 0
|
||||
cat > "/etc/config/$1"
|
||||
}
|
||||
uci_apply_defaults() {(
|
||||
cd /etc/uci-defaults || return 0
|
||||
files="$(ls)"
|
||||
[ -z "$files" ] && return 0
|
||||
mkdir -p /tmp/.uci
|
||||
for file in $files; do
|
||||
( . "./$(basename $file)" ) && rm -f "$file"
|
||||
done
|
||||
uci commit
|
||||
)}
|
||||
|
||||
[ -z "$IPKG_INSTROOT" ] && . /lib/config/uci.sh
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
[ ifup = "$ACTION" ] && {
|
||||
uci set "/var/state/network.$INTERFACE.up=1"
|
||||
uci_set_state network "$INTERFACE" up 1
|
||||
}
|
||||
|
|
|
@ -63,7 +63,6 @@ case "$ACTION" in
|
|||
ifup)
|
||||
include /lib/network
|
||||
scan_interfaces
|
||||
. /var/state/network
|
||||
config_foreach "add_route" route
|
||||
config_foreach "add_route6" route6
|
||||
;;
|
||||
|
|
|
@ -36,6 +36,8 @@ start() {
|
|||
mkdir -p /var/log
|
||||
mkdir -p /var/lock
|
||||
mkdir -p /var/state
|
||||
mkdir -p /tmp/.uci
|
||||
chown 0700 /tmp/.uci
|
||||
touch /var/log/wtmp
|
||||
touch /var/log/lastlog
|
||||
ln -sf /tmp/resolv.conf.auto /tmp/resolv.conf
|
||||
|
|
|
@ -140,7 +140,7 @@ setup_interface() {
|
|||
config_get macaddr "$config" macaddr
|
||||
grep "$iface:" /proc/net/dev > /dev/null && \
|
||||
$DEBUG ifconfig "$iface" ${macaddr:+hw ether "$macaddr"} ${mtu:+mtu $mtu} up
|
||||
uci set "/var/state/network.$config.ifname=$iface"
|
||||
uci_set_state network "$config" ifname "$iface"
|
||||
|
||||
pidfile="/var/run/$iface.pid"
|
||||
case "$proto" in
|
||||
|
|
|
@ -11,12 +11,8 @@
|
|||
exit
|
||||
}
|
||||
|
||||
config_load /var/state/network
|
||||
|
||||
# remove the interface's network state
|
||||
FILE=/var/state/network.$$
|
||||
grep -v "^config_set '$1' " /var/state/network > "$FILE"
|
||||
mv "$FILE" /var/state/network
|
||||
uci_revert_state network "$1"
|
||||
|
||||
include /lib/network
|
||||
scan_interfaces
|
||||
|
|
|
@ -75,22 +75,19 @@ start_net() {(
|
|||
set_wifi_up() {
|
||||
local cfg="$1"
|
||||
local ifname="$2"
|
||||
uci set "/var/state/wireless.${cfg}.up=1"
|
||||
uci set "/var/state/wireless.${cfg}.ifname=$ifname"
|
||||
uci_set_state wireless "$cfg" up 1
|
||||
uci_set_state wireless "$cfg" ifname "$ifname"
|
||||
}
|
||||
|
||||
set_wifi_down() {
|
||||
local cfg="$1"
|
||||
local vifs vif vifstr
|
||||
[ -f /var/state/wireless ] || return
|
||||
|
||||
uci_revert_state wireless "$cfg"
|
||||
config_get vifs "$cfg" vifs
|
||||
for vif in $vifs; do
|
||||
append vifstr "$vif" "|"
|
||||
uci_revert_state wireless "$vif"
|
||||
done
|
||||
FILE="/var/state/wireless.$$"
|
||||
grep -vE "^config_set '($vifstr)' " /var/state/wireless > "$FILE"
|
||||
mv "$FILE" /var/state/wireless
|
||||
}
|
||||
|
||||
scan_wifi() {
|
||||
|
|
|
@ -7,7 +7,6 @@ RESOLV_CONF="/tmp/resolv.conf.auto"
|
|||
|
||||
hotplug_event() {
|
||||
scan_interfaces
|
||||
config_load /var/state/network
|
||||
for ifc in $interfaces; do
|
||||
config_get ifname $ifc ifname
|
||||
[ "$ifname" = "$interface" ] || continue
|
||||
|
@ -15,11 +14,11 @@ hotplug_event() {
|
|||
config_get proto $ifc proto
|
||||
[ "$proto" = "dhcp" ] || continue
|
||||
[ ifup = "$1" ] && {
|
||||
uci set "/var/state/network.$ifc.ipaddr=$ip"
|
||||
uci set "/var/state/network.$ifc.netmask=${subnet:-255.255.255.0}"
|
||||
uci set "/var/state/network.$ifc.dnsdomain=$domain"
|
||||
uci set "/var/state/network.$ifc.dns=$dns"
|
||||
uci set "/var/state/network.$ifc.gateway=$router"
|
||||
uci_set_state network "$ifc" ipaddr "$ip"
|
||||
uci_set_state network "$ifc" netmask "${subnet:-255.255.255.0}"
|
||||
uci_set_state network "$ifc" dnsdomain "$domain"
|
||||
uci_set_state network "$ifc" dns "$dns"
|
||||
uci_set_state network "$ifc" gateway "$router"
|
||||
}
|
||||
env -i ACTION="$1" INTERFACE="$ifc" DEVICE="$ifname" PROTO=dhcp /sbin/hotplug-call iface
|
||||
done
|
||||
|
|
|
@ -231,7 +231,6 @@ dhcp_option_add() {
|
|||
start() {
|
||||
include /lib/network
|
||||
scan_interfaces
|
||||
config_load /var/state/network
|
||||
config_load dhcp
|
||||
|
||||
args=""
|
||||
|
|
|
@ -6,7 +6,6 @@ START=45
|
|||
start() {
|
||||
include /lib/network
|
||||
scan_interfaces
|
||||
config_load /var/state/network
|
||||
|
||||
config_get WAN wan ifname
|
||||
config_get WANDEV wan device
|
||||
|
|
|
@ -10,9 +10,7 @@ export PPP_IFACE PPP_TTY PPP_SPEED PPP_LOCAL PPP_REMOTE PPP_IPPARAM
|
|||
env -i ACTION="ifdown" INTERFACE="$PPP_IPPARAM" DEVICE="$PPP_IFACE" PROTO=ppp /sbin/hotplug-call "iface"
|
||||
|
||||
# remove the interface's network state
|
||||
FILE=/var/state/network.$$
|
||||
grep -v "^config_set '$PPP_IPPARAM' " /var/state/network > "$FILE"
|
||||
mv "$FILE" /var/state/network
|
||||
uci_revert_state network "$PPP_IPPARAM"
|
||||
}
|
||||
|
||||
[ -d /etc/ppp/ip-down.d ] && {
|
||||
|
|
|
@ -8,8 +8,8 @@ PPP_IPPARAM="$6"
|
|||
export PPP_IFACE PPP_TTY PPP_SPEED PPP_LOCAL PPP_REMOTE PPP_IPPARAM
|
||||
[ -z "$PPP_IPPARAM" ] || env -i ACTION="ifup" INTERFACE="$PPP_IPPARAM" DEVICE="$PPP_IFACE" PROTO=ppp /sbin/hotplug-call "iface"
|
||||
[ -z "$PPP_IPPARAM" -o -z "$PPP_LOCAL" ] || {
|
||||
uci set "/var/state/network.$PPP_IPPARAM.ipaddr=$PPP_LOCAL"
|
||||
uci set "/var/state/network.$PPP_IPPARAM.gateway=$PPP_REMOTE"
|
||||
uci_set_state network "$PPP_IPPARAM" ipaddr "$PPP_LOCAL"
|
||||
uci_set_state network "$PPP_IPPARAM" gateway "$PPP_REMOTE"
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ setup_interface_pptp() {
|
|||
# make sure the network state references the correct ifname
|
||||
scan_ppp "$config"
|
||||
config_get ifname "$config" ifname
|
||||
uci set "/var/state/network.$config.ifname=$ifname"
|
||||
uci_set_state network "$config" ifname "$ifname"
|
||||
|
||||
config_get mtu "$cfg" mtu
|
||||
config_get server "$cfg" server
|
||||
|
|
|
@ -17,7 +17,6 @@ add_insmod() {
|
|||
reset_cb
|
||||
include /lib/network
|
||||
scan_interfaces
|
||||
config_load /var/state/network
|
||||
config_get "$1" ifname
|
||||
)}
|
||||
} || {
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
#
|
||||
# Copyright (C) 2008 OpenWrt.org
|
||||
#
|
||||
# This is free software, licensed under the GNU General Public License v2.
|
||||
# See /LICENSE for more information.
|
||||
#
|
||||
# $Id$
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=uci
|
||||
PKG_VERSION:=0.1
|
||||
PKG_RELEASE:=1
|
||||
|
||||
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
|
||||
PKG_SOURCE_URL:=http://downloads.openwrt.org/sources
|
||||
PKG_MD5SUM:=f6340dce09f5f1552c4e03be98e64265
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
|
||||
# set to 1 to enable debugging
|
||||
DEBUG=
|
||||
|
||||
define Package/libuci
|
||||
SECTION:=libs
|
||||
CATEGORY:=Libraries
|
||||
DEPENDS:=+libuci
|
||||
TITLE:=C library for the Unified Configuration Interface (UCI)
|
||||
endef
|
||||
|
||||
define Package/uci
|
||||
SECTION:=base
|
||||
CATEGORY:=Base system
|
||||
DEPENDS:=+libuci
|
||||
TITLE:=Utility for the Unified Configuration Interface (UCI)
|
||||
endef
|
||||
|
||||
define Package/uci-sh
|
||||
SECTION:=base
|
||||
CATEGORY:=Base system
|
||||
DEPENDS:=@!PACKAGE_uci
|
||||
TITLE:=Old shell/awk implementation of UCI
|
||||
endef
|
||||
|
||||
define Build/Configure
|
||||
endef
|
||||
|
||||
define Build/Compile
|
||||
$(MAKE) -C $(PKG_BUILD_DIR) \
|
||||
$(TARGET_CONFIGURE_OPTS) \
|
||||
COPTS="$(TARGET_CFLAGS)" \
|
||||
DEBUG="$(DEBUG)" \
|
||||
VERSION="$(PKG_VERSION)" \
|
||||
OS="Linux"
|
||||
endef
|
||||
|
||||
define Package/libuci/install
|
||||
$(INSTALL_DIR) $(1)/lib
|
||||
$(CP) $(PKG_BUILD_DIR)/libuci.so* $(1)/lib/
|
||||
endef
|
||||
|
||||
define Package/uci/install
|
||||
$(INSTALL_DIR) $(1)/sbin
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/uci $(1)/sbin/
|
||||
$(CP) ./files/uci/* $(1)/
|
||||
endef
|
||||
|
||||
define Package/uci-sh/install
|
||||
$(INSTALL_DIR) $(1)
|
||||
$(CP) ./files/uci-sh/* $(1)/
|
||||
endef
|
||||
|
||||
$(eval $(call BuildPackage,uci))
|
||||
$(eval $(call BuildPackage,libuci))
|
||||
$(eval $(call BuildPackage,uci-sh))
|
|
@ -80,7 +80,7 @@ function uci_update_config(cfg, update, \
|
|||
i2 = 1
|
||||
delete l
|
||||
rest = line
|
||||
while (length(rest)) {
|
||||
while (length(rest)) {
|
||||
if (match(rest, /[ \t\"]+/)) {
|
||||
if (RSTART>1) {
|
||||
l[i2] = substr(rest,1,RSTART-1)
|
|
@ -18,20 +18,41 @@
|
|||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
uci_load() {
|
||||
config_load "$1"
|
||||
uci_set_default() {
|
||||
local PACKAGE="$1"
|
||||
[ -e "/etc/config/$1" ] && return 0
|
||||
cat > "/etc/config/$1"
|
||||
}
|
||||
|
||||
uci_apply_defaults() {(
|
||||
cd /etc/uci-defaults || return 0
|
||||
files="$(ls)"
|
||||
[ -z "$files" ] && return 0
|
||||
mkdir -p /tmp/.uci
|
||||
for file in $files; do
|
||||
( . "./$(basename $file)" ) && rm -f "$file"
|
||||
done
|
||||
uci commit
|
||||
)}
|
||||
uci_load() {
|
||||
local cfg
|
||||
local uci
|
||||
|
||||
_C=0
|
||||
export ${NO_EXPORT:+-n} CONFIG_SECTIONS=
|
||||
export ${NO_EXPORT:+-n} CONFIG_NUM_SECTIONS=0
|
||||
export ${NO_EXPORT:+-n} CONFIG_SECTION=
|
||||
|
||||
case "$PACKAGE" in
|
||||
/*) cfg="$PACKAGE";;
|
||||
*)
|
||||
cfg="$UCI_ROOT/etc/config/$PACKAGE"
|
||||
uci="$UCI_ROOT/tmp/.uci/$PACKAGE"
|
||||
state="$UCI_ROOT/var/state/$PACKAGE"
|
||||
;;
|
||||
esac
|
||||
|
||||
# no config?
|
||||
[ -z "$cfg" -o \! -f "$cfg" ] && return 1
|
||||
. "$cfg"
|
||||
|
||||
${CONFIG_SECTION:+config_cb}
|
||||
|
||||
[ -z "$uci" -o \! -f "$uci" ] || . "$uci"
|
||||
[ -z "$LOAD_STATE" -z "$state" -o \! -f "$state" ] || . "$state"
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
uci_call_awk() {
|
||||
local CMD="$*"
|
||||
|
@ -70,6 +91,25 @@ uci_add_update() {
|
|||
echo "$UPDATE" >> "$UCIFILE"
|
||||
}
|
||||
|
||||
uci_revert_state() {
|
||||
local PACKAGE="$1"
|
||||
local CONFIG="$2"
|
||||
FILE="/var/state/$PACKAGE.$$"
|
||||
grep -v "^config_set '$CONFIG' " "/var/state/$PAKAGE" > "$FILE"
|
||||
mv "$FILE" "/var/state/$PACKAGE"
|
||||
}
|
||||
|
||||
uci_set_state() {
|
||||
local PACKAGE="$1"
|
||||
local CONFIG="$2"
|
||||
local OPTION="$3"
|
||||
local VALUE="$4"
|
||||
|
||||
[ -z "$VALUE" ] && return 1
|
||||
uci_set "/var/state/$PACKAGE" "$CONFIG" "$OPTION" "$VALUE"
|
||||
}
|
||||
|
||||
|
||||
uci_set() {
|
||||
local PACKAGE="$1"
|
||||
local CONFIG="$2"
|
|
@ -0,0 +1,93 @@
|
|||
#!/bin/sh
|
||||
# Shell script compatibility wrappers for /sbin/uci
|
||||
#
|
||||
# Copyright (C) 2008 Felix Fietkau <nbd@openwrt.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
uci_load() {
|
||||
local PACKAGE="$1"
|
||||
|
||||
_C=0
|
||||
export ${NO_EXPORT:+-n} CONFIG_SECTIONS=
|
||||
export ${NO_EXPORT:+-n} CONFIG_NUM_SECTIONS=0
|
||||
export ${NO_EXPORT:+-n} CONFIG_SECTION=
|
||||
|
||||
eval "$(/sbin/uci ${LOAD_STATE:+-P /var/state} -S -n export "$PACKAGE")"
|
||||
|
||||
${CONFIG_SECTION:+config_cb}
|
||||
}
|
||||
|
||||
uci_set_default() {
|
||||
local PACKAGE="$1"
|
||||
/sbin/uci -q show "$1" > /dev/null && return 0
|
||||
/sbin/uci import "$1"
|
||||
}
|
||||
|
||||
uci_revert_state() {
|
||||
local PACKAGE="$1"
|
||||
local CONFIG="$2"
|
||||
local OPTION="$3"
|
||||
|
||||
/bin/uci -P /var/state revert "$PACKAGE${CONFIG:+.$CONFIG}${OPTION:+.$OPTION}"
|
||||
}
|
||||
|
||||
uci_set_state() {
|
||||
local PACKAGE="$1"
|
||||
local CONFIG="$2"
|
||||
local OPTION="$3"
|
||||
local VALUE="$4"
|
||||
|
||||
[ -z "$VALUE" ] && return 0
|
||||
/sbin/uci -P /var/state set "$PACKAGE.$CONFIG${OPTION:+.$OPTION}=$VALUE"
|
||||
}
|
||||
|
||||
uci_set() {
|
||||
local PACKAGE="$1"
|
||||
local CONFIG="$2"
|
||||
local OPTION="$3"
|
||||
local VALUE="$4"
|
||||
|
||||
/sbin/uci set "$PACKAGE.$CONFIG.$OPTION=$TYPE"
|
||||
}
|
||||
|
||||
uci_add() {
|
||||
local PACKAGE="$1"
|
||||
local TYPE="$2"
|
||||
local CONFIG="$3"
|
||||
|
||||
/sbin/uci set "$PACKAGE.$CONFIG=$TYPE"
|
||||
}
|
||||
|
||||
uci_rename() {
|
||||
local PACKAGE="$1"
|
||||
local CONFIG="$2"
|
||||
local VALUE="$3"
|
||||
|
||||
/sbin/uci rename "$PACKAGE.$CONFIG=$VALUE"
|
||||
}
|
||||
|
||||
uci_remove() {
|
||||
local PACKAGE="$1"
|
||||
local CONFIG="$2"
|
||||
local OPTION="$3"
|
||||
|
||||
/sbin/uci del "$PACKAGE.$CONFIG${OPTION:+.$OPTION}"
|
||||
}
|
||||
|
||||
uci_commit() {
|
||||
local PACKAGE="$1"
|
||||
/sbin/uci commit $PACKAGE
|
||||
}
|
Loading…
Reference in New Issue