aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbdrewery <bdrewery@FreeBSD.org>2014-04-12 11:39:02 +0800
committerbdrewery <bdrewery@FreeBSD.org>2014-04-12 11:39:02 +0800
commit39e2243ab529e4b7a16e7f4906892b155afd5a73 (patch)
treeb5235113da17195fc36663198e7440dd31ce2cc8
parent7687f0c989b1baac6fb46a477dae6aace752f3b8 (diff)
downloadfreebsd-ports-gnome-39e2243ab529e4b7a16e7f4906892b155afd5a73.tar.gz
freebsd-ports-gnome-39e2243ab529e4b7a16e7f4906892b155afd5a73.tar.zst
freebsd-ports-gnome-39e2243ab529e4b7a16e7f4906892b155afd5a73.zip
- 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
-rw-r--r--CHANGES17
-rw-r--r--Keywords/pkg_install.awk31
-rw-r--r--Keywords/sample.yaml29
-rw-r--r--Mk/bsd.port.mk3
4 files changed, 80 insertions, 0 deletions
diff --git a/CHANGES b/CHANGES
index 775711b976cd..87135b4c8c95 100644
--- a/CHANGES
+++ b/CHANGES
@@ -10,6 +10,23 @@ in the release notes and/or placed into UPDATING.
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
diff --git a/Keywords/pkg_install.awk b/Keywords/pkg_install.awk
new file mode 100644
index 000000000000..e4207d744d03
--- /dev/null
+++ b/Keywords/pkg_install.awk
@@ -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
+}
diff --git a/Keywords/sample.yaml b/Keywords/sample.yaml
new file mode 100644
index 000000000000..4d56793acca1
--- /dev/null
+++ b/Keywords/sample.yaml
@@ -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
diff --git a/Mk/bsd.port.mk b/Mk/bsd.port.mk
index 8dc8076284b7..4e3f3c9cd3c1 100644
--- a/Mk/bsd.port.mk
+++ b/Mk/bsd.port.mk
@@ -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