u2pnpd: add new package
authorMichael Heimpold <mhei@heimpold.de>
Thu, 1 Oct 2015 21:45:47 +0000 (23:45 +0200)
committerMichael Heimpold <mhei@heimpold.de>
Thu, 1 Oct 2015 21:49:20 +0000 (23:49 +0200)
u²pnpd announces a device as UPnP basic device on the
network so that an user could easily find it. It tries
to detect various system information automatically, however
everything can be overridden by UCI settings.

Signed-off-by: Michael Heimpold <mhei@heimpold.de>
net/u2pnpd/Makefile [new file with mode: 0644]
net/u2pnpd/files/u2pnpd.config [new file with mode: 0644]
net/u2pnpd/files/u2pnpd.defaults [new file with mode: 0644]
net/u2pnpd/files/u2pnpd.init [new file with mode: 0644]

diff --git a/net/u2pnpd/Makefile b/net/u2pnpd/Makefile
new file mode 100644 (file)
index 0000000..f859d3b
--- /dev/null
@@ -0,0 +1,63 @@
+#
+# Copyright (C) 2015 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:=u2pnpd
+PKG_VERSION:=0.1
+PKG_RELEASE:=1
+
+PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
+PKG_SOURCE_URL:=https://github.com/mhei/u2pnpd/releases/download/v$(PKG_VERSION)
+PKG_MD5SUM:=a98089923d93803fa90d03a504c98b8e
+
+PKG_LICENSE:=GPL-2.0
+PKG_LICENSE_FILES:=COPYING
+
+PKG_MAINTAINER:=Michael Heimpold <mhei@heimpold.de>
+
+PKG_INSTALL:=1
+PKG_BUILD_PARALLEL:=1
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/u2pnpd
+  SECTION:=net
+  CATEGORY:=Network
+  TITLE:=Announce device via UPnP on the network
+  URL:=https://github.com/mhei/u2pnpd
+  DEPENDS:=+libupnp
+endef
+
+define Package/u2pnpd/description
+  This tools announces a device via UPnP on the local network, thus it is possible
+  to find it within the network neightboorhood of a well-known OS and the user
+  can easily double-click on an icon to open the web frontend of this device without
+  knowing the IP address.
+endef
+
+define Package/u2pnpd/install
+       $(INSTALL_DIR) $(1)/usr/bin
+       $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/u2pnpd $(1)/usr/bin/
+
+       $(INSTALL_DIR) $(1)/etc/init.d
+       $(INSTALL_BIN) ./files/u2pnpd.init $(1)/etc/init.d/u2pnpd
+
+       $(INSTALL_DIR) $(1)/etc/uci-defaults
+       $(INSTALL_DATA) ./files/u2pnpd.defaults $(1)/etc/uci-defaults/u2pnpd
+
+       $(INSTALL_DIR) $(1)/etc/config
+       $(INSTALL_CONF) ./files/u2pnpd.config $(1)/etc/config/u2pnpd
+endef
+
+define Package/u2pnpd/postinst
+#!/bin/sh
+[ -n "$${IPKG_INSTROOT}" ] || (. /etc/uci-defaults/u2pnpd) && rm -f /etc/uci-defaults/u2pnpd
+exit 0
+endef
+
+$(eval $(call BuildPackage,u2pnpd))
diff --git a/net/u2pnpd/files/u2pnpd.config b/net/u2pnpd/files/u2pnpd.config
new file mode 100644 (file)
index 0000000..8c0d561
--- /dev/null
@@ -0,0 +1,11 @@
+config u2pnpd
+#      option interface        br-lan
+#      option use_https        no
+#      option manufacturer     'OpenWrt'
+#      option manufacturerURL  'http://www.openwrt.org/'
+#      option modelDescription ''
+#      option modelName        'Generic'
+#      option modelNumber      ''
+#      option modelURL         ''
+#      option serialNumber     ''
+#      option uuid             ''
diff --git a/net/u2pnpd/files/u2pnpd.defaults b/net/u2pnpd/files/u2pnpd.defaults
new file mode 100644 (file)
index 0000000..322b0bc
--- /dev/null
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+uuid=$(cat /proc/sys/kernel/random/uuid)
+
+uci -q batch <<-EOF >/dev/null
+       set u2pnpd.@u2pnpd[0].uuid=$uuid
+       commit u2pnpd
+EOF
+
+exit 0
diff --git a/net/u2pnpd/files/u2pnpd.init b/net/u2pnpd/files/u2pnpd.init
new file mode 100644 (file)
index 0000000..01437fd
--- /dev/null
@@ -0,0 +1,62 @@
+#!/bin/sh /etc/rc.common
+# Copyright (C) 2015 OpenWrt.org
+
+START=50
+STOP=20
+
+SERVICE_DAEMONIZE=1
+SERVICE_PID_FILE=/var/run/u2pnpd.pid
+SERVICE_USE_PID=1
+SERVICE_WRITE_PID=1
+
+start_instance() {
+       local section="$1"
+       local enabled
+       local interface manufacturer manufacturerURL modelDescription
+       local modelName modelNumber modelURL serialNumber friendlyName
+       local uuid httpsURL
+       local i
+
+       config_get_bool enabled "$section" 'enabled' 1
+       [ "$enabled" -gt 0 ] || return 0
+
+       for i in interface httpsURL manufacturer manufacturerURL modelDescription \
+                modelName modelNumber modelURL serialNumber friendlyName uuid; do
+               config_get "$i" "$section" "$i"
+       done
+
+       [ -n "$interface" ] && SERVICE_PID_FILE="/var/run/u2pnpd.$interface.pid"
+
+       service_start /usr/bin/u2pnpd ${httpsURL:+-s} \
+           ${interface:+--interface="$interface"} \
+           ${manufacturer:+--manufacturer="$manufacturer"} \
+           ${manufacturerURL:+--manufacturerURL="$manufacturerURL"} \
+           ${modelDescription:+--modelDescription="$modelDescription"} \
+           ${modelName:+--modelName="$modelName"} \
+           ${modelNumber:+--modelNumber="$modelNumber"} \
+           ${modelURL:+--modelURL="$modelURL"} \
+           ${serialNumber:+--serialNumber="$serialNumber"} \
+           ${friendlyName:+--friendlyName="$friendlyName"} \
+           ${uuid:+--uuid="$uuid"}
+}
+
+stop_instance() {
+       local section="$1"
+       local interface
+
+       config_get interface "$section" 'interface'
+       [ -n "$interface" ] && SERVICE_PID_FILE="/var/run/u2pnpd.$interface.pid"
+
+       service_stop /usr/bin/u2pnpd
+       rm -f "$SERVICE_PID_FILE"
+}
+
+start() {
+       config_load 'u2pnpd'
+       config_foreach start_instance 'u2pnpd'
+}
+
+stop() {
+       config_load 'u2pnpd'
+       config_foreach stop_instance 'u2pnpd'
+}