Subject: pkg/18557: install and rcd scripts should be created at post-build, not pre-install
To: None <gnats-bugs@gnats.netbsd.org>
From: Greg A. Woods <woods@weird.com>
List: netbsd-bugs
Date: 10/06/2002 17:28:41
>Number:         18557
>Category:       pkg
>Synopsis:       install and rcd scripts should be created at post-build, not pre-install
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    pkg-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Oct 06 14:29:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Greg A. Woods
>Release:        pkgsrc-current 2002/10/05
>Organization:
Planix, Inc.; Toronto, Ontario; Canada
>Environment:
System: NetBSD 1.5W
>Description:

	The generate-install-scripts and generate-rcd-scripts targets
	should be invoked at post-build time, not pre-install time, as
	they should not be run as root.

>How-To-Repeat:

>Fix:

	note that it would be ideal if re-running "make
	post-build-script" would do the right thing if the script source
	had changed, but it seems that when dependency lists are built
	the necessary variables are not yet properly assigned and so
	setting a dependency on the source fails, at least in the way I
	tried it and then commented out again....

	also included are some internal documentation tweaks.

	WARNING: the bsd.pkg.mk diff is hand edited and should only
	serve as an example for application of the changes by hand!


Index: bsd.pkg.install.mk
===================================================================
RCS file: /cvs/master/m-NetBSD/main/pkgsrc/mk/bsd.pkg.install.mk,v
retrieving revision 1.31
diff -c -r1.31 bsd.pkg.install.mk
*** bsd.pkg.install.mk	4 Oct 2002 23:46:26 -0000	1.31
--- bsd.pkg.install.mk	6 Oct 2002 20:58:46 -0000
***************
*** 136,141 ****
--- 136,150 ----
  #	will be copied into ${RCD_SCRIPTS_DIR} with ${RCD_SCRIPTS_MODE}
  #	permissions.
  #
+ #	Note that when LOCALBASE=/usr and /usr/etc -> /etc the install will 
+ #	"complain" that /etc/rc.d/$script already exists and that the "new"
+ #	example is in /usr/etc/rc.d/$script.  This could be fixed, but is just
+ #	noise for now.
+ #
+ #	When the package is deinstalled	the de-install will also "complain"
+ #	that it could not remove /usr/etc/rc.d/$script because the de-install
+ #	script will remove it.  This needs to be fixed.
+ #
  CONF_FILES?=		# empty
  CONF_FILES_MODE?=	0644
  CONF_FILES_PERMS?=	# empty
***************
*** 249,254 ****
--- 258,265 ----
  
  INSTALL_SCRIPTS_ENV=	PKG_PREFIX=${PREFIX}
  
+ post-build-scripts: generate-install-scripts generate-rcd-scripts
+ 
  pre-install-script: generate-install-scripts
  	${_PKG_SILENT}${_PKG_DEBUG}${SETENV} ${INSTALL_SCRIPTS_ENV}	\
  		${_PKG_DEBUG_SCRIPT} ${INSTALL_FILE} ${PKGNAME} PRE-INSTALL
***************
*** 273,282 ****
  #
  # RCD_SCRIPT_SRC.<script>	the source file for <script>; this will
  #				be run through FILES_SUBST to generate
! #				the rc.d script
  #
  # RCD_SCRIPTS_EXAMPLEDIR	the directory in which to install the
! #				example rc.d scripts
  #
  # If the source rc.d script is not present, then the automatic handling
  # doesn't occur.
--- 284,295 ----
  #
  # RCD_SCRIPT_SRC.<script>	the source file for <script>; this will
  #				be run through FILES_SUBST to generate
! #				the rc.d script (defaults to
! #				${FILESDIR}/<script>.sh)
  #
  # RCD_SCRIPTS_EXAMPLEDIR	the directory in which to install the
! #				example rc.d scripts (defaults to
! #				${PREFIX}/etc/rc.d)
  #
  # If the source rc.d script is not present, then the automatic handling
  # doesn't occur.
