diff options
Diffstat (limited to 'package')
19 files changed, 269 insertions, 87 deletions
diff --git a/package/base-files/files/etc/functions.sh b/package/base-files/files/etc/functions.sh index ef28015..5ad45ec 100755 --- a/package/base-files/files/etc/functions.sh +++ b/package/base-files/files/etc/functions.sh @@ -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 diff --git a/package/base-files/files/etc/hotplug.d/iface/00-netstate b/package/base-files/files/etc/hotplug.d/iface/00-netstate index 6bf6214..f215d29 100644 --- a/package/base-files/files/etc/hotplug.d/iface/00-netstate +++ b/package/base-files/files/etc/hotplug.d/iface/00-netstate @@ -1,3 +1,3 @@ [ ifup = "$ACTION" ] && { - uci set "/var/state/network.$INTERFACE.up=1" + uci_set_state network "$INTERFACE" up 1 } diff --git a/package/base-files/files/etc/hotplug.d/iface/10-routes b/package/base-files/files/etc/hotplug.d/iface/10-routes index 7e957f7..963728f 100644 --- a/package/base-files/files/etc/hotplug.d/iface/10-routes +++ b/package/base-files/files/etc/hotplug.d/iface/10-routes @@ -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 ;; diff --git a/package/base-files/files/etc/init.d/boot b/package/base-files/files/etc/init.d/boot index b524c39..0b77447 100755 --- a/package/base-files/files/etc/init.d/boot +++ b/package/base-files/files/etc/init.d/boot @@ -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 diff --git a/package/base-files/files/lib/network/config.sh b/package/base-files/files/lib/network/config.sh index 98d6f13..611da71 100755 --- a/package/base-files/files/lib/network/config.sh +++ b/package/base-files/files/lib/network/config.sh @@ -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 diff --git a/package/base-files/files/sbin/ifdown b/package/base-files/files/sbin/ifdown index 08433c7..1f200fb 100755 --- a/package/base-files/files/sbin/ifdown +++ b/package/base-files/files/sbin/ifdown @@ -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 diff --git a/package/base-files/files/sbin/wifi b/package/base-files/files/sbin/wifi index 8b65e45..54e55b4 100755 --- a/package/base-files/files/sbin/wifi +++ b/package/base-files/files/sbin/wifi @@ -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() { diff --git a/package/base-files/files/usr/share/udhcpc/default.script b/package/base-files/files/usr/share/udhcpc/default.script index 30e84e6..147b9f1 100755 --- a/package/base-files/files/usr/share/udhcpc/default.script +++ b/package/base-files/files/usr/share/udhcpc/default.script @@ -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 diff --git a/package/dnsmasq/files/dnsmasq.init b/package/dnsmasq/files/dnsmasq.init index 4425504..62e2f51 100644 --- a/package/dnsmasq/files/dnsmasq.init +++ b/package/dnsmasq/files/dnsmasq.init @@ -231,7 +231,6 @@ dhcp_option_add() { start() { include /lib/network scan_interfaces - config_load /var/state/network config_load dhcp args="" diff --git a/package/iptables/files/firewall.init b/package/iptables/files/firewall.init index 204310a..2d8c5ed 100755 --- a/package/iptables/files/firewall.init +++ b/package/iptables/files/firewall.init @@ -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 diff --git a/package/ppp/files/etc/ppp/ip-down b/package/ppp/files/etc/ppp/ip-down index f3d63a0..30151f4 100755 --- a/package/ppp/files/etc/ppp/ip-down +++ b/package/ppp/files/etc/ppp/ip-down @@ -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 ] && { diff --git a/package/ppp/files/etc/ppp/ip-up b/package/ppp/files/etc/ppp/ip-up index a50137f..acbb599 100755 --- a/package/ppp/files/etc/ppp/ip-up +++ b/package/ppp/files/etc/ppp/ip-up @@ -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" } diff --git a/package/pptp/files/pptp.sh b/package/pptp/files/pptp.sh index f1c46c9..0743082 100644 --- a/package/pptp/files/pptp.sh +++ b/package/pptp/files/pptp.sh @@ -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 diff --git a/package/qos-scripts/files/usr/lib/qos/generate.sh b/package/qos-scripts/files/usr/lib/qos/generate.sh index 55ddf3c..04c833b 100755 --- a/package/qos-scripts/files/usr/lib/qos/generate.sh +++ b/package/qos-scripts/files/usr/lib/qos/generate.sh @@ -17,7 +17,6 @@ add_insmod() { reset_cb include /lib/network scan_interfaces - config_load /var/state/network config_get "$1" ifname )} } || { diff --git a/package/uci/Makefile b/package/uci/Makefile new file mode 100644 index 0000000..f4bd07f --- /dev/null +++ b/package/uci/Makefile @@ -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)) diff --git a/package/base-files/files/bin/uci b/package/uci/files/uci-sh/bin/uci index f89fe82..f89fe82 100755 --- a/package/base-files/files/bin/uci +++ b/package/uci/files/uci-sh/bin/uci diff --git a/package/base-files/files/lib/config/uci.awk b/package/uci/files/uci-sh/lib/config/uci.awk index 5972ad2..c560907 100644 --- a/package/base-files/files/lib/config/uci.awk +++ b/package/uci/files/uci-sh/lib/config/uci.awk @@ -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) @@ -102,7 +102,7 @@ function uci_update_config(cfg, update, \ } } line = lines[n] - + # when a command wants to set a config value for the current # section and a blank line is encountered before an option with # the same name, insert it here to maintain some coherency between @@ -128,17 +128,17 @@ function uci_update_config(cfg, update, \ flag=1 gsub("^" section ".", "", update) cfg = cfg uci_cmd2option(update) "\n" - + update = "-" section "." update - } + } if (flag!=0) cfg = cfg "\n" } - + remove = "" section = l[3] if (!length(section)) { section = "cfg" scnt - } + } scnt++ if (update == "-" section) { remove = "section" @@ -147,7 +147,7 @@ function uci_update_config(cfg, update, \ update = "" } else if (update ~ "^&" section "=") { gsub("^&" section "=", "", update) - line = uci_cmd2config(l[2],update) + line = uci_cmd2config(l[2],update) update = "" } } @@ -163,7 +163,7 @@ function uci_update_config(cfg, update, \ } if (remove == "") cfg = cfg line "\n" } - + # any new options for the last section?? if (section != "") { if (update ~ "^" section "\\.") { @@ -171,7 +171,7 @@ function uci_update_config(cfg, update, \ cfg = cfg uci_cmd2option(update) "\n" update = "-" section "." update - } + } } if (update ~ "^@") { diff --git a/package/base-files/files/lib/config/uci.sh b/package/uci/files/uci-sh/lib/config/uci.sh index 71f2048..f584832 100644 --- a/package/base-files/files/lib/config/uci.sh +++ b/package/uci/files/uci-sh/lib/config/uci.sh @@ -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" diff --git a/package/uci/files/uci/lib/config/uci.sh b/package/uci/files/uci/lib/config/uci.sh new file mode 100644 index 0000000..3a264a2 --- /dev/null +++ b/package/uci/files/uci/lib/config/uci.sh @@ -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 +} |