* luci-0.8: backport updated olsrd package
authorJo-Philipp Wich <jow@openwrt.org>
Sat, 13 Sep 2008 23:18:13 +0000 (23:18 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Sat, 13 Sep 2008 23:18:13 +0000 (23:18 +0000)
contrib/package/olsrd-luci/Makefile
contrib/package/olsrd-luci/files/etc/config/olsr [deleted file]
contrib/package/olsrd-luci/files/etc/config/olsrd [new file with mode: 0644]
contrib/package/olsrd-luci/files/etc/init.d/olsrd
contrib/package/olsrd-luci/files/lib/config/olsr.lua [deleted file]

index c492f8feeff17e3ac003680bbb59aaf6ed765eec..42a0d514b603fa5a8dcd94c4455e67d4d53e577f 100644 (file)
@@ -12,7 +12,7 @@ include $(TOPDIR)/rules.mk
 PKG_BASENAME:=olsrd
 PKG_NAME:=$(PKG_BASENAME)-luci
 PKG_VERSION:=0.5.6
-PKG_RELEASE:=2
+PKG_RELEASE:=3
 
 PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_BASENAME)-$(PKG_VERSION)
 PKG_SOURCE:=$(PKG_BASENAME)-$(PKG_VERSION).tar.bz2
@@ -36,6 +36,10 @@ define Package/olsrd-luci
        DEPENDS:=+libpthread
 endef
 
+define Package/olsrd-luci/conffiles
+/etc/config/olsrd
+endef
+
 define Package/olsrd-luci-mod-arprefresh
        $(call Package/olsrd-luci/common_info)
        MENU:=1
@@ -138,73 +142,71 @@ endef
 
 define Package/olsrd-luci/install
        $(INSTALL_DIR) $(1)/usr/sbin
-       $(INSTALL_DIR) $(1)/lib/config
        $(INSTALL_DIR) $(1)/etc/config
        $(INSTALL_DIR) $(1)/etc/init.d
        $(INSTALL_BIN) $(PKG_BUILD_DIR)/olsrd $(1)/usr/sbin/
        $(INSTALL_BIN) ./files/etc/init.d/olsrd $(1)/etc/init.d/
-       $(INSTALL_CONF) ./files/etc/config/olsr $(1)/etc/config/
-       $(INSTALL_DATA) ./files/lib/config/olsr.lua $(1)/lib/config/
+       $(INSTALL_CONF) ./files/etc/config/olsrd $(1)/etc/config/
 endef
 
 define Package/olsrd-luci-mod-arprefresh/install
        $(INSTALL_DIR) $(1)/usr/lib
-       $(INSTALL_DATA) $(PKG_BUILD_DIR)/lib/arprefresh/olsrd_arprefresh.so.* $(1)/usr/lib/
+       $(INSTALL_BIN) $(PKG_BUILD_DIR)/lib/arprefresh/olsrd_arprefresh.so.* $(1)/usr/lib/
 endef
 
 define Package/olsrd-luci-mod-dot-draw/install
        $(INSTALL_DIR) $(1)/usr/lib
-       $(INSTALL_DATA) $(PKG_BUILD_DIR)/lib/dot_draw/olsrd_dot_draw.so.* $(1)/usr/lib/
+       $(INSTALL_BIN) $(PKG_BUILD_DIR)/lib/dot_draw/olsrd_dot_draw.so.* $(1)/usr/lib/
 endef
 
 define Package/olsrd-luci-mod-bmf/install
        $(INSTALL_DIR) $(1)/usr/lib
-       $(INSTALL_DATA) $(PKG_BUILD_DIR)/lib/bmf/olsrd_bmf.so.* $(1)/usr/lib/
+       $(INSTALL_BIN) $(PKG_BUILD_DIR)/lib/bmf/olsrd_bmf.so.* $(1)/usr/lib/
 endef
 
 define Package/olsrd-luci-mod-dyn-gw/install
        $(INSTALL_DIR) $(1)/usr/lib
-       $(INSTALL_DATA) $(PKG_BUILD_DIR)/lib/dyn_gw/olsrd_dyn_gw.so.* $(1)/usr/lib/
+       $(INSTALL_BIN) $(PKG_BUILD_DIR)/lib/dyn_gw/olsrd_dyn_gw.so.* $(1)/usr/lib/
 endef
 
 define Package/olsrd-luci-mod-dyn-gw-plain/install
        $(INSTALL_DIR) $(1)/usr/lib
