Skip to content

Commit

Permalink
Framework: add keyword support for sample/shadow like in core
Browse files Browse the repository at this point in the history
  • Loading branch information
fichtner committed Dec 7, 2023
1 parent 111564a commit bbec7f3
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 3 deletions.
57 changes: 57 additions & 0 deletions Keywords/sample.ucl
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# MAINTAINER: [email protected]
#
# @sample etc/somefile.conf.sample
# or
# @sample file1 file2
#
# Where file1 is considered as a sample file and file2 the target file
#
# 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(1)]
arguments: true
post-install: <<EOD
case "%1" in
/*) sample_file="%1" ;;
*) sample_file="%D/%1" ;;
esac
target_file="${sample_file%.sample}"
set -- %@
if [ $# -eq 2 ]; then
target_file=${2}
fi
case "${target_file}" in
/*) target_file="${target_file}" ;;
*) target_file="%D/${target_file}" ;;
esac
if ! [ -f "${target_file}" ]; then
/bin/cp -p "${sample_file}" "${target_file}"
fi
EOD
pre-deinstall: <<EOD
case "%1" in
/*) sample_file="%1" ;;
*) sample_file="%D/%1" ;;
esac
target_file="${sample_file%.sample}"
set -- %@
if [ $# -eq 2 ]; then
set -- %@
target_file=${2}
fi
case "${target_file}" in
/*) target_file="${target_file}" ;;
*) target_file="%D/${target_file}" ;;
esac
if cmp -s "${target_file}" "${sample_file}"; then
rm -f "${target_file}"
fi
EOD
48 changes: 48 additions & 0 deletions Keywords/shadow.ucl
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# MAINTAINER: [email protected]
#
# @shadow etc/somefile.conf.sample
# or
# @shadow file1 file2
#
# Where file1 is considered as a sample file and file2 the target file
#
# This will install the somefile.conf.sample and automatically copy to
# somefile.conf if it doesn't exist. On deinstall it will be removed.

actions: [file(1)]
arguments: true
post-install: <<EOD
case "%1" in
/*) sample_file="%1" ;;
*) sample_file="%D/%1" ;;
esac
target_file="${sample_file%.sample}"
set -- %@
if [ $# -eq 2 ]; then
target_file=${2}
fi
case "${target_file}" in
/*) target_file="${target_file}" ;;
*) target_file="%D/${target_file}" ;;
esac
if ! [ -f "${target_file}" ]; then
/bin/cp -p "${sample_file}" "${target_file}"
fi
EOD
pre-deinstall: <<EOD
case "%1" in
/*) sample_file="%1" ;;
*) sample_file="%D/%1" ;;
esac
target_file="${sample_file%.sample}"
set -- %@
if [ $# -eq 2 ]; then
set -- %@
target_file=${2}
fi
case "${target_file}" in
/*) target_file="${target_file}" ;;
*) target_file="%D/${target_file}" ;;
esac
rm -f "${target_file}"
EOD
17 changes: 14 additions & 3 deletions Mk/plugins.mk
Original file line number Diff line number Diff line change
Expand Up @@ -210,15 +210,26 @@ install: check
if [ "$${FILE%%.in}" != "$${FILE}" ]; then \
sed -i '' ${SED_REPLACE} "${DESTDIR}${LOCALBASE}/$${FILE}"; \
mv "${DESTDIR}${LOCALBASE}/$${FILE}" "${DESTDIR}${LOCALBASE}/$${FILE%%.in}"; \
FILE="$${FILE%%.in}"; \
fi; \
if [ "$${FILE%%.shadow}" != "$${FILE}" ]; then \
mv "${DESTDIR}${LOCALBASE}/$${FILE}" \
"${DESTDIR}${LOCALBASE}/$${FILE%%.shadow}.sample"; \
fi; \
done
@cat ${TEMPLATESDIR}/version | sed ${SED_REPLACE} > "${DESTDIR}${LOCALBASE}/opnsense/version/${PLUGIN_NAME}"

plist: check
@(cd ${.CURDIR}/src 2> /dev/null && find * -type f) | while read FILE; do \
if [ -f "$${FILE}.in" ]; then continue; fi; \
FILE="$${FILE%%.in}"; \
echo ${LOCALBASE}/$${FILE}; \
FILE="$${FILE%%.in}"; PREFIX=""; \
if [ "$${FILE%%.sample}" != "$${FILE}" ]; then \
PREFIX="@sample "; \
elif [ "$${FILE%%.shadow}" != "$${FILE}" ]; then \
FILE="$${FILE%%.shadow}.sample"; \
PREFIX="@shadow "; \
fi; \
echo "$${PREFIX}${LOCALBASE}/$${FILE}"; \
done
@echo "${LOCALBASE}/opnsense/version/${PLUGIN_NAME}"

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

upgrade-check: check
Expand Down

0 comments on commit bbec7f3

Please sign in to comment.