Skip to content

Commit bbec7f3

Browse files
committed
Framework: add keyword support for sample/shadow like in core
1 parent 111564a commit bbec7f3

File tree

3 files changed

+119
-3
lines changed

3 files changed

+119
-3
lines changed

Keywords/sample.ucl

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# MAINTAINER: [email protected]
2+
#
3+
# @sample etc/somefile.conf.sample
4+
# or
5+
# @sample file1 file2
6+
#
7+
# Where file1 is considered as a sample file and file2 the target file
8+
#
9+
# This will install the somefile.conf.sample and automatically copy to
10+
# somefile.conf if it doesn't exist. On deinstall it will remove the
11+
# somefile.conf if it still matches the sample, otherwise it is
12+
# kept.
13+
#
14+
# This replaces the old pattern:
15+
# @unexec if cmp -s %D/etc/pkgtools.conf %D/etc/pkgtools.conf.sample; then rm -f %D/etc/pkgtools.conf; fi
16+
# etc/pkgtools.conf.sample
17+
# @exec [ -f %B/pkgtools.conf ] || cp %B/%f %B/pkgtools.conf
18+
19+
actions: [file(1)]
20+
arguments: true
21+
post-install: <<EOD
22+
case "%1" in
23+
/*) sample_file="%1" ;;
24+
*) sample_file="%D/%1" ;;
25+
esac
26+
target_file="${sample_file%.sample}"
27+
set -- %@
28+
if [ $# -eq 2 ]; then
29+
target_file=${2}
30+
fi
31+
case "${target_file}" in
32+
/*) target_file="${target_file}" ;;
33+
*) target_file="%D/${target_file}" ;;
34+
esac
35+
if ! [ -f "${target_file}" ]; then
36+
/bin/cp -p "${sample_file}" "${target_file}"
37+
fi
38+
EOD
39+
pre-deinstall: <<EOD
40+
case "%1" in
41+
/*) sample_file="%1" ;;
42+
*) sample_file="%D/%1" ;;
43+
esac
44+
target_file="${sample_file%.sample}"
45+
set -- %@
46+
if [ $# -eq 2 ]; then
47+
set -- %@
48+
target_file=${2}
49+
fi
50+
case "${target_file}" in
51+
/*) target_file="${target_file}" ;;
52+
*) target_file="%D/${target_file}" ;;
53+
esac
54+
if cmp -s "${target_file}" "${sample_file}"; then
55+
rm -f "${target_file}"
56+
fi
57+
EOD

Keywords/shadow.ucl

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# MAINTAINER: [email protected]
2+
#
3+
# @shadow etc/somefile.conf.sample
4+
# or
5+
# @shadow file1 file2
6+
#
7+
# Where file1 is considered as a sample file and file2 the target file
8+
#
9+
# This will install the somefile.conf.sample and automatically copy to
10+
# somefile.conf if it doesn't exist. On deinstall it will be removed.
11+
12+
actions: [file(1)]
13+
arguments: true
14+
post-install: <<EOD
15+
case "%1" in
16+
/*) sample_file="%1" ;;
17+
*) sample_file="%D/%1" ;;
18+
esac
19+
target_file="${sample_file%.sample}"
20+
set -- %@
21+
if [ $# -eq 2 ]; then
22+
target_file=${2}
23+
fi
24+
case "${target_file}" in
25+
/*) target_file="${target_file}" ;;
26+
*) target_file="%D/${target_file}" ;;
27+
esac
28+
if ! [ -f "${target_file}" ]; then
29+
/bin/cp -p "${sample_file}" "${target_file}"
30+
fi
31+
EOD
32+
pre-deinstall: <<EOD
33+
case "%1" in
34+
/*) sample_file="%1" ;;
35+
*) sample_file="%D/%1" ;;
36+
esac
37+
target_file="${sample_file%.sample}"
38+
set -- %@
39+
if [ $# -eq 2 ]; then
40+
set -- %@
41+
target_file=${2}
42+
fi
43+
case "${target_file}" in
44+
/*) target_file="${target_file}" ;;
45+
*) target_file="%D/${target_file}" ;;
46+
esac
47+
rm -f "${target_file}"
48+
EOD

Mk/plugins.mk

+14-3
Original file line numberDiff line numberDiff line change
@@ -210,15 +210,26 @@ install: check
210210
if [ "$${FILE%%.in}" != "$${FILE}" ]; then \
211211
sed -i '' ${SED_REPLACE} "${DESTDIR}${LOCALBASE}/$${FILE}"; \
212212
mv "${DESTDIR}${LOCALBASE}/$${FILE}" "${DESTDIR}${LOCALBASE}/$${FILE%%.in}"; \
213+
FILE="$${FILE%%.in}"; \
214+
fi; \
215+
if [ "$${FILE%%.shadow}" != "$${FILE}" ]; then \
216+
mv "${DESTDIR}${LOCALBASE}/$${FILE}" \
217+
"${DESTDIR}${LOCALBASE}/$${FILE%%.shadow}.sample"; \
213218
fi; \
214219
done
215220
@cat ${TEMPLATESDIR}/version | sed ${SED_REPLACE} > "${DESTDIR}${LOCALBASE}/opnsense/version/${PLUGIN_NAME}"
216221

217222
plist: check
218223
@(cd ${.CURDIR}/src 2> /dev/null && find * -type f) | while read FILE; do \
219224
if [ -f "$${FILE}.in" ]; then continue; fi; \
220-
FILE="$${FILE%%.in}"; \
221-
echo ${LOCALBASE}/$${FILE}; \
225+
FILE="$${FILE%%.in}"; PREFIX=""; \
226+
if [ "$${FILE%%.sample}" != "$${FILE}" ]; then \
227+
PREFIX="@sample "; \
228+
elif [ "$${FILE%%.shadow}" != "$${FILE}" ]; then \
229+
FILE="$${FILE%%.shadow}.sample"; \
230+
PREFIX="@shadow "; \
231+
fi; \
232+
echo "$${PREFIX}${LOCALBASE}/$${FILE}"; \
222233
done
223234
@echo "${LOCALBASE}/opnsense/version/${PLUGIN_NAME}"
224235

@@ -269,7 +280,7 @@ package: check
269280
@${MAKE} DESTDIR=${WRKSRC} metadata
270281
@echo " done"
271282
@echo ">>> Packaging files for ${PLUGIN_PKGNAME}-${PLUGIN_PKGVERSION}:"
272-
@${PKG} create -v -m ${WRKSRC} -r ${WRKSRC} \
283+
@PORTSDIR=${PLUGINSDIR} ${PKG} create -v -m ${WRKSRC} -r ${WRKSRC} \
273284
-p ${WRKSRC}/plist -o ${PKGDIR}
274285

275286
upgrade-check: check

0 commit comments

Comments
 (0)