-       $(INSTALL_DATA) $(PKG_BUILD_DIR)/lib/dyn_gw_plain/olsrd_dyn_gw_plain.so.* $(1)/usr/lib/
+       $(INSTALL_BIN) $(PKG_BUILD_DIR)/lib/dyn_gw_plain/olsrd_dyn_gw_plain.so.* $(1)/usr/lib/
 endef
 
 define Package/olsrd-luci-mod-httpinfo/install
        $(INSTALL_DIR) $(1)/usr/lib
-       $(INSTALL_DATA) $(PKG_BUILD_DIR)/lib/httpinfo/olsrd_httpinfo.so.* $(1)/usr/lib/
+       $(INSTALL_BIN) $(PKG_BUILD_DIR)/lib/httpinfo/olsrd_httpinfo.so.* $(1)/usr/lib/
 endef
 
 define Package/olsrd-luci-mod-nameservice/install
        $(INSTALL_DIR) $(1)/usr/lib
-       $(INSTALL_DATA) $(PKG_BUILD_DIR)/lib/nameservice/olsrd_nameservice.so.* $(1)/usr/lib/
+       $(INSTALL_BIN) $(PKG_BUILD_DIR)/lib/nameservice/olsrd_nameservice.so.* $(1)/usr/lib/
 endef
 
 define Package/olsrd-luci-mod-secure/install
        $(INSTALL_DIR) $(1)/usr/lib
-       $(INSTALL_DATA) $(PKG_BUILD_DIR)/lib/secure/olsrd_secure.so.* $(1)/usr/lib/
+       $(INSTALL_BIN) $(PKG_BUILD_DIR)/lib/secure/olsrd_secure.so.* $(1)/usr/lib/
 endef
 
 define Package/olsrd-luci-mod-txtinfo/install
        $(INSTALL_DIR) $(1)/usr/lib
-       $(INSTALL_DATA) $(PKG_BUILD_DIR)/lib/txtinfo/olsrd_txtinfo.so.* $(1)/usr/lib/
+       $(INSTALL_BIN) $(PKG_BUILD_DIR)/lib/txtinfo/olsrd_txtinfo.so.* $(1)/usr/lib/
 endef
 
 define Package/olsrd-luci-mod-pgraph/install
        $(INSTALL_DIR) $(1)/usr/lib
-       $(INSTALL_DATA) $(PKG_BUILD_DIR)/lib/pgraph/olsrd_pgraph.so.* $(1)/usr/lib/
+       $(INSTALL_BIN) $(PKG_BUILD_DIR)/lib/pgraph/olsrd_pgraph.so.* $(1)/usr/lib/
 endef
 
 define Package/olsrd-luci-mod-quagga/install
        $(INSTALL_DIR) $(1)/usr/lib
-       $(INSTALL_DATA) $(PKG_BUILD_DIR)/lib/quagga/olsrd_quagga.so.* $(1)/usr/lib/
+       $(INSTALL_BIN) $(PKG_BUILD_DIR)/lib/quagga/olsrd_quagga.so.* $(1)/usr/lib/
 endef
 
 define Package/olsrd-luci-mod-tas/install
        $(INSTALL_DIR) $(1)/usr/lib
-       $(INSTALL_DATA) $(PKG_BUILD_DIR)/lib/tas/olsrd_tas.so.* $(1)/usr/lib/
+       $(INSTALL_BIN) $(PKG_BUILD_DIR)/lib/tas/olsrd_tas.so.* $(1)/usr/lib/
 endef
 
 
