Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 9 Nov 2004 16:41:03 +0100
From:      Oliver Eikemeier <eikemeier@fillmore-labs.com>
To:        Edwin Groothuis <edwin@mavetju.org>
Cc:        ports@freebsd.org
Subject:   Re: rc.subr extensions
Message-ID:  <C376B747-3265-11D9-A7A8-00039312D914@fillmore-labs.com>
In-Reply-To: <20041109040834.GA8940@k7.mavetju>

next in thread | previous in thread | raw e-mail | index | archive | help
Edwin Groothuis wrote:

> Hi,
>
> In ports/73691[1], I have submitted a patch for bsd.port.mk to make
> it easier for porters to use the rc.subr framework.
>
> The suggested changes are:
>
> - define RC_FILES, which contain a list of all the files to be
>   stored in /usr/local/etc/rc.d. This file may contain macros like
>   %%LOCALBASE%% and %%RC_SUBR%%.
>
> - define RC_SUBST, which contain a list of all variables to be
>   replaced. For example LOCALBASE with ${LOCALBASE}.
>
> - add three new targets:
>     - patch-rc, which patches the original RC_FILES to one with the
>       macros translated.

This should be done at the build stage, since these are not real 
`patches'.

>     - install-rc, which installs the RC_FILES to /usr/local/etc/rc.d.
>     - add-plist-rc, which adds the RC_FILES to the pkg-plist.
>
> This way it will be easier for porters to incorperate the rc.d files
> into the Makefile/bsd.port.mk framework.
>
> I'm sure I have missed a couple of things, so if you have played
> with rc.subr and missed some features, tell me about it and lets
> see how we can add them.

I would support this idea, in fact I discussed a similar patch on July 
26th on portmgr@. It's main intend was to ease the transition from rc.d 
scripts installed with a `.sh' extension to one installed extensionless 
to support rcorder(8) integration.

I cite it here just as a reference:

This patch allow to do

RC_SCRIPTS=	apache1 apache2.sh apache3.sh.sample 
${FILESDIR}/apache4.sh.tmpl ${.CURDIR}/files/apache5.sh

which will look for
${FILESDIR}/apache1.sh
${FILESDIR}/apache2.sh
${FILESDIR}/apache3.sh.sample
${FILESDIR}/apache4.sh.tmpl
${.CURDIR}/files/apache5.sh

and install (and add to the plist)

etc/rc.d/apache1.sh
etc/rc.d/apache2.sh
etc/rc.d/apache3.sh
etc/rc.d/apache4.sh
etc/rc.d/apache5.sh

