ports/157168: New hook: CONF_FILES automatically handles configuration files
Chris Rees
utisoft at gmail.com
Wed May 18 20:20:13 UTC 2011
>Number: 157168
>Category: ports
>Synopsis: New hook: CONF_FILES automatically handles configuration files
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-ports-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: change-request
>Submitter-Id: current-users
>Arrival-Date: Wed May 18 20:20:12 UTC 2011
>Closed-Date:
>Last-Modified:
>Originator: Chris Rees
>Release:
>Organization:
>Environment:
>Description:
As discussed on ports@ and with bapt@ on IRC, here is a patch to bsd.port.mk introducing two variables; CONF_FILES and CONF_DIRS.
The top of the patch contains terse descriptions, I will document it in the Porter's Handbook and try to figure out portlint when it's finalised.
This _must_ _not_ _be_ committed until the following PRs are committed:
ports/157158
ports/157159
ports/157160
ports/157161
ports/157162
ports/157163
ports/157164
ports/157165
ports/157166
AND until www/mod_pubcookie meets its end since these ports use CONF_FILES internally. I'll keep following up in the audit trail of this PR.
and if someone with a arc bit could please commit:
misc/157062
that would bring CONFMODE etc into the base system.
Hope it's all OK!
>How-To-Repeat:
>Fix:
- Introduce new macro INSTALL_CONF
- Introduce new functions CONF_FILES and CONF_DIRS -- automated and correct handling of configuration files installed by ports.
Submitted by: Chris Rees (utisoft at gmail.com)
Patch attached with submission follows:
Index: bsd.port.mk
===================================================================
RCS file: /exports/cvsroot-freebsd/ports/Mk/bsd.port.mk,v
retrieving revision 1.682
diff -u -r1.682 bsd.port.mk
--- bsd.port.mk 6 May 2011 06:20:12 -0000 1.682
+++ bsd.port.mk 18 May 2011 20:08:55 -0000
@@ -631,6 +631,8 @@
# INSTALL_DATA - A command to install sharable data.
# INSTALL_MAN - A command to install manpages. May or not compress,
# depending on the value of MANCOMPRESSED (see below).
+# INSTALL_CONF - A command to install configuration files. Not normally called
+# by ports directly, use CONF_FILES (see below).
#
# Boolean to control whether manpages are installed.
#
@@ -971,6 +973,18 @@
# MTREE_FILE - The name of the mtree file.
# Default: ${PORTSDIR}/Templates/BSD.local.dist or
# /etc/mtree/BSD.usr.dist if ${PREFIX} == "/usr".
+# CONF_FILES - A list of "absolute_path/src_file:relative_path/[dest_file]"
+# tuples of configuration files this package should install
+# as sample files (extension .pkgconf). "absolute_path" is
+# usually ${WRKSRC}/path_to_conf_file, and "src_file" can be
+# a filename or sh glob. If "dest_file" is omitted, the
+# trailing slash is non-optional, and the filename is taken from
+# "src_file". If a glob is used in "src_file" then "dest_file"
+# should be omitted. The sample files are copied to conf files
+# if there is no existing conf file, and unchanged conf files
+# are removed on deinstall.
+# CONF_DIRS - Directories to be created to put config files in and
+# added to the packing list
# PLIST_DIRS - Directories to be added to packing list
# PLIST_DIRSTRY - Directories to be added to packing list and try to remove them.
# PLIST_FILES - Files and symbolic links to be added to packing list
@@ -2419,12 +2433,20 @@
_BINOWNGRP= -o ${BINOWN} -g ${BINGRP}
_SHROWNGRP= -o ${SHAREOWN} -g ${SHAREGRP}
_MANOWNGRP= -o ${MANOWN} -g ${MANGRP}
+_CONFOWNGRP= -o ${CONFOWN} -g ${CONFGRP}
.else
_BINOWNGRP=
_SHROWNGRP=
_MANOWNGRP=
+_CONFOWNGRP=
.endif
+# CONF* macros are only defined in recent versions; these
+# lines can be removed once 8.2-RELEASE is no longer supported.
+CONFOWN?= root
+CONFGRP?= wheel
+CONFMODE?= 644
+
# A few aliases for *-install targets
INSTALL_PROGRAM= \
${INSTALL} ${COPY} ${STRIP} ${_BINOWNGRP} -m ${BINMODE}
@@ -2438,6 +2460,8 @@
${INSTALL} ${COPY} ${_SHROWNGRP} -m ${SHAREMODE}
INSTALL_MAN= \
${INSTALL} ${COPY} ${_MANOWNGRP} -m ${MANMODE}
+INSTALL_CONF= \
+ ${INSTALL} ${COPY} ${_CONFOWNGRP} -m ${CONFMODE}
INSTALL_MACROS= BSD_INSTALL_PROGRAM="${INSTALL_PROGRAM}" \
BSD_INSTALL_LIB="${INSTALL_LIB}" \
@@ -4468,10 +4492,10 @@
pre-install-script generate-plist check-already-installed
_INSTALL_SUSEQ= check-umask install-mtree pre-su-install \
pre-su-install-script create-users-groups do-install \
- install-desktop-entries install-license install-rc-script \
- post-install post-install-script add-plist-info \
- add-plist-docs add-plist-examples add-plist-data \
- add-plist-post fix-plist-sequence compress-man \
+ install-desktop-entries install-license install-conf-files \
+ install-rc-script post-install post-install-script \
+ add-plist-info add-plist-docs add-plist-examples \
+ add-plist-data add-plist-post fix-plist-sequence compress-man \
install-ldconfig-file fake-pkg security-check
_PACKAGE_DEP= install
_PACKAGE_SEQ= package-message pre-package pre-package-script \
@@ -5973,6 +5997,46 @@
.endif
.endif
+.if !target(install-conf-files)
+install-conf-files:
+. if defined(CONF_FILES)
+ @${ECHO_MSG} "===> Installing configuration file(s)"
+ @${ECHO_CMD} "@cwd ${PREFIX}" >> ${TMPPLIST}
+. if defined(CONF_DIRS)
+. for dir in ${CONF_DIRS}
+ @${MKDIR} ${dir}
+. endfor
+. endif
+. for confs in ${CONF_FILES}
+ CONF_FILES_SRC=$$(${ECHO_CMD} \
+ "${confs}" | ${SED} -E -e 's,([^: ]*).*,\1,') ; \
+ CONF_FILES_DEST=$$(${ECHO_CMD} \
+ "${confs}" | ${SED} -E -e 's,([^: ]*):([^: ]*),\2,') ; \
+ for src in $${CONF_FILES_SRC} ; \
+ do \
+ [ -z $${CONF_FILES_DEST##*/} ] \
+ && dest=$${CONF_FILES_DEST}$${src##*/} \
+ || dest=$${CONF_FILES_DEST} ; \
+ ${INSTALL_DATA} $${src} ${PREFIX}/$${dest}.pkgconf ; \
+ [ ! -f ${PREFIX}/$${dest} ] \
+ && ${INSTALL_CONF} ${PREFIX}/$${dest}.pkgconf \
+ ${PREFIX}/$${dest} ; \
+ ${ECHO_CMD} "@unexec cmp -s %D/$${dest}.pkgconf %D/$${dest} \
+ && ${RM} -f %D/$${dest}" >> ${TMPPLIST} ; \
+ ${ECHO_CMD} "$${dest}.pkgconf" >> ${TMPPLIST} ; \
+ ${ECHO_CMD} "@exec [ ! -f %D/$${dest} ] \
+ && ${INSTALL_CONF} %D/%F %B/$${dest}" >> ${TMPPLIST} ; \
+ done
+. endfor
+. if defined(CONF_DIRS_
+. for dir in ${CONF_DIRS}
+ @${ECHO_CMD} "@unexec rmdir %D/${dir} 2>/dev/null || true" \
+ >> ${TMPPLIST}
+. endfor
+. endif
+. endif
+.endif
+
.if !target(install-rc-script)
install-rc-script:
.if defined(USE_RCORDER) || defined(USE_RC_SUBR) && ${USE_RC_SUBR:U} != "YES"
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-ports-bugs
mailing list