***************
*** 288,294 ****
  RCD_SCRIPT_SRC.${_script_}?=	${FILESDIR}/${_script_}.sh
  
  generate-rcd-scripts: generate-rcd-${_script_}
! generate-rcd-${_script_}:
  	${_PKG_SILENT}${_PKG_DEBUG}					\
  	if [ ! -f ${WRKDIR}/${_script_} ] &&				\
  	   [ -f ${RCD_SCRIPT_SRC.${_script_}} ]; then			\
--- 301,307 ----
  RCD_SCRIPT_SRC.${_script_}?=	${FILESDIR}/${_script_}.sh
  
  generate-rcd-scripts: generate-rcd-${_script_}
! generate-rcd-${_script_}: # ${RCD_SCRIPT_SRC.${_script_}} # ARGH! This doesn't work!
  	${_PKG_SILENT}${_PKG_DEBUG}					\
  	if [ ! -f ${WRKDIR}/${_script_} ] &&				\
  	   [ -f ${RCD_SCRIPT_SRC.${_script_}} ]; then
	\
Index: bsd.pkg.mk
===================================================================
RCS file: /cvs/master/m-NetBSD/main/pkgsrc/mk/bsd.pkg.mk,v
retrieving revision 1.1063
diff -c -r1.1063 bsd.pkg.mk
*** bsd.pkg.mk	4 Oct 2002 11:19:26 -0000	1.1063
--- bsd.pkg.mk	6 Oct 2002 20:30:13 -0000
***************
*** 2671,2697 ****
  .ORDER: patch-message pre-patch do-patch post-patch patch-cookie
  .ORDER: buildlink-message pre-buildlink do-buildlink post-buildlink buildlink-cookie
  .ORDER: configure-message pre-configure do-configure post-configure configure-cookie
! .ORDER: build-message pre-build do-build post-build build-cookie
  
  # Please note that the order of the following targets is important, and
  # should not be modified (.ORDER is not recognised by make(1) in a serial
  # make i.e. without -j n)
  real-fetch: pre-fetch do-fetch post-fetch
  real-extract: extract-message install-depends pre-extract do-extract post-extract extract-cookie
  real-patch: patch-message pre-patch do-patch post-patch patch-cookie
  real-buildlink: buildlink-message pre-buildlink do-buildlink post-buildlink buildlink-cookie
  real-configure: configure-message pre-configure do-configure post-configure configure-cookie
! real-build: build-message pre-build do-build post-build build-cookie
  real-package: do-su-package
  real-replace: do-su-replace
  real-undo-replace: do-su-undo-replace
--- 2822,2864 ----
  .ORDER: patch-message pre-patch do-patch post-patch patch-cookie
  .ORDER: buildlink-message pre-buildlink do-buildlink post-buildlink buildlink-cookie
  .ORDER: configure-message pre-configure do-configure post-configure configure-cookie
! .ORDER: build-message pre-build do-build post-build post-build-scripts build-cookie
  
  # Please note that the order of the following targets is important, and
  # should not be modified (.ORDER is not recognised by make(1) in a serial
  # make i.e. without -j n)
  real-fetch: pre-fetch do-fetch post-fetch
  real-extract: extract-message install-depends pre-extract do-extract post-extract extract-cookie
  real-patch: patch-message pre-patch do-patch post-patch patch-cookie
  real-buildlink: buildlink-message pre-buildlink do-buildlink post-buildlink buildlink-cookie
  real-configure: configure-message pre-configure do-configure post-configure configure-cookie
! real-build: build-message pre-build do-build post-build post-build-scripts build-cookie
  real-package: do-su-package
  real-replace: do-su-replace
  real-undo-replace: do-su-undo-replace
***************
*** 2755,2761 ****
  
  # Empty pre-* and post-* targets
  
! .for name in fetch extract patch buildlink configure build install-script install package
  
  .  if !target(pre-${name})
  pre-${name}:
--- 2912,2918 ----
  
  # Empty pre-* and post-* targets
  
! .for name in fetch extract patch buildlink configure build-scripts build install-script install package
  
  .  if !target(pre-${name})
  pre-${name}:
>Release-Note:
>Audit-Trail:
>Unformatted: