This patch adds combined uci support for etherwake and wol.
It is similar to the uci support currently only in the wol package.

Package "uci-etherwake" adds uci support for etherwake (and also
busybox's ether-wake). The uci settings are used by script
/bin/uci-etherwake. Package "uci-wol" adds the same for wol.
Package "uci-wakeonlan" adds uci support for defining wol targets, that
can be waked up either by etherwake or wol. Targets can also be waked up
on system boot via init script.

These packages, etherwake and wol are moved into a separate submenu.

Used in production with recent trunk on WRT350Nv2 (Marvell Orion) and
with Kamikaze 8.09.1 on WRT54G v2.2

Signed-off-by: Matthias Buecher <m...@maddes.net>

Index: net/etherwake/Makefile
===================================================================
--- net/etherwake/Makefile      (revision 17017)
+++ net/etherwake/Makefile      (working copy)
@@ -1,8 +1,9 @@
 #
-# Copyright (C) 2007 OpenWrt.org
+# Copyright (C) 2007-2009 OpenWrt.org
 #
 # This is free software, licensed under the GNU General Public License v2.
 # See /LICENSE for more information.
+#
 
 include $(TOPDIR)/rules.mk
 
@@ -21,7 +22,8 @@
 define Package/etherwake
   SECTION:=net
   CATEGORY:=Network
-  TITLE:=A little tool to send magic Wake-on-LAN packets
+  SUBMENU:=Wake-On-LAN
+  TITLE:=WoL client for magic packets via ethernet frames
   URL:=http://ftp.debian.org/debian/pool/main/e/etherwake
 endef
 
Index: net/wol/Makefile
===================================================================
--- net/wol/Makefile    (revision 17017)
+++ net/wol/Makefile    (working copy)
@@ -1,5 +1,5 @@
 # 
-# Copyright (C) 2007 OpenWrt.org
+# Copyright (C) 2007-2009 OpenWrt.org
 #
 # This is free software, licensed under the GNU General Public License v2.
 # See /LICENSE for more information.
@@ -20,7 +20,8 @@
 define Package/wol
   SECTION:=net
   CATEGORY:=Network
-  TITLE:=Wake On LAN client
+  SUBMENU:=Wake-On-LAN
+  TITLE:=WoL client for magic packets via udp
   URL:=http://ahh.sourceforge.net/wol/
 endef
 
Index: net/uci-etherwake/Makefile
===================================================================
--- net/uci-etherwake/Makefile  (revision 0)
+++ net/uci-etherwake/Makefile  (revision 0)
@@ -0,0 +1,47 @@
+#
+# Copyright (C) 2009 OpenWrt.org
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=uci-etherwake
+PKG_VERSION:=0.9
+PKG_RELEASE:=1
+
+PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/uci-etherwake
+  SECTION:=net
+  CATEGORY:=Network
+  SUBMENU:=Wake-On-LAN
+  DEPENDS:=+uci-wakeonlan
+  TITLE:=uci support for etherwake and also busybox's ether-wake
+  PKGARCH:=all
+endef
+
+define Package/uci-etherwake/description
+       You can define system defaults via uci.
+       The script uci-etherwake uses these defaults for calling etherwake.
+       No more need to remember which interface to use or if broadcasting is 
necessary.
+       Also supports sudo, so that non-root users can send magic packets
+       via ethernet frames too.
+endef
+
+define Build/Compile
+endef
+
+define Package/uci-etherwake/install
+       $(INSTALL_DIR) $(1)/bin
+       $(INSTALL_BIN) files/bin/$(PKG_NAME) $(1)/bin/
+       $(INSTALL_DIR) $(1)/etc/config
+       $(INSTALL_DATA) files/etc/config/$(PKG_NAME) $(1)/etc/config/
+       $(INSTALL_DIR) $(1)/lib/uci-wakeonlan
+       $(INSTALL_DATA) files/lib/uci-wakeonlan/$(PKG_NAME).sh 
$(1)/lib/uci-wakeonlan/
+endef
+
+$(eval $(call BuildPackage,uci-etherwake))
Index: net/uci-etherwake/files/etc/config/uci-etherwake
===================================================================
--- net/uci-etherwake/files/etc/config/uci-etherwake    (revision 0)
+++ net/uci-etherwake/files/etc/config/uci-etherwake    (revision 0)
@@ -0,0 +1,11 @@
+config 'uci-etherwake' 'setup'
+       # possible program pathes
+       option 'pathes' '/usr/bin/etherwake /usr/bin/ether-wake'
+       # use sudo, defaults to off
+       option 'sudo' 'off'
+       # interface, defaults to 'eth0'
+       # -i <ifname>
+       option 'interface' ''
+       # send wake-up packet to the broadcast address, defaults to off
+       # -b
+       option 'broadcast' 'off'
Index: net/uci-etherwake/files/bin/uci-etherwake
===================================================================
--- net/uci-etherwake/files/bin/uci-etherwake   (revision 0)
+++ net/uci-etherwake/files/bin/uci-etherwake   (revision 0)
@@ -0,0 +1,44 @@
+#!/bin/sh
+# Copyright (C) 2009 OpenWrt.org
+
+NAME='etherwake'
+
+. /etc/functions.sh
+include /lib/uci-wakeonlan
+
+config_load "uci-${NAME}"
+
+local searchlist=''
+config_get searchlist 'setup' 'pathes'
+
+local program=''
+program=$(search_wolprogram "${searchlist}")
+[ -z "${program}" ] && {
+       echo "No ${NAME} program installed. Check: opkg list | grep ${NAME}"
+       exit 1
+}
+
+local value=''
+local cmd=''
+
+# sudo
+config_get_bool value 'setup' 'sudo' '0'
+[ "${value}" -ne 0 ] && append cmd 'sudo'
+
+# program
+append cmd "${program}"
+
+# interface
+config_get value 'setup' 'interface'
+[ -n "${value}" ] && append cmd "-i ${value}"
+
+# broadcast
+config_get_bool value 'setup' 'broadcast' '0'
+[ "${value}" -ne 0 ] && append cmd '-b'
+
+# append given command line paramters
+[ -n "$*" ] && append cmd "$*"
+
+echo "Waking up via ${cmd} ..."
+${cmd}
+exit $?
Index: net/uci-etherwake/files/lib/uci-wakeonlan/uci-etherwake.sh
===================================================================
--- net/uci-etherwake/files/lib/uci-wakeonlan/uci-etherwake.sh  (revision 0)
+++ net/uci-etherwake/files/lib/uci-wakeonlan/uci-etherwake.sh  (revision 0)
@@ -0,0 +1,11 @@
+#!/bin/sh
+# Copyright (C) 2009 OpenWrt.org
+
+# prepare hex password
+etherwake_password()
+{
+       local delimiter=':'
+       local password=`echo "$1" | sed "s/../&${delimiter}/g"`
+       echo "-p ${password%${delimiter}}"
+       return
+}
Index: net/uci-wakeonlan/Makefile
===================================================================
--- net/uci-wakeonlan/Makefile  (revision 0)
+++ net/uci-wakeonlan/Makefile  (revision 0)
@@ -0,0 +1,46 @@
+#
+# Copyright (C) 2009 OpenWrt.org
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=uci-wakeonlan
+PKG_VERSION:=0.9
+PKG_RELEASE:=1
+
+PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/uci-wakeonlan
+  SECTION:=net
+  CATEGORY:=Network
+  SUBMENU:=Wake-On-LAN
+  TITLE:=Wake up WoL targets via UCI configuration
+  PKGARCH:=all
+endef
+
+define Package/uci-wakeonlan/description
+       You can define WoL targets in UCI with mac and password. Additionally
+       the program (etherwake or wol) to wake it up can be defined, plus if
+       the target should be waked up when the system starts (via init script).
+endef
+
+define Build/Compile
+endef
+
+define Package/uci-wakeonlan/install
+       $(INSTALL_DIR) $(1)/bin
+       $(INSTALL_BIN) files/bin/$(PKG_NAME) $(1)/bin/
+       $(INSTALL_DIR) $(1)/etc/config
+       $(INSTALL_DATA) files/etc/config/$(PKG_NAME) $(1)/etc/config/
+       $(INSTALL_DIR) $(1)/etc/init.d
+       $(INSTALL_BIN) files/etc/init.d/$(PKG_NAME) $(1)/etc/init.d/
+       $(INSTALL_DIR) $(1)/lib/uci-wakeonlan
+       $(INSTALL_DATA) files/lib/uci-wakeonlan/config.sh 
$(1)/lib/uci-wakeonlan/
+endef
+
+$(eval $(call BuildPackage,uci-wakeonlan))
Index: net/uci-wakeonlan/files/etc/config/uci-wakeonlan
===================================================================
--- net/uci-wakeonlan/files/etc/config/uci-wakeonlan    (revision 0)
+++ net/uci-wakeonlan/files/etc/config/uci-wakeonlan    (revision 0)
@@ -0,0 +1,19 @@
+config 'target' 'example1'
+       # mac address to wake up
+       option 'mac' '11:11:11:11:11:11:11'
+       # password in hex without any delimiters
+       option 'password' 'AAAAAAAAAAAA'
+       # wake-on-lan program to use (etherwake or wol)
+       option 'program' 'etherwake'
+       # wake up with init script (e.g. when system starts), defaults to off
+       option 'wakeonboot' 'on'
+
+config 'target' 'example2'
+       # mac address to wake up
+       option 'mac' '22:22:22:22:22:22:22'
+       # password in hex without any delimiters
+       option 'password' 'BBBBBBBBBBBB'
+       # wake-on-lan program to use (etherwake or wol)
+       option 'program' 'etherwake'
+       # wake up with init script (e.g. when system starts), defaults to off
+       option 'wakeonboot' 'off'
Index: net/uci-wakeonlan/files/bin/uci-wakeonlan
===================================================================
--- net/uci-wakeonlan/files/bin/uci-wakeonlan   (revision 0)
+++ net/uci-wakeonlan/files/bin/uci-wakeonlan   (revision 0)
@@ -0,0 +1,17 @@
+#!/bin/sh
+# Copyright (C) 2009 OpenWrt.org
+
+NAME='uci-wakeonlan'
+
+. /etc/functions.sh
+include /lib/uci-wakeonlan
+
+config_load "${NAME}"
+
+local section=''
+local output=''
+
+for section in $* ; do
+       output=$(execute_wakeup "${section}")
+       echo ${output}
+done
Index: net/uci-wakeonlan/files/lib/uci-wakeonlan/config.sh
===================================================================
--- net/uci-wakeonlan/files/lib/uci-wakeonlan/config.sh (revision 0)
+++ net/uci-wakeonlan/files/lib/uci-wakeonlan/config.sh (revision 0)
@@ -0,0 +1,67 @@
+#!/bin/sh
+# Copyright (C) 2009 OpenWrt.org
+
+# find first available program from searchlist
+search_wolprogram()
+{
+       local searchlist="$1"
+       local test=''
+       local program=''
+
+       for test in ${searchlist} ; do
+               [ -x "${test}" ] && {
+                       program="${test}"
+                       break;
+               }
+       done
+
+       [ -n "${program}" ] && echo "${program}"
+
+       return
+}
+
+# wake up a target
+execute_wakeup()
+{
+       local section="$1"
+
+       local program=''
+       local password=''
+       local value=''
+       local cmd=''
+
+       # program for target
+       config_get program "${section}" 'program'
+       [ -z "${program}" ] && {
+               echo "${NAME}: No program specified for target ${section} 
(etherwake or wol)"
+               return 1
+       }
+       append cmd "/bin/uci-${program}"
+
+       # only allow known programs
+       case "${program}" in
+        'wol')
+               ;;
+        'etherwake')
+               ;;
+        *)
+               echo "${NAME}: Unknown program ${program} specified for target 
${section} (etherwake or wol)"
+               return 1
+               ;;
+       esac
+
+       # password
+       config_get value "${section}" 'password'
+       [ -n "${value}" ] && {
+               password=$(${program}_password "${value}")
+               append cmd "${password}"
+       }
+
+       # mac address
+       config_get value "${section}" 'mac'
+       [ -n "${value}" ] && append cmd "${value}"
+
+       echo "Waking up ${section} via ${cmd} ..."
+       ${cmd} >/dev/null
+       return $?
+}
Index: net/uci-wakeonlan/files/etc/init.d/uci-wakeonlan
===================================================================
--- net/uci-wakeonlan/files/etc/init.d/uci-wakeonlan    (revision 0)
+++ net/uci-wakeonlan/files/etc/init.d/uci-wakeonlan    (revision 0)
@@ -0,0 +1,27 @@
+#!/bin/sh /etc/rc.common
+# Copyright (C) 2009 OpenWrt.org
+
+NAME='uci-wakeonlan'
+START=60
+
+include /lib/uci-wakeonlan
+
+wakeonlan_start() {
+       local section="$1"
+       local value=''
+
+       # wake up target via init script
+       config_get_bool value "${section}" 'wakeonboot' '0'
+       [ "${value}" -eq 0 ] && return 0
+
+       value=$(execute_wakeup "${section}")
+       echo ${value}
+       return 0
+}
+
+start() {
+       config_load "${NAME}"
+
+       # wake up targets
+       config_foreach wakeonlan_start target
+}
Index: net/uci-wol/Makefile
===================================================================
--- net/uci-wol/Makefile        (revision 0)
+++ net/uci-wol/Makefile        (revision 0)
@@ -0,0 +1,45 @@
+# 
+# Copyright (C) 2009 OpenWrt.org
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=uci-wol
+PKG_VERSION:=0.9
+PKG_RELEASE:=1
+
+PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/uci-wol
+  SECTION:=net
+  CATEGORY:=Network
+  SUBMENU:=Wake-On-LAN
+  DEPENDS:=+wol +uci-wakeonlan
+  TITLE:=uci support for wol
+  PKGARCH:=all
+endef
+
+define Package/uci-wol/description
+       You can define system defaults via uci.
+       The script uci-wol uses these defaults for calling wol.
+       No more need to remember which ip or port to use.
+endef
+
+define Build/Compile
+endef
+
+define Package/uci-wol/install
+       $(INSTALL_DIR) $(1)/bin
+       $(INSTALL_BIN) files/bin/$(PKG_NAME) $(1)/bin/
+       $(INSTALL_DIR) $(1)/etc/config
+       $(INSTALL_DATA) files/etc/config/$(PKG_NAME) $(1)/etc/config/
+       $(INSTALL_DIR) $(1)/lib/uci-wakeonlan
+       $(INSTALL_DATA) files/lib/uci-wakeonlan/$(PKG_NAME).sh 
$(1)/lib/uci-wakeonlan/
+endef
+
+$(eval $(call BuildPackage,uci-wol))
Index: net/uci-wol/files/etc/config/uci-wol
===================================================================
--- net/uci-wol/files/etc/config/uci-wol        (revision 0)
+++ net/uci-wol/files/etc/config/uci-wol        (revision 0)
@@ -0,0 +1,9 @@
+config 'uci-wol' 'setup'
+       # possible program pathes
+       option 'pathes' '/usr/bin/wol'
+       # ip address, e.g. broadcast address
+       # --ipaddr=<ip>
+       option 'ip' ''
+       # ip port
+       # --port=<port>
+       option 'port' ''
Index: net/uci-wol/files/bin/uci-wol
===================================================================
--- net/uci-wol/files/bin/uci-wol       (revision 0)
+++ net/uci-wol/files/bin/uci-wol       (revision 0)
@@ -0,0 +1,44 @@
+#!/bin/sh
+# Copyright (C) 2009 OpenWrt.org
+
+NAME='wol'
+
+. /etc/functions.sh
+include /lib/uci-wakeonlan
+
+config_load "uci-${NAME}"
+
+local searchlist=''
+config_get searchlist 'setup' 'pathes'
+
+local program=''
+program=$(search_wolprogram "${searchlist}")
+[ -z "${program}" ] && {
+       echo "No ${NAME} program installed. Check: opkg list | grep ${NAME}"
+       exit 1
+}
+
+local value=''
+local cmd=''
+
+# sudo
+config_get_bool value 'setup' 'sudo' '0'
+[ "${value}" -ne 0 ] && append cmd 'sudo'
+
+# program
+append cmd "${program}"
+
+# ip address
+config_get value 'setup' 'ip'
+[ -n "${value}" ] && append cmd "--ipaddr=${value}"
+
+# port
+config_get value 'setup' 'port'
+[ -n "${value}" ] && append cmd "--port=${value}"
+
+# append given command line paramters
+[ -n "$*" ] && append cmd "$*"
+
+echo "Waking up via ${cmd} ..."
+${cmd}
+exit $?
Index: net/uci-wol/files/lib/uci-wakeonlan/uci-wol.sh
===================================================================
--- net/uci-wol/files/lib/uci-wakeonlan/uci-wol.sh      (revision 0)
+++ net/uci-wol/files/lib/uci-wakeonlan/uci-wol.sh      (revision 0)
@@ -0,0 +1,11 @@
+#!/bin/sh
+# Copyright (C) 2009 OpenWrt.org
+
+# prepare hex password
+wol_password()
+{
+       local delimiter='-'
+       local password=`echo "$1" | sed "s/../&${delimiter}/g"`
+       echo "--passwd=${password%${delimiter}}"
+       return
+}
_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel

Reply via email to