Bug 157168 - [bsd.port.mk] New hook: CONF_FILES automatically handles configuration files
Summary: [bsd.port.mk] New hook: CONF_FILES automatically handles configuration files
Status: Closed Works As Intended
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Ports Framework (show other bugs)
Version: Latest
Hardware: Any Any
: Normal Affects Only Me
Assignee: Port Management Team
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-18 21:20 UTC by Chris Rees
Modified: 2014-06-02 08:14 UTC (History)
1 user (show)

See Also:


Attachments
file.diff (4.85 KB, patch)
2011-05-18 21:20 UTC, Chris Rees
no flags Details | Diff
patch.txt (4.86 KB, text/plain; charset=US-ASCII)
2011-06-03 20:34 UTC, Chris Rees
no flags Details
patch.txt (4.87 KB, text/plain; charset=US-ASCII)
2011-06-25 11:56 UTC, Chris Rees
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Rees 2011-05-18 21:20:12 UTC
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!

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@gmail.com)

Patch attached with submission follows:
Comment 1 Tilman Keskinoz freebsd_committer freebsd_triage 2011-05-21 19:16:49 UTC
Responsible Changed
From-To: freebsd-ports-bugs->portmgr

Over to bsd.port.mk maintainers
Comment 2 Chris Rees 2011-06-03 20:30:20 UTC
Silly me... I forgot to put || true at the end of the @unexec line put
into TMPPLIST, which would cause errors on deinstall if the conf file
had been customised.

Likewise, I've rearranged the [ ! -f ] && into [ -f ] || for the same reason.

Chris
Comment 3 Chris Rees 2011-06-03 20:34:43 UTC
On 3 June 2011 20:30, Chris Rees <utisoft@gmail.com> wrote:
> Silly me... I forgot to put || true at the end of the @unexec line put
> into TMPPLIST, which would cause errors on deinstall if the conf file
> had been customised.
>
> Likewise, I've rearranged the [ ! -f ] && into [ -f ] || for the same reason.
>
> Chris
>

