[package] add uci support to etherwake, patch from Matthias Buecher (#6025)
git-svn-id: svn://svn.openwrt.org/openwrt/packages@20321 3c298f89-4303-0410-b956-a3cf2f4a3e73
This commit is contained in:
parent
3a1b370296
commit
f0f67928f4
@ -1,14 +1,15 @@
|
|||||||
#
|
#
|
||||||
# Copyright (C) 2007 OpenWrt.org
|
# Copyright (C) 2007-2009 OpenWrt.org
|
||||||
#
|
#
|
||||||
# This is free software, licensed under the GNU General Public License v2.
|
# This is free software, licensed under the GNU General Public License v2.
|
||||||
# See /LICENSE for more information.
|
# See /LICENSE for more information.
|
||||||
|
#
|
||||||
|
|
||||||
include $(TOPDIR)/rules.mk
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
PKG_NAME:=etherwake
|
PKG_NAME:=etherwake
|
||||||
PKG_VERSION:=1.09
|
PKG_VERSION:=1.09
|
||||||
PKG_RELEASE:=1
|
PKG_RELEASE:=2
|
||||||
|
|
||||||
PKG_SOURCE:=$(PKG_NAME)_$(PKG_VERSION).orig.tar.gz
|
PKG_SOURCE:=$(PKG_NAME)_$(PKG_VERSION).orig.tar.gz
|
||||||
PKG_SOURCE_URL:=http://ftp.debian.org/debian/pool/main/e/etherwake
|
PKG_SOURCE_URL:=http://ftp.debian.org/debian/pool/main/e/etherwake
|
||||||
@ -21,7 +22,7 @@ include $(INCLUDE_DIR)/package.mk
|
|||||||
define Package/etherwake
|
define Package/etherwake
|
||||||
SECTION:=net
|
SECTION:=net
|
||||||
CATEGORY:=Network
|
CATEGORY:=Network
|
||||||
TITLE:=A little tool to send magic Wake-on-LAN packets
|
TITLE:=WoL client for magic packets via ethernet frames
|
||||||
URL:=http://ftp.debian.org/debian/pool/main/e/etherwake
|
URL:=http://ftp.debian.org/debian/pool/main/e/etherwake
|
||||||
endef
|
endef
|
||||||
|
|
||||||
@ -40,6 +41,10 @@ endef
|
|||||||
define Package/etherwake/install
|
define Package/etherwake/install
|
||||||
$(INSTALL_DIR) $(1)/usr/bin
|
$(INSTALL_DIR) $(1)/usr/bin
|
||||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/etherwake $(1)/usr/bin/
|
$(INSTALL_BIN) $(PKG_BUILD_DIR)/etherwake $(1)/usr/bin/
|
||||||
|
$(INSTALL_DIR) $(1)/etc/config
|
||||||
|
$(INSTALL_DATA) files/$(PKG_NAME).config $(1)/etc/config/$(PKG_NAME)
|
||||||
|
$(INSTALL_DIR) $(1)/etc/init.d
|
||||||
|
$(INSTALL_BIN) files/$(PKG_NAME).init $(1)/etc/init.d/$(PKG_NAME)
|
||||||
endef
|
endef
|
||||||
|
|
||||||
$(eval $(call BuildPackage,etherwake))
|
$(eval $(call BuildPackage,etherwake))
|
||||||
|
28
net/etherwake/files/etherwake.config
Normal file
28
net/etherwake/files/etherwake.config
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
config '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'
|
||||||
|
|
||||||
|
config 'target'
|
||||||
|
# name for the target
|
||||||
|
option 'name' 'example'
|
||||||
|
# mac address to wake up
|
||||||
|
option 'mac' '11:22:33:44:55:66'
|
||||||
|
# password in hex without any delimiters
|
||||||
|
option 'password' 'AABBCCDDEEFF'
|
||||||
|
# wake up on system start, defaults to off
|
||||||
|
option 'wakeonboot' 'off'
|
||||||
|
|
||||||
|
# To add a new target use:
|
||||||
|
# uci add etherwake target
|
||||||
|
# uci set etherwake.@target[-1].name=example
|
||||||
|
# uci set etherwake.@target[-1].mac=11:22:33:44:55:66
|
||||||
|
# uci set etherwake.@target[-1].password=AABBCCDDEEFF
|
||||||
|
# uci set etherwake.@target[-1].wakeonboot=off
|
132
net/etherwake/files/etherwake.init
Normal file
132
net/etherwake/files/etherwake.init
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
#!/bin/sh /etc/rc.common
|
||||||
|
# Copyright (C) 2009 OpenWrt.org
|
||||||
|
|
||||||
|
NAME='etherwake'
|
||||||
|
START=60
|
||||||
|
PROGRAM=''
|
||||||
|
|
||||||
|
start()
|
||||||
|
{
|
||||||
|
local searchlist=''
|
||||||
|
local section=''
|
||||||
|
local value=''
|
||||||
|
|
||||||
|
config_load "${NAME}"
|
||||||
|
|
||||||
|
# check for available program
|
||||||
|
config_get searchlist 'setup' 'pathes'
|
||||||
|
PROGRAM=$(search_program "${searchlist}")
|
||||||
|
[ -z "${PROGRAM}" ] && {
|
||||||
|
echo "${initscript}: No ${NAME} program installed. Check: opkg list | grep ${NAME}"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# sudo
|
||||||
|
config_get_bool value 'setup' 'sudo' '0'
|
||||||
|
[ "${value}" -ne 0 ] && PROGRAM="sudo ${PROGRAM}"
|
||||||
|
|
||||||
|
# interface
|
||||||
|
config_get value 'setup' 'interface'
|
||||||
|
[ -n "${value}" ] && append PROGRAM "-i ${value}"
|
||||||
|
|
||||||
|
# broadcast
|
||||||
|
config_get_bool value 'setup' 'broadcast' '0'
|
||||||
|
[ "${value}" -ne 0 ] && append PROGRAM '-b'
|
||||||
|
|
||||||
|
# wake up targets
|
||||||
|
config_foreach etherwake_start target $*
|
||||||
|
}
|
||||||
|
|
||||||
|
etherwake_start()
|
||||||
|
{
|
||||||
|
local section="$1"
|
||||||
|
shift
|
||||||
|
|
||||||
|
local names="$*"
|
||||||
|
|
||||||
|
local value=''
|
||||||
|
local target=''
|
||||||
|
|
||||||
|
if [ -z "${names}" ]
|
||||||
|
then
|
||||||
|
# check if boot target
|
||||||
|
config_get_bool value "${section}" 'wakeonboot' '0'
|
||||||
|
[ "${value}" -eq 0 ] && return 0
|
||||||
|
|
||||||
|
# wake up target
|
||||||
|
do_etherwake "${section}"
|
||||||
|
return $?
|
||||||
|
else
|
||||||
|
# name
|
||||||
|
config_get value "${section}" 'name'
|
||||||
|
[ -z "${value}" ] && return 0
|
||||||
|
|
||||||
|
for target in ${names}
|
||||||
|
do
|
||||||
|
[ "${value}" != "${target}" ] && continue
|
||||||
|
|
||||||
|
# wake up target
|
||||||
|
do_etherwake "${section}"
|
||||||
|
return $?
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# execute etherwake command for target
|
||||||
|
do_etherwake()
|
||||||
|
{
|
||||||
|
local section="$1"
|
||||||
|
local value=''
|
||||||
|
local password=''
|
||||||
|
local args=''
|
||||||
|
|
||||||
|
# password
|
||||||
|
config_get value "${section}" 'password'
|
||||||
|
[ -n "${value}" ] && {
|
||||||
|
password=$(etherwake_password "${value}")
|
||||||
|
append args "-p ${password}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# mac address
|
||||||
|
config_get value "${section}" 'mac'
|
||||||
|
[ -z "${value}" ] && { echo "${initscript}: Target ${section} has no MAC address"; return 1; }
|
||||||
|
append args "${value}"
|
||||||
|
|
||||||
|
# name
|
||||||
|
config_get value "${section}" 'name'
|
||||||
|
[ -z "${value}" ] && value="{section}"
|
||||||
|
|
||||||
|
# execute command
|
||||||
|
echo "${initscript}: Waking up ${value} via ${PROGRAM}${args:+ ${args}}"
|
||||||
|
${PROGRAM} ${args}
|
||||||
|
return $?
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# find first available program from searchlist
|
||||||
|
search_program()
|
||||||
|
{
|
||||||
|
local searchlist="$1"
|
||||||
|
local test=''
|
||||||
|
local program=''
|
||||||
|
|
||||||
|
for test in ${searchlist} ; do
|
||||||
|
[ -x "${test}" ] && {
|
||||||
|
program="${test}"
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
done
|
||||||
|
|
||||||
|
[ -n "${program}" ] && echo "${program}"
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
# prepare hex password
|
||||||
|
etherwake_password()
|
||||||
|
{
|
||||||
|
local delimiter=':'
|
||||||
|
local password=`echo "$1" | sed "s/../&${delimiter}/g"`
|
||||||
|
echo "${password%${delimiter}}"
|
||||||
|
return
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user