diff --git a/contrib/package/olsrd-luci/files/etc/config/olsr b/contrib/package/olsrd-luci/files/etc/config/olsr
deleted file mode 100644 (file)
index 5361b70..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-config 'olsr' 'general'
-        option 'DebugLevel' '0'
-        option 'IpVersion' '4'
-        option 'AllowNoInt' 'yes'
-        option 'Pollrate' '0.025'
-        option 'TcRedundancy' '2'
-        option 'MprCoverage' '7'
-        option 'LinkQualityFishEye' '1'
-        option 'LinkQualityWinSize' '100'
-        option 'LinkQualityDijkstraLimit' '0 9.0'
-        option 'LinkQualityLevel' '2'
-        option 'UseHysteresis' 'no'
-
-config 'LoadPlugin' 'dyn_gw'
-        option 'Library' 'olsrd_dyn_gw.so.0.4'
-
-config 'LoadPlugin' 'nameservice'
-        option 'Library' 'olsrd_nameservice.so.0.3'
-        option 'suffix' '.olsr'
-        option 'latlon_infile' '/tmp/latlon.txt'
-        option 'hosts_file' '/var/etc/hosts'
-        option 'name' 'luci-node'
-
-config 'LoadPlugin' 'txtinfo'
-        option 'Library' 'olsrd_txtinfo.so.0.1'
-        option 'Accept' '127.0.0.1'
-
-config 'Interface'
-        option 'HelloInterval' '6.0'
-        option 'MidValidityTime' '324.0'
-        option 'TcInterval' '4.0'
-        option 'HnaValidityTime' '108.0'
-        option 'HelloValidityTime' '108.0'
-        option 'TcValidityTime' '324.0'
-        option 'HnaInterval' '18.0'
-        option 'MidInterval' '18.0'
-        option 'Interface' 'br-lan'
-        
-config 'ipc' 'IpcConnect'
-       option 'MaxConnections' '0'
-       option 'Host' '127.0.0.1 10.0.0.5'
-       option 'Net' '192.168.1.0 255.255.255.0 10.0.0.0 255.0.0.0'
diff --git a/contrib/package/olsrd-luci/files/etc/config/olsrd b/contrib/package/olsrd-luci/files/etc/config/olsrd
new file mode 100644 (file)
index 0000000..2e0e4e6
--- /dev/null
@@ -0,0 +1,22 @@
+config 'olsrd'
+       option 'IpVersion' '4'
+       option 'FIBMetric' 'flat'
+       option 'LinkQualityAlgorithm' 'etx_ff'
+
+config 'Interface'
+       option 'interface' 'ff'
+       option 'Ip4Broadcast' '255.255.255.255'
+
+config 'LoadPlugin'
+       option 'library' 'olsrd_dyn_gw.so.0.4'
+       option 'Ping' '141.1.1.1'
+#      option 'HNA' '192.168.80.0 255.255.255.0'
+       option 'Interval' '60'
+
+config 'LoadPlugin'
+       option 'library' 'olsrd_nameservice.so.0.3'
+       option 'name' 'luci-node.olsr'
+
+config 'LoadPlugin'
+       option 'library' 'olsrd_txtinfo.so.0.1'
+       option 'accept' '127.0.0.1'
index 04c3a757873f0cf2131d09ea0d4882afc49542a9..54f5502bfcafd1c487fbd34e82db1f0dd559f627 100755 (executable)
 #!/bin/sh /etc/rc.common
+# Copyright (C) 2008  Alina Friedrichsen <x-alina@gmx.net>
+# Special thanks to bittorf wireless ))
 START=50
 
 BIN=/usr/sbin/olsrd
 CONF=/var/etc/olsrd.conf
-DEFAULT=/etc/default/olsrd
 PID=/var/run/olsrd.pid
 