(omitting the `.sh' when OSVERSION >= 600000)

The rules are:
- simple names suffice, an extra `.sh' is appended (standard case)
- if a path is given, the full pathname is required
- a .sh and an additional extension will be stripped

Index: bsd.port.mk
===================================================================
RCS file: /home/ncvs/ports/Mk/bsd.port.mk,v
retrieving revision 1.495
diff -u -u -r1.495 bsd.port.mk
--- bsd.port.mk	23 Jul 2004 19:10:05 -0000	1.495
+++ bsd.port.mk	26 Jul 2004 11:25:17 -0000
@@ -1358,13 +1358,27 @@
  .endif
  .endif

-.if defined(USE_RC_SUBR)
+.if defined(USE_RC_SUBR) || defined(RC_SCRIPTS)
  .if ${OSVERSION} < 500037
  RUN_DEPENDS+=	${LOCALBASE}/etc/rc.subr:${PORTSDIR}/sysutils/rc_subr
  RC_SUBR=	${LOCALBASE}/etc/rc.subr
  .else
  RC_SUBR=	/etc/rc.subr
  .endif
+.if ${OSVERSION} < 600000
+RC_SUFX=	.sh
+.else
+RC_SUFX=
+.endif
+PLIST_SUB+=	RC_SUFX=${RC_SUFX}
+
+RC_SCRIPT_SUB+=	RC_SUBR=${RC_SUBR} \
+				PREFIX=${PREFIX} \
+				LOCALBASE=${LOCALBASE} \
+				DATADIR=${DATADIR} \
+				DOCSDIR=${DOCSDIR} \
+				EXAMPLESDIR=${EXAMPLESDIR} \
+				PERL=${PERL}
  .endif

  .if defined(USE_ICONV)
@@ -3136,6 +3150,25 @@
  .endif
  .endif

+.if !target(build-rcscripts)
+build-rcscripts:
+	@cd ${.CURDIR}; \
+	for script in 
${RC_SCRIPTS:C/^([^|]*\/)?([^|]*)\.sh(\.[^.\/|]+)?$/\2|&/:C/.*/"&"/}; 
do \
+		case "$${script#*|}" in \
+		*/*)			source="$${script#*|}" ;; \
+		*.sh|*.sh.*)	source="${FILESDIR}/$${script#*|}" ;; \
+		*)				source="${FILESDIR}/$${script#*|}.sh" ;; \
+		esac; \
+		if [ -f "$${source}" ]; then \
+			${SED} ${RC_SCRIPT_SUB:S/$/!g/:S/^/ -e s!%%/:S/=/%%!/} -e 
"s!%%NAME%%!$${script%%|*}!g" \
+				"$${source}" > "${WRKDIR}/.$${script%%|*}.sh.${PREFIX:S/\//_/g}"; \
+		else \
+			${ECHO_MSG} ">> Missing script $$source."; \
+			${FALSE}; \
+		fi; \
+	done
+.endif
+
  # Check conflicts

  .if !target(check-conflicts)
@@ -3191,6 +3224,14 @@
  .endif
  .endif

+.if !target(install-rcscripts)
+install-rcscripts:
+	@for script in 
${RC_SCRIPTS:C/^([^|]*\/)?([^|]*)\.sh(\.[^.\/|]+)?$/\2/:C/.*/"&"/}; do \
+		${INSTALL_SCRIPT} "${WRKDIR}/.$${script%%|*}.sh.${PREFIX:S/\//_/g}" \
+			"${PREFIX}/etc/rc.d/$${script%%|*}${RC_SUFX}"; \
+	done
+.endif
+
  # Package

  .if !target(do-package)
@@ -3541,13 +3582,13 @@
  		run-autotools do-configure post-configure post-configure-script
  _BUILD_DEP=		configure
  _BUILD_SEQ=		build-message pre-build pre-build-script do-build \
-				post-build post-build-script
+				build-rcscripts post-build post-build-script
  _INSTALL_DEP=	build
  _INSTALL_SEQ=	install-message check-conflicts \
  			    run-depends lib-depends pre-install pre-install-script \
  				generate-plist check-already-installed
  _INSTALL_SUSEQ= check-umask install-mtree pre-su-install \
-				pre-su-install-script do-install post-install \
+				pre-su-install-script do-install install-rcscripts post-install \
  				post-install-script add-plist-info add-plist-docs \
  				compress-man run-ldconfig fake-pkg security-check
  _PACKAGE_DEP=	install
@@ -4602,6 +4643,9 @@
  .for dir in ${PLIST_DIRS}
  	@${ECHO_CMD} ${dir} | ${SED} ${PLIST_SUB:S/$/!g/:S/^/ -e 
s!%%/:S/=/%%!/} | ${SED} -e 's,^,@dirrm ,' >> ${TMPPLIST}
  .endfor
+	@for script in 
${RC_SCRIPTS:C/^([^|]*\/)?([^|]*)\.sh(\.[^.\/|]+)?$/\2|&/:C/.*/"&"/}; 
do \
+		${ECHO_CMD} "etc/rc.d/$${script%%|*}${RC_SUFX}" >> ${TMPPLIST}; \
+	done
  .if defined(INSTALLS_SHLIB) && !defined(INSTALL_AS_USER)
  	@${ECHO_CMD} "@exec ${LDCONFIG} -m ${LDCONFIG_PLIST}" >> ${TMPPLIST}
  	@${ECHO_CMD} "@unexec ${LDCONFIG} -R" >> ${TMPPLIST}


There is also a similar patch in PR 67151, but with a broader subject.

-Oliver



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?C376B747-3265-11D9-A7A8-00039312D914>