First effort at doing make like variable expansion so we don't have to patch when file locations change

This commit is contained in:
Scott Kitterman
2019-04-25 00:50:23 -04:00
parent 0b522ca4d1
commit ae8b17c0ce
2 changed files with 107 additions and 0 deletions
+54
View File
@@ -0,0 +1,54 @@
#!/sbin/openrc-run
# Copyright 1999-2019 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
CONFFILE="@SYSCONFDIR@/${RC_SVCNAME}.conf"
required_files="${CONFFILE}"
command="@SBINDIR@/dkimpy-milter"
pidfile="@RUNSTATEDIR@/${RC_SVCNAME}.pid"
command_args="-P ${pidfile} -x ${CONFFILE}"
extra_commands="checkconfig"
depend() {
use dns logger net
before mta
}
checkconfig() {
#
# The dkimpy-milter.conf man page says,
#
# For parameters that are Boolean in nature, only the first byte
# of the value is processed... For negative values, the following
# are accepted: "F", "f", "N", "n", "0".'
#
if @GREP@ '^[[:space:]]*Background[[:space:]]\+[FfNn0]' "${CONFFILE}" \
>/dev/null 2>&1; then
eend 1 "${RC_SVCNAME} cannot run in the foreground!"
fi
if ! "${command}" -n "${command_args}"; then
eend 1 "${RC_SVCNAME} configuration check failed"
fi
}
start_pre() {
# If this isn't a restart, make sure that the user's config isn't
# busted before we try to start the daemon (this will produce
# better error messages than if we just try to start it blindly).
#
# If, on the other hand, this *is* a restart, then the stop_pre
# action will have ensured that the config is usable and we don't
# need to do that again.
if [ "${RC_CMD}" != "restart" ]; then
checkconfig || return $?
fi
}
stop_pre() {
# If this is a restart, check to make sure the user's config
# isn't busted before we stop the running daemon.
if [ "${RC_CMD}" = "restart" ]; then
checkconfig || return $?
fi
}
+53
View File
@@ -17,10 +17,60 @@
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.""" 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA."""
from setuptools import setup from setuptools import setup
import distutils.cmd
import distutils.log
import sys
import os import os
import subprocess
description = "Domain Keys Identified Mail (DKIM) signing/verifying milter for Postfix/Sendmail." description = "Domain Keys Identified Mail (DKIM) signing/verifying milter for Postfix/Sendmail."
class FileMacroExpand(distutils.cmd.Command):
description = "Expand @@ variables in input files, simlar to make macros."
user_options = [
('sysconfigdir=', 'e', 'Specify configuration directory. [/usr/local/etc]'),
('sbindir=', 's', 'Specify system binary directory. [/usr/local/sbin]'),
('bindir=', 'b', 'Specify binary directory. [/usr/loca/bin]'),
('rundir=', 'r', 'Specify run state directory. [/run]'),
]
def initialize_options(self):
self.sysconfigdir = '/usr/local/etc'
self.sbindir = '/usr/local/sbin'
self.bindir = '/usr/local/bin'
self.rundir = '/run'
# For this option, we find the system grep, wherever it is and use it,
# no override provided.
self.grep = subprocess.check_output(["which", "grep"]).decode()[:-1]
def finalize_options(self):
pass
def run(self):
files = ['etc/dkimpy-milter.openrc',]
for infile in files:
outfile = ''
filein = open(infile + '.in')
for line in filein:
for function in ["@SYSCONFDIR@", "@SBINDIR@", "@BINDIR@", "@RUNSTATEDIR@", "@GREP@"]:
splitline = line.split(function)
if len(splitline) > 1:
if function == "@SYSCONFDIR@":
line = splitline[0] + self.sysconfigdir + splitline[1]
elif function == "@SBINDIR@":
line = splitline[0] + self.sbindir + splitline[1]
elif function == "@BINDIR@":
line = splitline[0] + self.bindir + splitline[1]
elif function == "@RUNSTATEDIR@":
line = splitline[0] + self.rundir + splitline[1]
elif function == "@GREP@":
line = splitline[0] + self.grep + splitline[1]
outfile += line
out = open(infile, 'w')
for line in outfile:
out.write(line)
out.close()
kw = {} # Work-around for lack of 'or' requires in setuptools. kw = {} # Work-around for lack of 'or' requires in setuptools.
try: try:
import dns import dns
@@ -62,5 +112,8 @@ setup(
['system/dkimpy-milter.service']),(os.path.join('etc', 'init.d'), ['system/dkimpy-milter.service']),(os.path.join('etc', 'init.d'),
['system/dkimpy-milter'])], ['system/dkimpy-milter'])],
zip_safe = False, zip_safe = False,
cmdclass={
'expand': FileMacroExpand,
},
**kw **kw
) )