Init script to start instances of socat for port-forwarding etc.

Signed-off-by: Henning Schild <[email protected]>
---
 net/socat/Makefile           | 10 +++++++++-
 net/socat/files/socat.config |  5 +++++
 net/socat/files/socat.init   | 39 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 53 insertions(+), 1 deletion(-)
 create mode 100644 net/socat/files/socat.config
 create mode 100644 net/socat/files/socat.init

diff --git a/net/socat/Makefile b/net/socat/Makefile
index a0d1e51..91a86a3 100644
--- a/net/socat/Makefile
+++ b/net/socat/Makefile
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=socat
 PKG_VERSION:=1.7.2.4
-PKG_RELEASE:=1
+PKG_RELEASE:=2
 
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
 PKG_SOURCE_URL:=http://www.dest-unreach.org/socat/download
@@ -50,6 +50,10 @@ config SOCAT_SSL
           Implements SSL support in socat (using libopenssl).
 endef
 
+define Package/socat/conffiles
+/etc/config/socat
+endef
+
 CONFIGURE_ARGS += \
        --disable-libwrap \
        --disable-readline \
@@ -68,6 +72,10 @@ CONFIGURE_VARS += \
 define Package/socat/install
        $(INSTALL_DIR) $(1)/usr/bin
        $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/socat $(1)/usr/bin/
+       $(INSTALL_DIR) $(1)/etc/config
+       $(INSTALL_CONF) ./files/socat.config $(1)/etc/config/socat
+       $(INSTALL_DIR) $(1)/etc/init.d
+       $(INSTALL_BIN) ./files/socat.init $(1)/etc/init.d/socat
 endef
 
 $(eval $(call BuildPackage,socat))
diff --git a/net/socat/files/socat.config b/net/socat/files/socat.config
new file mode 100644
index 0000000..7df6358
--- /dev/null
+++ b/net/socat/files/socat.config
@@ -0,0 +1,5 @@
+# forward port 8000 on IPv6 to IPv4 host port 80
+# change enable to '1' to use this example
+config socat 'http'
+       option enable '0'
+       option SocatOptions '-d -d TCP6-LISTEN:8000,fork TCP4:192.168.1.20:80'
diff --git a/net/socat/files/socat.init b/net/socat/files/socat.init
new file mode 100644
index 0000000..379dc07
--- /dev/null
+++ b/net/socat/files/socat.init
@@ -0,0 +1,39 @@
+#!/bin/sh /etc/rc.common
+# Copyright (C) 2008-2014 OpenWrt.org
+
+START=99
+STOP=99
+
+USE_PROCD=1
+PROG=/usr/bin/socat
+NAME=socat
+
+validate_section_socat()
+{
+       uci_validate_section socat socat "${1}" \
+               'enable:bool:1' \
+               'SocatOptions:string'
+       return $?
+}
+
+socat_instance()
+{
+       local SocatOptions enable
+
+       validate_section_socat "${1}" || {
+               echo "validation failed"
+               return 1
+       }
+
+       [ "${enable}" = "0" ] && return 1
+
+       procd_open_instance
+       procd_set_param command "$PROG"
+       procd_append_param command ${SocatOptions}
+       procd_close_instance
+}
+
+start_service () {
+       config_load "${NAME}"
+       config_foreach socat_instance socat
+}
-- 
1.8.5.5
_______________________________________________
openwrt-devel mailing list
[email protected]
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel

Reply via email to