Bunch of fail that I am today, I forgot to attach the patch :(

Chris
Comment 4 Chris Rees freebsd_committer freebsd_triage 2011-06-12 08:57:12 UTC
Ok, I've been thinking about this again.

It's great having the automated install of the .sample file, but how
about as well we have another form of usage:

CONF_FILES=  etc/${FILE_INSTALLED_BY_AUTOCONF}.sample

without the colon tuples? Otherwise we're going to be patching every
configure.ac and CMakeLists.txt under the Sun...

We could use CONF_FILES:M*\:* and CONF_FILES:N*\:* to separate them,
and code slightly differently for each case...

Or should I do away with the automated installation part altogether
and just have the CONF_FILES write the plist code and copy the sample
files over instead?

Example proposed usage:

<pre>

CONF_FILES= etc/${PORTNAME}.conf.sample

do-install:
      ${BLAH}
      ${INSTALL_DATA} ${WRKSRC}/${PORTNAME}.conf
${PREFIX}/etc/${PORTNAME}.conf.sample

</pre>

The CONF_FILES bit would still deal with copying over the sample and
pkg-plist guff.

Does that make any sense at all?

Is that a better way to approach it?

Chris
Comment 5 Chris Rees freebsd_committer freebsd_triage 2011-06-25 11:56:51 UTC
After a little more discussion on IRC, I've done away with the
colon-separated tuples -- overcomplicated.

The result is something like MAN and PORTDOCS (indeed most of the code
is stolen from PORTDOCS).

This means that shell globs, filenames and directories are specified
in CONF_FILES, but the sample file is installed in the Makefile as
.pkgconf.

Examples for MailScanner [1] show how it can replace huge trees of
config files, and for portscout [2] shows how it is used for just one
file.

Look at how much has been removed from the MailScanner plist and
pkg-*install.in files -- there are three screens of unused functions
that could also be chopped out now too!

Chris

[1] http://people.freebsd.org/~crees/patches/mailscanner-conf-files.diff
[2] http://people.freebsd.org/~crees/patches/portscout-conf-files.diff
Comment 6 Chris Rees freebsd_committer freebsd_triage 2011-06-25 12:36:56 UTC
Forwarded munged message --hopefully it won't do that this time.

On 25 June 2011 11:56, Chris Rees <crees@freebsd.org> wrote:
> After a little more discussion on IRC, I've done away with the
> colon-separated tuples -- overcomplicated.
>
> The result is something like MAN and PORTDOCS (indeed most of the code
> is stolen from PORTDOCS).
>
> This means that shell globs, filenames and directories are specified
> in CONF_FILES, but the sample file is installed in the Makefile as
> .pkgconf.
>
> Examples for MailScanner [1] show how it can replace huge trees of
> config files, and for portscout [2] shows how it is used for just one
> file.
>
> Look at how much has been removed from the MailScanner plist and
> pkg-*install.in files -- there are three screens of unused functions
> that could also be chopped out now too!
>
> Chris
>
> [1] http://people.freebsd.org/~crees/patches/mailscanner-conf-files.diff
> [2] http://people.freebsd.org/~crees/patches/portscout-conf-files.diff
>
Comment 7 dfilter service freebsd_committer freebsd_triage 2014-04-12 04:39:08 UTC
Author: bdrewery
Date: Sat Apr 12 03:39:02 2014
New Revision: 351064
URL: http://svnweb.freebsd.org/changeset/ports/351064
QAT: https://qat.redports.org/buildarchive/r351064/

Log:
  - Add a @sample plist keyword
  
    It accepts a file (must end in .sample, this is not configurable):
  
      @sample file.conf.sample
  
    This will install file.conf.sample and copy it to file.conf. The file.conf
    will be removed if it matches file.conf.sample on deinstall.
  
    This replaces older patterns of:
  
      @unexec if cmp -s %D/etc/pkgtools.conf %D/etc/pkgtools.conf.sample; then rm -f %D/etc/pkgtools.conf; fi
      etc/pkgtools.conf.sample
      @exec [ -f %B/pkgtools.conf ] || cp %B/%f %B/pkgtools.conf
  
    [1] This somewhat obsoletes work in ports/157168 which added CONF_FILES,
        but we have been moving towards more logic in pkg-plist where possible
        and less magical macros. Though this thinking does clash with autoplist
        ideas. We may still want CONF_FILES, which just drops a list of
        @sample entries into the plist anyway.
  - Add a Keywords/pkg_install.awk and hook it into generate-plist. This is
    for pkg_install compatibility since it does not know how to read
    Keywords/sample.yaml.
    This file gives us a strategy to implement more keywords before
    pkg_install is EOL.
    Keywords are documented here:
    https://github.com/freebsd/pkg/commit/bffc31420b1fd6146a43c9abcd45109dd901198a
  - This needs to be documented in PH and portlint support added still.
  
  PR:		ports/157168 [1]
  Discussed with:	bapt
  Reviewed by:	bapt
  Requested by:	many
  With hat:	portmgr

Added:
  head/Keywords/pkg_install.awk   (contents, props changed)
  head/Keywords/sample.yaml   (contents, props changed)
Modified:
  head/CHANGES
  head/Mk/bsd.port.mk

Modified: head/CHANGES
==============================================================================
--- head/CHANGES	Sat Apr 12 03:26:25 2014	(r351063)
+++ head/CHANGES	Sat Apr 12 03:39:02 2014	(r351064)
@@ -10,6 +10,23 @@ in the release notes and/or placed into 
 
 All ports committers are allowed to commit to this file.
 
+20140411:
+AUTHOR: bdrewery@FreeBSD.org
+
+  A new plist keyword has been added, @sample. It accepts a file (must end in
+  .sample):
+
+    @sample file.conf.sample
+
+  This will install file.conf.sample and copy it to file.conf. The file.conf
+  will be removed if it matches file.conf.sample on deinstall.
+
+  This replaces older patterns of:
+
+    @unexec if cmp -s %D/etc/pkgtools.conf %D/etc/pkgtools.conf.sample; then rm -f %D/etc/pkgtools.conf; fi
+    etc/pkgtools.conf.sample
+    @exec [ -f %B/pkgtools.conf ] || cp %B/%f %B/pkgtools.conf
+
 20140312:
 AUTHOR: bapt@FreeBSD.org
 

Added: head/Keywords/pkg_install.awk
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/Keywords/pkg_install.awk	Sat Apr 12 03:39:02 2014	(r351064)
@@ -0,0 +1,31 @@
+# $FreeBSD$
+#
+# MAINTAINER: portmgr@FreeBSD.org
+#
+# This file handles converting keywords to pkg_install compatible format.
+# It will be removed once pkg_install is EOL.
+#
+
+#  @sample somefile.conf.sample
+# ->
+#  @comment begin @sample somefile.conf.sample
+#  @unexec if cmp -s %D/etc/somefile.conf %D/etc/somefile.conf.sample; then rm -f %D/etc/somefile.conf; fi
+#  etc/somefile.conf.sample
+#  @exec if ! [ -f %D/etc/somefile.conf ]; then cp %D/etc/somefile.conf.sample %D/etc/somefile.conf; fi
+#  @comment end @sample somefile.conf.sample
+# 
+$1 == "@sample" {
+  sample_file=$2
+  # Take out .sample
+  target_file=substr(sample_file, 0, length(sample_file) - 7)
+  print "@comment begin " $0
+  print "@unexec if cmp -s '%D/" target_file "' '%D/" sample_file "'; then rm -f '%D/" target_file "'; fi"
+  print sample_file
+  print "@exec if ! [ -f '%D/" target_file "' ]; then /bin/cp -p '%D/" sample_file "' '%D/" target_file "'; fi"
+  print "@comment end " $0
+  next
+}
+# Print everything else as-is
+{
+  print $0
+}

Added: head/Keywords/sample.yaml
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/Keywords/sample.yaml	Sat Apr 12 03:39:02 2014	(r351064)
@@ -0,0 +1,29 @@
+# $FreeBSD$
+#
+# MAINTAINER: portmgr@FreeBSD.org
+#
+# @sample etc/somefile.conf.sample
+#
+# This will install the somefile.conf.sample and automatically copy to
+# somefile.conf if it doesn't exist. On deinstall it will remove the
+# somefile.conf if it still matches the sample, otherwise it is
+# kept.
+#
+# This replaces the old pattern:
+#  @unexec if cmp -s %D/etc/pkgtools.conf %D/etc/pkgtools.conf.sample; then rm -f %D/etc/pkgtools.conf; fi
+#  etc/pkgtools.conf.sample
+#  @exec [ -f %B/pkgtools.conf ] || cp %B/%f %B/pkgtools.conf
+
+actions: [file]
+post-install: |
+  sample_file="%D/%@"
+  target_file="${sample_file%.sample}"
+  if ! [ -f "${target_file}" ]; then
+    /bin/cp -p "${sample_file}" "${target_file}"
+  fi
+pre-deinstall: |
+  sample_file="%D/%@"
+  target_file="${sample_file%.sample}"
+  if cmp -s "${target_file}" "${sample_file}"; then
+    rm -f "${target_file}"
+  fi

Modified: head/Mk/bsd.port.mk
==============================================================================
--- head/Mk/bsd.port.mk	Sat Apr 12 03:26:25 2014	(r351063)
+++ head/Mk/bsd.port.mk	Sat Apr 12 03:39:02 2014	(r351064)
@@ -1405,6 +1405,7 @@ ETCDIR?=		${PREFIX}/etc/${PORTNAME}
 
 PACKAGES?=		${PORTSDIR}/packages
 TEMPLATES?=		${PORTSDIR}/Templates
+KEYWORDS?=		${PORTSDIR}/Keywords
 
 PATCHDIR?=		${MASTERDIR}/files
 FILESDIR?=		${MASTERDIR}/files
@@ -5625,6 +5626,8 @@ generate-plist:
 .endif
 .if !defined(WITH_PKGNG)
 	@cd ${.CURDIR} && { ${MAKE} pretty-print-config | fold -sw 120 | ${SED} -e 's/^/@comment OPTIONS:/'; } >> ${TMPPLIST}
+	@${AWK} -f ${KEYWORDS}/pkg_install.awk ${TMPPLIST} > ${TMPPLIST}.keyword && \
+	    ${MV} -f ${TMPPLIST}.keyword ${TMPPLIST}
 .endif
 .endif
 
_______________________________________________
svn-ports-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-ports-all
To unsubscribe, send any mail to "svn-ports-all-unsubscribe@freebsd.org"
Comment 8 Mark Linimon freebsd_committer freebsd_triage 2014-06-02 03:00:00 UTC
Committed 20140412.