git: 1d7b2b3983c9 - main - audio/owntone: support for multiple profiles

From: Dirk Meyer <dinoex_at_FreeBSD.org>
Date: Sun, 19 Nov 2023 17:34:38 UTC
The branch main has been updated by dinoex:

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

commit 1d7b2b3983c9ab9e4b9232b567625ceca3803b27
Author:     Dirk Meyer <dinoex@FreeBSD.org>
AuthorDate: 2023-11-19 17:33:27 +0000
Commit:     Dirk Meyer <dinoex@FreeBSD.org>
CommitDate: 2023-11-19 17:33:27 +0000

    audio/owntone: support for multiple profiles
    
    Submitted by: Raivo Hool
---
 audio/owntone/files/owntone.in | 66 +++++++++++++++++++++++++++++++++++-------
 1 file changed, 56 insertions(+), 10 deletions(-)

diff --git a/audio/owntone/files/owntone.in b/audio/owntone/files/owntone.in
index c4209cf44a0c..0c4173e197e1 100644
--- a/audio/owntone/files/owntone.in
+++ b/audio/owntone/files/owntone.in
@@ -11,23 +11,69 @@
 #				Set it to YES to enable owntone.
 # owntone_config (path):	Set to %%PREFIX%%/etc/owntone.conf
 #				by default.
-# owntone_flags (str):	Set to "" by default
+# owntone_flags (str):		Set to "" by default
+#
+# for mutiple profiles create an symlink
+# cd %%PREFIX%%/etc/rc.d/ && ln -s owntone NAME
+# and set this lines:
+#
+# NAME_enable (bool):		Set to NO by default.
+#				Set it to YES to enable owntone.
+# NAME_config="/usr/local/etc/owntone/NAME.conf"    # config file
+# NAME_flags (str):		Set to "" by default
 
 . /etc/rc.subr
 
-name=owntone
+# service(8) does not create an authentic environment, try to guess,
+# and as of 10.3-RELEASE-p0, it will not find the indented name
+# assignments below. So give it a default.
+# Trailing semicolon also for service(8)'s benefit:
+name="$file" ;
+rcvar=${name}_enable
+
+case "$0" in
+/etc/rc*)
+	# during boot (shutdown) $0 is /etc/rc (/etc/rc.shutdown),
+	# so get the name of the script from $_file
+	name="$_file"
+	;;
+*/service)
+	# do not use this as $0
+	;;
+*)
+	name="$0"
+	;;
+esac
+
+# default name to "owntone" if guessing failed
+# Trailing semicolon also for service(8)'s benefit:
+name="${name:-owntone}" ;
+name="${name##*/}"
 rcvar=${name}_enable
 
-load_rc_config $name
+stop_postcmd()
+{
+	rm -f "$pidfile" || warn "Could not remove $pidfile."
+}
+
+# pidfile
+pidfile="/var/run/${name}.pid"
+
+# command and arguments
+command="/usr/local/sbin/owntone"
+
+# run this last
+stop_postcmd="stop_postcmd"
+
+load_rc_config ${name}
+eval ": \${${name}_enable:=\"NO\"}"
+eval ": \${${name}_config:=\"/usr/local/etc/${name}.conf\"}"
 
-: ${owntone_enable:="NO"}
-: ${owntone_config:="%%PREFIX%%/etc/owntone.conf"}
-: ${owntone_flags:=""}
+config="$(eval echo \${${name}_config})"
+flags="$(eval echo \${${name}_flags})"
 
-pidfile="/var/run/owntone.pid"
-required_files="$owntone_config"
+required_files=${config}
 
-command="%%PREFIX%%/sbin/owntone"
-command_args="-P $pidfile -c $owntone_config $owntone_flags"
+command_args="-P ${pidfile} -c ${config} ${flags}"
 
 run_rc_command "$1"