git: 1c86bd3eab08 - main - net/shadowsocks-rust: Add RC scripts and config file

From: Yuri Victorovich <yuri_at_FreeBSD.org>
Date: Mon, 19 Feb 2024 23:09:55 UTC
The branch main has been updated by yuri:

URL: https://cgit.FreeBSD.org/ports/commit/?id=1c86bd3eab08028106a5ca3e59cba5187ee596c9

commit 1c86bd3eab08028106a5ca3e59cba5187ee596c9
Author:     Yuri Victorovich <yuri@FreeBSD.org>
AuthorDate: 2024-02-19 23:08:20 +0000
Commit:     Yuri Victorovich <yuri@FreeBSD.org>
CommitDate: 2024-02-19 23:09:53 +0000

    net/shadowsocks-rust: Add RC scripts and config file
    
    Suggested by:   Matthias Fechner <mfechner@freebsd.org>
---
 net/shadowsocks-rust/Makefile               | 12 ++++++-----
 net/shadowsocks-rust/files/sslocal-rust.in  | 33 +++++++++++++++++++++++++++++
 net/shadowsocks-rust/files/ssserver-rust.in | 33 +++++++++++++++++++++++++++++
 net/shadowsocks-rust/pkg-plist              |  6 ++++++
 4 files changed, 79 insertions(+), 5 deletions(-)

diff --git a/net/shadowsocks-rust/Makefile b/net/shadowsocks-rust/Makefile
index 37bf97862d73..ca51eba183ca 100644
--- a/net/shadowsocks-rust/Makefile
+++ b/net/shadowsocks-rust/Makefile
@@ -1,7 +1,7 @@
 PORTNAME=	shadowsocks-rust
 DISTVERSIONPREFIX=	v
 DISTVERSION=	1.18.1
-PORTREVISION=	1
+PORTREVISION=	2
 CATEGORIES=	net
 
 MAINTAINER=	yuri@FreeBSD.org
@@ -12,6 +12,8 @@ LICENSE=	MIT
 LICENSE_FILE=	${WRKSRC}/LICENSE
 
 USES=		cargo
+USE_RC_SUBR=	sslocal-rust \
+		ssserver-rust
 
 USE_GITHUB=	yes
 GH_ACCOUNT=	shadowsocks
@@ -411,13 +413,13 @@ OPENSSLLIB=	/usr/lib
 
 EXECUTABLES=	sslocal ssmanager ssserver ssservice ssurl
 
-.for e in ${EXECUTABLES}
-PLIST_FILES+=	bin/${e}
-.endfor
-
 post-install:
+	# strip binaries
 .for e in ${EXECUTABLES}
 	@${STRIP_CMD} ${STAGEDIR}${PREFIX}/bin/${e}
 .endfor
+	# install config file
+	${MKDIR} ${STAGEDIR}${ETCDIR}
+	${INSTALL_DATA} ${WRKSRC}/examples/config.json ${STAGEDIR}${ETCDIR}/config.json.sample
 
 .include <bsd.port.mk>
diff --git a/net/shadowsocks-rust/files/sslocal-rust.in b/net/shadowsocks-rust/files/sslocal-rust.in
new file mode 100644
index 000000000000..b27fa7e949cc
--- /dev/null
+++ b/net/shadowsocks-rust/files/sslocal-rust.in
@@ -0,0 +1,33 @@
+#!/bin/sh
+
+# PROVIDE: sslocal_rust
+# REQUIRE: NETWORKING SERVERS
+#
+# Add the following lines to /etc/rc.conf to run sslocal:
+# sslocal_rust_enable (bool):	Set it to "YES" to enable sslocal.
+#				Default is "NO".
+# sslocal_rust_args (string):	Set it to the desired arguments to run sslocal.
+#				Default is "-c %%ETCDIR%%/config.json".
+#
+
+. /etc/rc.subr
+
+name="sslocal_rust"
+rcvar=sslocal_rust_enable
+
+pidfile="/var/run/${name}.pid"
+logfile="/var/log/${name}.log"
+
+: ${sslocal_rust_enable="NO"}
+: ${sslocal_rust_args="-c %%ETCDIR%%/config.json"}
+
+procname=%%PREFIX%%/bin/sslocal
+command="/usr/sbin/daemon"
+command_args="-f -S \
+	-p ${pidfile} \
+	-o ${logfile} \
+	-t ${name}_sslocal \
+	%%PREFIX%%/bin/sslocal $sslocal_rust_args"
+
+load_rc_config $name
+run_rc_command "$1"
diff --git a/net/shadowsocks-rust/files/ssserver-rust.in b/net/shadowsocks-rust/files/ssserver-rust.in
new file mode 100644
index 000000000000..24bee1855a2e
--- /dev/null
+++ b/net/shadowsocks-rust/files/ssserver-rust.in
@@ -0,0 +1,33 @@
+#!/bin/sh
+
+# PROVIDE: ssserver_rust
+# REQUIRE: NETWORKING SERVERS
+#
+# Add the following lines to /etc/rc.conf to run ssserver:
+# ssserver_rust_enable (bool):	Set it to "YES" to enable ssserver.
+#				Default is "NO".
+# ssserver_rust_args (string):	Set it to the desired arguments to run ssserver.
+#				Default is "-c %%ETCDIR%%/config.json".
+#
+
+. /etc/rc.subr
+
+name="ssserver_rust"
+rcvar=ssserver_rust_enable
+
+pidfile="/var/run/${name}.pid"
+logfile="/var/log/${name}.log"
+
+: ${ssserver_rust_enable="NO"}
+: ${ssserver_rust_args="-c %%ETCDIR%%/config.json"}
+
+procname=%%PREFIX%%/bin/ssserver
+command="/usr/sbin/daemon"
+command_args="-f -S \
+	-p ${pidfile} \
+	-o ${logfile} \
+	-t ${name}_ssserver \
+	%%PREFIX%%/bin/ssserver $ssserver_rust_args"
+
+load_rc_config $name
+run_rc_command "$1"
diff --git a/net/shadowsocks-rust/pkg-plist b/net/shadowsocks-rust/pkg-plist
new file mode 100644
index 000000000000..86c406291454
--- /dev/null
+++ b/net/shadowsocks-rust/pkg-plist
@@ -0,0 +1,6 @@
+bin/sslocal
+bin/ssmanager
+bin/ssserver
+bin/ssservice
+bin/ssurl
+@sample %%ETCDIR%%/config.json.sample