rtpproxy: add init script and UCI config
authorJiri Slachta <slachta@cesnet.cz>
Sun, 21 Dec 2014 11:25:42 +0000 (12:25 +0100)
committerJiri Slachta <slachta@cesnet.cz>
Sun, 21 Dec 2014 11:25:42 +0000 (12:25 +0100)
Signed-off-by: Jiri Slachta <slachta@cesnet.cz>
net/rtpproxy/Makefile
net/rtpproxy/files/rtpproxy.config [new file with mode: 0644]
net/rtpproxy/files/rtpproxy.init [new file with mode: 0644]

index 3aed248ede2cb8d128a0a1b1dc436f7823e4b48d..2fa30144145100cd8ad0b62a0fad6d58f4c7e8b4 100644 (file)
@@ -1,5 +1,5 @@
 #
-# Copyright (C) 2013 OpenWrt.org
+# Copyright (C) 2014 OpenWrt.org
 #
 # This is free software, licensed under the GNU General Public License v2.
 # See /LICENSE for more information.
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=rtpproxy
 PKG_VERSION:=1.2.1
-PKG_RELEASE:=1
+PKG_RELEASE:=2
 
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
 PKG_SOURCE_URL:=http://b2bua.org/chrome/site/
@@ -31,11 +31,15 @@ define Package/rtpproxy
   URL:=http://www.rtpproxy.org/
 endef
 
-# uses GNU configure
-
 define Package/rtpproxy/install
        $(INSTALL_DIR) $(1)/usr/bin
        $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/rtpproxy $(1)/usr/bin/
+
+       $(INSTALL_DIR) $(1)/etc/init.d
+       $(INSTALL_BIN) ./files/rtpproxy.init $(1)/etc/init.d/rtpproxy
+
+       $(INSTALL_DIR) $(1)/etc/config
+       $(INSTALL_BIN) ./files/rtpproxy.config $(1)/etc/config/rtpproxy
 endef
 
 $(eval $(call BuildPackage,rtpproxy))
diff --git a/net/rtpproxy/files/rtpproxy.config b/net/rtpproxy/files/rtpproxy.config
new file mode 100644 (file)
index 0000000..9b72d7c
--- /dev/null
@@ -0,0 +1,14 @@
+config rtpproxy global
+       option enabled 0                                                # 0 - disabled, 1 - enabled
+
+config instance 'site1'                
+        option socket 'udp:127.0.0.1:7723'                             # socket
+       option ipaddr '127.0.0.1'                                       # IPv4 address
+       option ip6addr '2001:0db8:0000:0000:0000:0000:1428:57ab'        # IPv6 address
+       option user 'nobody'                                            # userid to run rtpproxy instance from
+       option opts ''                                          # additional options for rtpproxy instance
+                                      
+config instance 'site2'               
+        option socket 'udp:127.0.0.1:7724'
+       option ipaddr '192.168.1.1'
+
diff --git a/net/rtpproxy/files/rtpproxy.init b/net/rtpproxy/files/rtpproxy.init
new file mode 100644 (file)
index 0000000..d1e2b37
--- /dev/null
@@ -0,0 +1,70 @@
+#!/bin/sh /etc/rc.common
+# Copyright (C) 2014 CESNET, z.s.p.o
+
+START=99
+RTPPROXY_BIN="/usr/bin/rtpproxy"
+
+run_instance(){
+       local params="$1"
+
+       ${RTPPROXY_BIN} $1
+       echo "[INFO] rtpproxy instance $2 has started"
+}
+
+check_param(){
+       local param="$1"
+       local value="$2"
+       local default_value="$3"
+
+       if [ "$value" != "" ]; then
+               rtpproxy_options=$rtpproxy_options" $param $value"
+       else
+               if [ "$default_value" != "" ]; then
+                       rtpproxy_options=$rtpproxy_options" $param $default_value"
+               fi
+       fi
+}
+
+check_special_param(){
+       local param="$1"
+
+       if [ "$param" != "" ]; then
+               rtpproxy_options=$rtpproxy_options" $param"
+       fi
+}
+
+handle_instance() {
+       local site="$1"
+       local socket opts ipaddr ip6addr rtpproxy_options
+
+       config_get socket       "$site" socket
+       config_get opts         "$site" opts
+       config_get ipaddr       "$site" ipaddr
+       config_get ip6addr      "$site" ip6addr
+       config_get user         "$site" user
+
+       check_param "-s" "$socket"
+       check_param "-l" "$ipaddr"
+       check_param "-6" "$ip6addr"
+       check_param "-u" "$user" "nobody"
+       check_special_param "$opts"
+
+       run_instance "$rtpproxy_options" "$site"
+}
+
+start(){
+       config_load rtpproxy
+       local section="global"
+       config_get_bool enabled global enabled 0
+
+       if [ "$enabled" -eq 1 ]; then
+               config_foreach handle_instance instance
+       else
+               echo "[WARNING] rtpproxy not yet configured. Edit /etc/config/rtpproxy first."
+       fi
+}
+
+stop() {
+       killall rtpproxy
+}
+