Instead of requiring a pre-existing config, the patch
will create one from UCI settings (when enabled):

config ddns
       option enabled 0
       option interface wan
       option program ez-ipupdate
       option service zoneedit
       option username myname
       option password mypassword
       option hostname mydomain.com       

You may also still use a specific configuration file:

config ddns
       option interface wan
       option program ez-ipupdate
       option config /etc/ez-ipupdate.conf

The "program" option is required, and only supports ez-ipupdate in this pkg,
but the ddns UCI config may be used for other similar programs just the same.
The "interface" is also required and multiple ddns blocks with different
interfaces/settings are possible. 

Signed-off-by: David Bird <[EMAIL PROTECTED]>

Index: net/ez-ipupdate/files/ez-ipupdate.hotplug
===================================================================
--- net/ez-ipupdate/files/ez-ipupdate.hotplug   (revision 11362)
+++ net/ez-ipupdate/files/ez-ipupdate.hotplug   (working copy)
@@ -1,14 +1,76 @@
 NAME=ez-ipupdate
-CONFIG=/etc/$NAME.conf
 COMMAND=/usr/sbin/$NAME
 
-[ "$ACTION" = "ifup" -a "$INTERFACE" = "wan" ] && {
-        [ -x $COMMAND ] && [ -r $CONFIG ] && {
-                               include /lib/network
-                               scan_interfaces
-                               
-                               config_get ifname wan ifname 
-                               [ -n "$ifname" ] && \
-                       $COMMAND -c $CONFIG -i $ifname 2>&1 | logger -t $NAME
-        } &
-}
+case "$ACTION" in
+    ifup|ifdown)
+       cleanup() {
+           [ -e $1 ] && {
+               kill -9 $(cat $1)
+               rm $1
+           }
+       }
+
+       ddns() {
+           local cfg="$1"
+           config_get program $cfg program
+           [ "$program" = "$NAME" ] && {
+               config_get interface $cfg interface
+               [ "$interface" = "$INTERFACE" ] && {
+                   config_get dev "$INTERFACE" ifname
+
+                   config_get enabled $cfg enabled
+                   enabled=${enabled:-1}
+
+                   config_get pidfile $cfg pidfile
+                   pidfile=${pidfile:-/var/run/$NAME-$dev.pid}
+                           
+                   case "$ACTION" in
+                       ifdown)
+                           cleanup $pidfile
+                           ;;
+                       *)
+                           case "$enabled" in
+                               1|yes|true)
+                                   [ ! -e $pidfile ] && {
+                                       config_get cache $cfg cache
+                                       [ -z "$cache" ] && 
cache=/tmp/$NAME-$dev.cache
+                                       
+                                       config_get config $cfg config
+                                       [ -z "$config" ] && {
+                                           config=/var/run/$NAME-$dev.conf
+                                           config_get service  $cfg service
+                                           config_get username $cfg username
+                                           config_get password $cfg password
+                                           config_get hostname $cfg hostname
+                                           service=${service:-"dyndns"}
+                                           cat > $config <<EOF
+service-type=$service
+user=$username:$password
+host=$hostname
+cache-file=$cache
+pid-file=$pidfile
+interface=$dev
+quiet
+EOF
+                                       }
+                                       
+                                       $COMMAND -d -c $config 2>&1 | logger -t 
$NAME &
+                                   }
+                                   ;;
+                               *)
+                                   cleanup $pidfile
+                                   ;;
+                           esac
+                   esac
+               }
+           }
+       }
+       
+       
+       include /lib/network
+       scan_interfaces
+       config_load ddns
+       
+       config_foreach ddns ddns
+       ;;
+esac
Index: net/ez-ipupdate/files/ez-ipupdate.conf
===================================================================
--- net/ez-ipupdate/files/ez-ipupdate.conf      (revision 11362)
+++ net/ez-ipupdate/files/ez-ipupdate.conf      (working copy)
@@ -1,8 +0,0 @@
-service-type=zoneedit
-user=myname:mypassword
-host=mydomain.com
-quiet
-
-# Do not change the lines below
-cache-file=/tmp/ez-ipupdate.cache
-pid-file=/var/run/ez-ipupdate.pid
Index: net/ez-ipupdate/files/ez-ipupdate.config
===================================================================
--- net/ez-ipupdate/files/ez-ipupdate.config    (revision 0)
+++ net/ez-ipupdate/files/ez-ipupdate.config    (revision 0)
@@ -0,0 +1,14 @@
+
+config ddns
+       option enabled 0
+       option interface wan
+       option program ez-ipupdate
+       option service zoneedit
+       option username myname
+       option password mypassword
+       option hostname mydomain.com       
+
+# config ddns
+#       option interface wan
+#       option program ez-ipupdate
+#       option config /etc/ez-ipupdate.conf
Index: net/ez-ipupdate/Makefile
===================================================================
--- net/ez-ipupdate/Makefile    (revision 11362)
+++ net/ez-ipupdate/Makefile    (working copy)
@@ -28,10 +28,6 @@
   URL:=http://ez-ipupdate.com/
 endef
 
-define Package/ez-ipupdate/conffiles
-/etc/ez-ipupdate.conf
-endef
-
 # uses GNU configure
 
 define Build/Compile
@@ -41,8 +37,8 @@
 define Package/ez-ipupdate/install
        $(INSTALL_DIR) $(1)/usr/sbin
        $(INSTALL_BIN) $(PKG_BUILD_DIR)/ez-ipupdate $(1)/usr/sbin/
-       $(INSTALL_DIR) $(1)/etc
-       $(INSTALL_CONF) ./files/ez-ipupdate.conf $(1)/etc/
+       $(INSTALL_DIR) $(1)/etc/config/
+       $(INSTALL_CONF) ./files/ez-ipupdate.config $(1)/etc/config/ddns
        $(INSTALL_DIR) $(1)/etc/hotplug.d/iface
        $(INSTALL_BIN) ./files/ez-ipupdate.hotplug 
$(1)/etc/hotplug.d/iface/30-ez-ipupdate
 endef


_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
http://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel

Reply via email to