-start() {
-       ### load defaults
-       [ -f $DEFAULT ] && . $DEFAULT
+OLSRD_OLSRD_SCHEMA='ignore:internal config_file:internal DebugLevel=0 IpVersion=4 AllowNoInt:bool=1 Pollrate=0.025 TcRedundancy=2 MprCoverage=3 LinkQualityFishEye=1 LinkQualityWinSize=100 LinkQualityDijkstraLimit=0+9.0 LinkQualityLevel=2 UseHysteresis:bool=0 FIBMetric=flat ClearScreen:bool=1 Willingness=3 LinkQualityAging=0.1 LinkQualityAlgorithm=etx_fpm'
+OLSRD_IPCCONNECT_SCHEMA='ignore:internal Host:list Net:list2'
+OLSRD_LOADPLUGIN_SCHEMA='ignore:internal library:internal Host:list Net:list2 Ping:list redistribute:list NonOlsrIf:list name:list lat lon latlon_infile HNA:list2 hosts:list2'
+OLSRD_INTERFACE_SCHEMA='ignore:internal interface:internal AutoDetectChanges:bool Ip4Broadcast=255.255.255.255 HelloInterval=2.0 HelloValidityTime=40.0 TcInterval=5.0 TcValidityTime=100.0 MidInterval=18.0 MidValidityTime=324.0 HnaInterval=18.0 HnaValidityTime=108.0'
+
+T='    '
+N='
+'
+
+validate_varname() {
+       local varname=$1
+       [ -z "$varname" -o "$varname" != "${varname%%[!A-Za-z0-9_]*}" ] && return 1
+       return 0
+}
+
+validate_ifname() {
+       local ifname=$1
+       [ -z "$ifname" -o "$ifname" != "${ifname%%[!A-Za-z0-9.:_-]*}" ] && return 1
+       return 0
+}
+
+validate_olsrd_option() {
+       local str=$1
+       [ -z "$str" -o "$str" != "${str%%[!     0-9A-Za-z./:_-]*}" ] && return 1
+       return 0
+}
+
+get_ifname() {
+       IFNAME=
+       local interface=$1
+       validate_varname "$interface" || return 1
+       local ifname
+
+       config_get ifname "$interface" ifname
+       validate_ifname "$ifname" || return 1
+       IFNAME=$ifname
+
+       return 0
+}
+
+system_config() {
+       local cfg=$1
+       local cfgt
+       local hostname
+       local latlon
+
+       config_get cfgt "$cfg" TYPE
+
+       if [ "$cfgt" = "system" ]; then
+               config_get hostname "$cfg" hostname
+               hostname=${hostname:-OpenWrt}
+               SYSTEM_HOSTNAME=$hostname
+       fi
+
+       if [ -z "$SYSTEM_LAT" -o -z "$SYSTEM_LON" ]; then
+               config_get latlon "$cfg" latlon
+               IFS=" ${T}${N},"
+               set -- $latlon
+               unset IFS
+               SYSTEM_LAT=$1
+               SYSTEM_LON=$2
+       fi
+}
+
+olsrd_find_config_file() {
+       local cfg=$1
+       validate_varname "$cfg" || return 0
+
+       config_get_bool ignore "$cfg" ignore 0
+       [ "$ignore" -ne 0 ] && return 0
+       config_get OLSRD_CONFIG_FILE "$cfg" config_file
+
+       return 0
+}
+
+warning_invalid_value() {
+       local package=$1
+       validate_varname "$package" || package=
+       local config=$2
+       validate_varname "$config" || config=
+       local option=$3
+       validate_varname "$option" || option=
+
+       echo -n "Warning: Invalid value" 1>&2
+
+       if [ -n "$package" -a -n "$config" ]; then
+               echo -n " in option '$package.$config${option:+.}$option'" 1>&2
+       fi
+
+       echo ", skipped" 1>&2
+
+       return 0
+}
+
+olsrd_write_option() {
+       local param=$1
+       local cfg=$2
+       validate_varname "$cfg" || return 1
+       local option=$3
+       validate_varname "$option" || return 1
+       local value=$4
+       local option_type=$5
+
+       if [ "$option_type" = bool ]; then
+               case "$value" in
+                       1|on|true|enabled|yes) value=yes;;
+                       0|off|false|disabled|no) value=no;;
+                       *) warning_invalid_value olsrd "$cfg" "$option"; return 1;;
+               esac
+       fi
+
+       if ! validate_olsrd_option "$value"; then
+               warning_invalid_value olsrd "$cfg" "$option"
+               return 1
+       fi
+
+       if [ "$value" != "${value%%[G-Zg-z_-]*}" ]; then
+               if [ "$value" != "yes" -a "$value" != "no" ]; then
+                       value="\"$value\""
+               fi
+       fi
+
+       echo -n "${N}$param$option $value"
+
+       return 0
+}
+
+olsrd_write_plparam() {
+       local param=$1
+       local cfg=$2
+       validate_varname "$cfg" || return 1
+       local option=$3
+       validate_varname "$option" || return 1
+       local value=$4
+       local option_type=$5
+       local _option
+
+       if [ "$option_type" = bool ]; then
+               case "$value" in
+                       1|on|true|enabled|yes) value=yes;;
+                       0|off|false|disabled|no) value=no;;
+                       *) warning_invalid_value olsrd "$cfg" "$option"; return 1;;
+               esac
+       fi
+
+       if ! validate_olsrd_option "$value"; then
+               warning_invalid_value olsrd "$cfg" "$option"
+               return 1
+       fi
+
+       IFS='-_'
+       set -- $option
+       option="$*"
+       unset IFS
+       _option="$option"
+       if [ "$option" = 'hosts' ]; then
+               set -- $value
+               option=$1
+               shift
+               value="$*"
+       fi
+
+       echo -n "${N}${param}PlParam \"$option\" \"$value\""
+
+       return 0
+}
+
+config_update_schema() {
+       unset IFS
+       local schema_varname=$1
+       validate_varname "$schema_varname" || return 1
+       local command=$2
+       validate_varname "$command" || return 1
+       local option=$3
+       validate_varname "$option" || return 1
+       local value=$4
+       local schema
+       local cur_option
+
+       case "$varname" in
+               *_LENGTH) return 0;;
+               *_ITEM*) return 0;;
+       esac
+
+       eval "export -n -- \"schema=\${$schema_varname}\""
+
+       for cur_option in $schema; do
+               [ "${cur_option%%[:=]*}" = "$option" ] && return 0
+       done
+
+       if [ "$command" = list ]; then
+               set -- $value
+               if [ "$#" -ge "3" ]; then
+                       schema_entry="$option:list3"
+               elif [ "$#" -ge "2" ]; then
+                       schema_entry="$option:list2"
+               else
+                       schema_entry="$option:list"
+               fi
+       else
+               schema_entry="$option"
+       fi
+
+       append "$schema_varname" "$schema_entry"
+
+       return 0
+}
+
+config_write_options() {
+       unset IFS
+       local schema=$1
+       local cfg=$2
+       validate_varname "$cfg" || return 1
+       local write_func=$3
+       [ -z "$write_func" ] && output_func=echo
+       local write_param=$4
+       local schema_entry
+       local option
+       local option_length
+       local option_type
+       local default
+       local value
+       local list_size
+       local list_item
+       local list_value
+       local i
+       local position
+
+       for schema_entry in $schema; do
+               default=${schema_entry#*[=]}
+               [ "$default" = "$schema_entry" ] && default=
+               option=${schema_entry%%[=]*}
+               IFS=':'
+               set -- $option
+               unset IFS
+               option=$1
+               option_type=$2
+               validate_varname "$option" || continue
+               [ -z "$option_type" ] || validate_varname "$option_type" || continue
+               [ "$option_type" = internal ] && continue
+               config_get value "$cfg" "$option"
+
+               if [ -z "$value" ]; then
+                       IFS='+'
+                       set -- $default
+                       unset IFS
+                       value=$*
+               elif [ "$value" = '-' -a -n "$default" ]; then
+                       continue
+               fi
+
+               [ -z "$value" ] && continue
+
+               case "$option_type" in
+                       list) list_size=1;;
+                       list2) list_size=2;;
+                       list3) list_size=3;;
+                       *) list_size=0;;
+               esac
+
+               if [ "$list_size" -gt 0 ]; then
+                       config_get option_length "$cfg" "${option}_LENGTH"
+                       if [ -n "$option_length" ]; then
+                               i=1
+                               while [ "$i" -le "$option_length" ]; do
+                                       config_get list_value "$cfg" "${option}_ITEM$i"
+                                       "$write_func" "$write_param" "$cfg" "$option" "$list_value" "$option_type" || break
+                                       i=$((i + 1))
+                               done
+                       else
+                               list_value=
+                               i=0
+                               for list_item in $value; do
+                                       append "list_value" "$list_item"
+                                       i=$((i + 1))
+                                       position=$((i % list_size))
+                                       if [ "$position" -eq 0 ]; then
+                                               "$write_func" "$write_param" "$cfg" "$option" "$list_value" "$option_type" || break
+                                               list_value=
+                                       fi
+                               done
+                               [ "$position" -ne 0 ] && "$write_func" "$write_param" "$cfg" "$option" "$list_value" "$option_type"
+                       fi
+               else
+                       "$write_func" "$write_param" "$cfg" "$option" "$value" "$option_type"
+               fi
+       done
+
+       return 0
+}
+
+olsrd_write_olsrd() {
+       local cfg=$1
+       validate_varname "$cfg" || return 0
+       local ignore
+
+       config_get_bool ignore "$cfg" ignore 0
+       [ "$ignore" -ne 0 ] && return 0
+
+       [ "$OLSRD_COUNT" -gt 0 ] && return 0
+
+       config_write_options "$OLSRD_OLSRD_SCHEMA" "$cfg" olsrd_write_option
+       echo
+       OLSRD_COUNT=$((OLSRD_COUNT + 1))
+
+       return 0
+}
+
+olsrd_write_ipcconnect() {
+       local cfg=$1
+       validate_varname "$cfg" || return 0
+       local ignore
+
+       config_get_bool ignore "$cfg" ignore 0
+       [ "$ignore" -ne 0 ] && return 0
+
+       [ "$IPCCONNECT_COUNT" -gt 0 ] && return 0
+
+       echo -n "${N}IpcConnect${N}{"
+       config_write_options "$OLSRD_IPCCONNECT_SCHEMA" "$cfg" olsrd_write_option "${T}"
+       echo "${N}}"
+       IPCCONNECT_COUNT=$((IPCCONNECT_COUNT + 1))
+
+       return 0
+}
+
+olsrd_write_hna4() {
+       local cfg=$1
+       validate_varname "$cfg" || return 0
+       local ignore
+
+       config_get_bool ignore "$cfg" ignore 0
+       [ "$ignore" -ne 0 ] && return 0
+
+       config_get netaddr "$cfg" netaddr
+       if ! validate_olsrd_option "$netaddr"; then
+               warning_invalid_value olsrd "$cfg" "netaddr"
+               return 0
+       fi
+
+       config_get netmask "$cfg" netmask
+       if ! validate_olsrd_option "$netmask"; then
+               warning_invalid_value olsrd "$cfg" "netmask"
+               return 0
+       fi
+
+       [ "$HNA4_COUNT" -le 0 ] && echo -n "${N}Hna4${N}{"
+       echo -n "${N}${T}$netaddr $netmask"
+       HNA4_COUNT=$((HNA4_COUNT + 1))
+
+       return 0
+}
+
+olsrd_write_hna6() {
+       local cfg=$1
+       validate_varname "$cfg" || return 0
+       local ignore
+
+       config_get_bool ignore "$cfg" ignore 0
+       [ "$ignore" -ne 0 ] && return 0
+
+       config_get netaddr "$cfg" netaddr
+       if ! validate_olsrd_option "$netaddr"; then
+               warning_invalid_value olsrd "$cfg" "netaddr"
+               return 0
+       fi
+
+       config_get prefix "$cfg" prefix
+       if ! validate_olsrd_option "$prefix"; then
+               warning_invalid_value olsrd "$cfg" "prefix"
+               return 0
+       fi
+
+       [ "$HNA6_COUNT" -le 0 ] && echo -n "${N}Hna6${N}{"
+       echo -n "${N}${T}$netaddr $prefix"
+       HNA6_COUNT=$((HNA6_COUNT + 1))
+
+       return 0
+}
+
+olsrd_write_loadplugin() {
+       local cfg=$1
+       validate_varname "$cfg" || return 0
+       local ignore
+       local name
+       local suffix
+       local lat
+       local lon
+       local latlon_infile
 
-       ### generate config
-       mkdir -p ${CONF%/*}
-       lua /lib/config/olsr.lua > $CONF
+       config_get_bool ignore "$cfg" ignore 0
+       [ "$ignore" -ne 0 ] && return 0
 
-       ### check for running instance (start-stop-daemon is too stupid to do this)
+       config_get library "$cfg" library
+       if ! validate_olsrd_option "$library"; then
+               warning_invalid_value olsrd "$cfg" "library"
+               return 0
+       fi
+       if ! [ -x "/lib/$library" -o -x "/usr/lib/$library" -o -x "/usr/local/lib/$library" ]; then
+               echo "Warning: Plugin library '$library' not found, skipped" 1>&2
+               return 0
+       fi
+
+       case "$library" in
+               olsrd_nameservice.*)
+                       config_get name "$cfg" name
+                       [ -z "$name" ] && config_set "$cfg" name $SYSTEM_HOSTNAME
+
+                       config_get suffix "$cfg" suffix
+                       [ -z "$suffix" ] && config_set "$cfg" suffix '.olsr'
+
+                       config_get lat "$cfg" lat
+                       config_get lon "$cfg" lon
+                       config_get latlon_infile "$cfg" latlon_infile
+                       if [ \( -z "$lat" -o -z "$lat" \) -a -z "$latlon_infile" ]; then
+                               if [ -f '/var/run/latlon.txt' ]; then
+                                       config_set "$cfg" lat ''
+                                       config_set "$cfg" lon ''
+                                       config_set "$cfg" latlon_infile '/var/run/latlon.txt'
+                               else
+                                       config_set "$cfg" lat "$SYSTEM_LAT"
+                                       config_set "$cfg" lon "$SYSTEM_LON"
+                               fi
+                       fi
+
+                       config_get latlon_file "$cfg" latlon_file
+                       [ -z "$latlon_file" ] && config_set "$cfg" latlon_file '/var/run/latlon.js'
+               ;;
+       esac
+
+       echo -n "${N}LoadPlugin \"$library\"${N}{"
+       config_write_options "$OLSRD_LOADPLUGIN_SCHEMA" "$cfg" olsrd_write_plparam "${T}"
+       echo "${N}}"
+
+       return 0
+}
+
+olsrd_write_interface() {
+       local cfg=$1
+       validate_varname "$cfg" || return 0
+       local ignore
+       local interfaces
+       local interface
+       local ifnames
+
+       config_get_bool ignore "$cfg" ignore 0
+       [ "$ignore" -ne 0 ] && return 0
+
+       ifnames=
+       config_get interfaces "$cfg" interface
+       for interface in $interfaces; do
+               if validate_varname "$interface"; then
+                       if get_ifname "$interface"; then
+                               ifnames="$ifnames \"$IFNAME\""
+                       else
+                               echo "Warning: Interface '$interface' not found, skipped" 1>&2
+                       fi
+               else
+                       warning_invalid_value olsrd "$cfg" "interface"
+               fi
+       done
+
+       [ -z "$ifnames" ] && return 0
+
+       echo -n "${N}Interface$ifnames${N}{"
+       config_write_options "$OLSRD_INTERFACE_SCHEMA" "$cfg" olsrd_write_option "${T}"
+       echo "${N}}"
+       INTERFACES_COUNT=$((INTERFACES_COUNT + 1))
+
+       return 0
+}
+
+olsrd_update_schema() {
+       local command="$1"
+       validate_varname "$command" || return 0
+       local varname="$2"
+       validate_varname "$varname" || return 0
+       local value="$3"
+       local cfg="$CONFIG_SECTION"
+       local cfgt
+       local cur_varname
+
+       config_get cfgt "$cfg" TYPE
+       case "$cfgt" in
+               olsrd) config_update_schema OLSRD_OLSRD_SCHEMA "$command" "$varname" "$value";;
+               IpcConnect) config_update_schema OLSRD_IPCCONNECT_SCHEMA "$command" "$varname" "$value";;
+               LoadPlugin) config_update_schema OLSRD_LOADPLUGIN_SCHEMA "$command" "$varname" "$value";;
+               Interface) config_update_schema OLSRD_INTERFACE_SCHEMA "$command" "$varname" "$value";;
+       esac
+
+       return 0
+}
+
+olsrd_write_config() {
+       OLSRD_COUNT=0
+       config_foreach olsrd_write_olsrd olsrd
+       IPCCONNECT_COUNT=0
+       config_foreach olsrd_write_ipcconnect IpcConnect
+       HNA4_COUNT=0
+       config_foreach olsrd_write_hna4 Hna4
+       [ "$HNA4_COUNT" -gt 0 ] && echo "${N}}"
+       HNA6_COUNT=0
+       config_foreach olsrd_write_hna6 Hna6
+       [ "$HNA6_COUNT" -gt 0 ] && echo "${N}}"
+       config_foreach olsrd_write_loadplugin LoadPlugin
+       INTERFACES_COUNT=0
+       config_foreach olsrd_write_interface Interface
+       echo
+
+       return 0
+}
+
+start() {
+       ### check for running instance
        if [ -s $PID ]; then
                if kill -0 $(cat $PID) 2>&-; then
                        echo "there is already a running instance ($(cat $PID))"
-                       exit 1
+                       return 1
                fi
        fi
+       
+       SYSTEM_HOSTNAME=
+       SYSTEM_LAT=
+       SYSTEM_LON=
+       config_load system
+       config_foreach system_config system
+
+       option_cb() {
+               olsrd_update_schema "option" "$@"
+       }
+
+       list_cb() {
+               olsrd_update_schema "list" "$@"
+       }
+
+       include /lib/network
+       scan_interfaces
+       config_load olsrd
+       reset_cb
+
+       OLSRD_CONFIG_FILE=
+       config_foreach olsrd_find_config_file olsrd
+
+       if [ -z "$OLSRD_CONFIG_FILE" ]; then
+               ### generate config
+               mkdir -p ${CONF%/*}
+               olsrd_write_config > $CONF
+               if [ "$INTERFACES_COUNT" -gt 0 -a "$OLSRD_COUNT" -gt 0 ]; then
+                       OLSRD_CONFIG_FILE=$CONF
+               fi
+       fi
+
+       [ -z "$OLSRD_CONFIG_FILE" ] && return 1
 
        ### start olsrd
-       start-stop-daemon -b -m -p $PID -x $BIN -S -- -f $CONF -nofork $OPTIONS
+       start-stop-daemon -b -m -p $PID -x $BIN -S -- -f $CONF -nofork
 }
 
 stop() {
diff --git a/contrib/package/olsrd-luci/files/lib/config/olsr.lua b/contrib/package/olsrd-luci/files/lib/config/olsr.lua
deleted file mode 100644 (file)
index 1afd9a0..0000000
+++ /dev/null
@@ -1,145 +0,0 @@
-#!/usr/bin/lua
-
---[[
-
-OLSRd configuration generator
-(c) 2008 Freifunk Leipzig / Jo-Philipp Wich <xm@leipzig.freifunk.net>
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
-        http://www.apache.org/licenses/LICENSE-2.0
-
-$Id$
-
-]]--
-
-require("luci.fs")
-require("luci.util")
-require("luci.model.uci")
-
-local uci  = luci.model.uci.cursor()
-local conf = uci:get_all("olsr")
-
-local function _value(val)
-       if val:match("^[0-9%. \t]+$") or val == "yes" or val == "no" then
-               return val
-       else
-               return string.format( '"%s"', val )
-       end
-end
-
-local function _section(sect,sval,parstr)
-       local rv  = ""
-       local pad = ""
-
-       if sval then
-               if sval == "Interface" then
-                       rv = string.format( 'Interface "%s"\n{\n', uci:get("network",conf[sect][sval],"ifname") )
-               else
-                       rv  = string.format( '%s "%s"\n{\n', conf[sect][".type"], conf[sect][sval] )
-               end
-               pad = "\t"
-       end
-
-       for k, v in luci.util.spairs(conf[sect]) do
-               if k:sub(1,1) ~= '.' and k ~= sval then
-                       if parstr then
-                               rv = rv .. string.format(
-                                       '%s%s "%s"\t"%s"\n',
-                                       pad, parstr,
-                                       k:gsub( "_", "-" ),     -- XXX: find a better solution for this
-                                       v
-                               )
-                       else
-                               rv = rv .. string.format(
-                                       '%s%s\t%s\n',
-                                       pad, k, _value(v)
-                               )
-                       end
-               end
-       end
-
-       if sval then
-               rv = rv .. "}\n"
-       end
-
-       return rv
-end
-
-local function _hna(sval)
-       local rv = string.format( "%s\n{\n", sval )
-
-       for k, v in luci.util.spairs(conf) do
-               if conf[k][".type"] == sval and conf[k].NetAddr and conf[k].Prefix then
-                       rv = rv .. string.format(
-                               "\t%s\t%s\n",
-                               conf[k].NetAddr,
-                               conf[k].Prefix
-                       )
-               end
-       end
-
-       return rv .. "}\n"
-end
-
-local function _ipc(sval)
-       local rv = string.format( "%s\n{\n", sval )
-
-       for k, v in luci.util.spairs(conf[sval]) do
-               if k:sub(1,1) ~= "." then
-                       local vals = luci.util.split(v, "%s+", nil, true)
-
-                       if k == "Net" then
-                               for i = 1,#vals,2 do
-                                       rv = rv .. string.format(
-                                               "\tNet\t%s\t%s\n",
-                                               vals[i], vals[i+1]
-                                       )
-                               end
-                       elseif k == "Host" then
-                               for i, v in ipairs(vals) do
-                                       rv = rv .. string.format(
-                                               "\t%s\t%s\n",
-                                               k, vals[i]
-                                       )
-                               end
-                       else
-                               rv = rv .. string.format(
-                                       "\t%s\t%s\n",
-                                       k, v
-                               )
-                       end
-               end
-       end
-
-       return rv .. "}\n"
-end
-
-
--- general config section
-print( _section("general") )
-
--- plugin config sections
-for k, v in luci.util.spairs(conf) do
-       if conf[k][".type"] == "LoadPlugin" then
-               if v.Library and luci.fs.access("/usr/lib/"..v.Library) then
-                       print( _section( k, "Library", "PlParam" ) )
-               end
-       end
-end
-
--- interface config sections
-for k, v in luci.util.spairs(conf) do
-       if conf[k][".type"] == "Interface" then
-               print( _section( k, "Interface" ) )
-       end
-end
-
--- write Hna4, Hna6 sections
-print( _hna("Hna4") )
-print( _hna("Hna6") )
-
--- write IpcConnect section
-print( _ipc("IpcConnect") )