aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2013-04-06 06:05:08 +0000
committerRob Austein <sra@hactrn.net>2013-04-06 06:05:08 +0000
commitbab399d245e12d1eb91b0fd1d166d500b93802c1 (patch)
tree5cacdb2c2482b81bd1c91ffc2dea1661691dee51
parent734c17faf9023fcdb63203c4a0eeffbe4adfcce4 (diff)
Teach setup.py how to install scripts in more than one directory, move
some of the scripts to ${libexecdir} where they probably should have been all along. Teach rpki-start-servers to use rpki.autoconf to determine where the daemon scripts live. svn path=/trunk/; revision=5287
-rw-r--r--buildtools/debian-skeleton/rpki-ca.postinst2
-rw-r--r--buildtools/debian-skeleton/rpki-rp.postinst5
-rw-r--r--rpkid/Makefile.in8
-rwxr-xr-xrpkid/rpki-start-servers25
-rw-r--r--rpkid/setup.py212
5 files changed, 159 insertions, 93 deletions
diff --git a/buildtools/debian-skeleton/rpki-ca.postinst b/buildtools/debian-skeleton/rpki-ca.postinst
index 8b93c2bd..35c77cf7 100644
--- a/buildtools/debian-skeleton/rpki-ca.postinst
+++ b/buildtools/debian-skeleton/rpki-ca.postinst
@@ -96,7 +96,7 @@ setup_django() {
setup_cron() {
t=$(hexdump -n 1 -e '"%u"' /dev/urandom) && echo "$(($t % 60)) */2 * * * nobody /usr/share/rpki/routeviews.sh" > /etc/cron.d/rpkigui-routeviews
chmod 644 /etc/cron.d/rpkigui-routeviews
- ln -sf /usr/sbin/rpkigui-check-expired /etc/cron.daily/rpkigui-check-expired
+ ln -sf /usr/lib/rpki/rpkigui-check-expired /etc/cron.daily/rpkigui-check-expired
}
# summary of how this script can be called:
diff --git a/buildtools/debian-skeleton/rpki-rp.postinst b/buildtools/debian-skeleton/rpki-rp.postinst
index 63720f13..46ef8b97 100644
--- a/buildtools/debian-skeleton/rpki-rp.postinst
+++ b/buildtools/debian-skeleton/rpki-rp.postinst
@@ -40,7 +40,10 @@ setup_rcynic_cron() {
}
setup_rpki_rtr_listener() {
- killall -HUP xinetd
+ if test -f /var/run/xinetd.pid
+ then
+ kill -HUP `cat /var/run/xinetd.pid`
+ fi
}
# summary of how this script can be called:
diff --git a/rpkid/Makefile.in b/rpkid/Makefile.in
index 17635389..8f4d5991 100644
--- a/rpkid/Makefile.in
+++ b/rpkid/Makefile.in
@@ -177,7 +177,7 @@ clean::
rpki/autoconf.py: Makefile
@echo 'Generating $@'; \
(echo '# Automatically generated. DO NOT EDIT.'; \
- echo 'bindir = "${bindir}"'; \
+ echo 'bindir = "${bindir}"'; \
echo 'datarootdir = "${datarootdir}"'; \
echo 'localstatedir = "${localstatedir}"'; \
echo 'sbindir = "${sbindir}"'; \
@@ -192,9 +192,9 @@ clean::
setup_autoconf.py: rpki/autoconf.py
@echo 'Generating $@'; \
(cat rpki/autoconf.py; \
- echo 'CFLAGS = """${CFLAGS}"""'; \
- echo 'LDFLAGS = """${LDFLAGS}"""'; \
- echo 'LIBS = """${LIBS}"""'; \
+ echo 'CFLAGS = """${CFLAGS}"""'; \
+ echo 'LDFLAGS = """${LDFLAGS}"""'; \
+ echo 'LIBS = """${LIBS}"""'; \
) > $@
clean::
diff --git a/rpkid/rpki-start-servers b/rpkid/rpki-start-servers
index 3babfd1c..d92a4f1f 100755
--- a/rpkid/rpki-start-servers
+++ b/rpkid/rpki-start-servers
@@ -6,7 +6,7 @@ which servers the user wants started.
$Id$
-Copyright (C) 2009--2012 Internet Systems Consortium ("ISC")
+Copyright (C) 2009--2013 Internet Systems Consortium ("ISC")
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
@@ -36,17 +36,22 @@ PERFORMANCE OF THIS SOFTWARE.
"""
-import subprocess, os, getopt, sys, time, rpki.config
-
-rpkid_dir = os.path.normpath(sys.path[0])
+import subprocess
+import os
+import getopt
+import sys
+import time
+import rpki.config
+import rpki.autoconf
os.environ["TZ"] = "UTC"
time.tzset()
cfg_file = None
-debug = False
+debug = False
+log_dir = "."
-opts, argv = getopt.getopt(sys.argv[1:], "c:dhp:?", ["config=", "debug" "help"])
+opts, argv = getopt.getopt(sys.argv[1:], "c:dhp:?", ["config=", "debug" "help", "logdir="])
for o, a in opts:
if o in ("-h", "--help", "-?"):
print __doc__
@@ -55,15 +60,19 @@ for o, a in opts:
cfg_file = a
elif o in ("-d", "--debug"):
debug = True
+ elif o == "--logdir":
+ log_dir = a
cfg = rpki.config.parser(cfg_file, "myrpki")
def run(name):
# pylint: disable=E1103
- cmd = (sys.executable, os.path.join(rpkid_dir, name), "-c", cfg.filename)
+ cmd = (os.path.join(rpki.autoconf.libexecdir, name), "-c", cfg.filename)
if debug:
- proc = subprocess.Popen(cmd + ("-d",), stdout = open(name + ".log", "a"), stderr = subprocess.STDOUT)
+ proc = subprocess.Popen(cmd + ("-d",),
+ stdout = open(os.path.join(log_dir, name + ".log"), "a"),
+ stderr = subprocess.STDOUT)
else:
proc = subprocess.Popen(cmd)
if debug and proc.poll() is None:
diff --git a/rpkid/setup.py b/rpkid/setup.py
index fa52695f..859f8aeb 100644
--- a/rpkid/setup.py
+++ b/rpkid/setup.py
@@ -15,22 +15,29 @@
# PERFORMANCE OF THIS SOFTWARE.
from distutils.core import setup, Extension
+from distutils.util import change_root, convert_path
+from distutils.command.build_scripts import build_scripts as _build_scripts
+from distutils.command.install_scripts import install_scripts as _install_scripts
+from distutils import log
+from stat import S_IMODE
import os
-# We can't build POW without these settings, but allow them to be null
-# so that things like "python setup.py --help" will work.
-
try:
- import setup_autoconf
- ac_cflags = setup_autoconf.CFLAGS.split()
- ac_ldflags = setup_autoconf.LDFLAGS.split()
- ac_libs = setup_autoconf.LIBS.split()
- ac_sbindir = setup_autoconf.sbindir
- ac_libexecdir = setup_autoconf.libexecdir
- ac_datarootdir = os.path.join(setup_autoconf.datarootdir, "rpki")
- ac_sysconfdir = os.path.join(setup_autoconf.sysconfdir, "rpki")
+ # Import settings derived from autoconf tests and configuration.
+ #
+ import setup_autoconf as autoconf
+ ac_cflags = autoconf.CFLAGS.split()
+ ac_ldflags = autoconf.LDFLAGS.split()
+ ac_libs = autoconf.LIBS.split()
+ ac_sbindir = autoconf.sbindir
+ ac_libexecdir = autoconf.libexecdir
+ ac_datarootdir = os.path.join(autoconf.datarootdir, "rpki")
+ ac_sysconfdir = os.path.join(autoconf.sysconfdir, "rpki")
except ImportError:
+ # We can't build POW without the autoconf settings, but we allow them
+ # to be absent when running things like "python setup.py --help".
+ #
ac_cflags = ()
ac_ldflags = ()
ac_libs = ()
@@ -39,79 +46,126 @@ except ImportError:
ac_datarootdir = None
ac_sysconfdir = None
-# Scripts and data files, moved here from Makefile.in.
-
-ac_scripts = [
- "rpki-sql-backup",
- "rpki-sql-setup",
- "rpki-start-servers",
- "irbe_cli",
- "irdbd",
- "pubd",
- "rootd",
- "rpkic",
- "rpkid",
- "rpki-confgen",
- "portal-gui/scripts/rpkigui-import-routes",
- "portal-gui/scripts/rpkigui-check-expired",
- "portal-gui/scripts/rpkigui-rcynic",
- "portal-gui/scripts/rpki-manage" ]
-
-ac_aux_scripts = []
-
-ac_data_files = []
-
-ac_conf_files = [
- "portal-gui/apache.conf",
- "rpki-confgen.xml" ]
-
-# Non-standard extension build specification: we need to force
-# whatever build options our top-level ./configure selected, and we
-# have to specify our libraries as extra_link_args because they may be
-# complete pathnames to .a files elsewhere in the build tree. Most of
-# this insanity is to kludge around pre-existing OpenSSL libraries
-# that would screw up our build without these gymnastics.
+class build_scripts(_build_scripts):
+ """
+ Hacked version of distutils.build_scripts, designed to support
+ multiple target installation directories like install_data does.
-# pylint: disable=W0622
+ [(target_directory, [list_of_source_scripts]), ...]
-pow = Extension("rpki.POW._POW", ["ext/POW.c"],
- extra_compile_args = ac_cflags,
- extra_link_args = ac_ldflags + ac_libs)
+ Most of the real work is in the companion hacked install_scripts,
+ but we need to tweak the list of source files that build_scripts
+ pulls out of the Distribution object.
+ """
-# Be careful constructing data_files, empty file lists here appear to
-# confuse setup into putting dangerous nonsense into the list of
-# installed files.
-#
-# bdist_rpm seems to get confused by relative names for scripts, so we
-# have to prefix source names here with the build directory name. Well,
-# if we care about bdist_rpm, which it now looks like we don't, but
-# leave it alone for the moment.
-
-data_files = []
-if ac_sbindir and ac_scripts:
- data_files.append((ac_sbindir, [os.path.abspath(f) for f in ac_scripts]))
-if ac_libexecdir and ac_aux_scripts:
- data_files.append((ac_libexecdir, [os.path.abspath(f) for f in ac_aux_scripts]))
-if ac_datarootdir and ac_data_files:
- data_files.append((ac_datarootdir, [os.path.abspath(f) for f in ac_data_files]))
-if ac_sysconfdir and ac_conf_files:
- data_files.append((ac_sysconfdir, [os.path.abspath(f) for f in ac_conf_files]))
-if not data_files:
- data_files = None
+ def finalize_options(self):
+ _build_scripts.finalize_options(self)
+ self.scripts = []
+ for script in self.distribution.scripts:
+ if isinstance(script, str):
+ self.scripts.append(script)
+ else:
+ self.scripts.extend(script[1])
+
+class install_scripts(_install_scripts):
+ """
+ Hacked version of distutils.install_scripts, designed to support
+ multiple target installation directories like install_data does.
+
+ [(target_directory, [list_of_source_scripts]), ...]
+
+ The code here is a tweaked combination of what the stock
+ install_scripts and install_data classes do.
+ """
+
+ user_options = _install_scripts.user_options + [
+ ("root=", None, "install everything relative to this alternate root directory")]
+
+ def initialize_options(self):
+ _install_scripts.initialize_options(self)
+ self.outfiles = []
+ self.root = None
+
+ def finalize_options (self):
+ self.set_undefined_options("build",
+ ("build_scripts", "build_dir"))
+ self.set_undefined_options("install",
+ ("install_scripts", "install_dir"),
+ ("root", "root"),
+ ("force", "force"),
+ ("skip_build", "skip_build"))
+
+ def run(self):
+ if not self.skip_build:
+ self.run_command("build_scripts")
+ for script in self.distribution.scripts:
+ if isinstance(script, str):
+ fn = os.path.join(self.build_dir, os.path.basename(convert_path(script)))
+ out, _ = self.copy_file(fn, self.install_dir)
+ self.outfiles.append(out)
+ else:
+ dn = convert_path(script[0])
+ if not os.path.isabs(dn):
+ dn = os.path.join(self.install_dir, dn)
+ elif self.root:
+ dn = change_root(self.root, dn)
+ self.mkpath(dn)
+ if not script[1]:
+ self.outfiles.append(dn)
+ else:
+ for s in script[1]:
+ fn = os.path.join(self.build_dir, os.path.basename(convert_path(s)))
+ out, _ = self.copy_file(fn, dn)
+ self.outfiles.append(out)
+ if os.name == "posix":
+ for fn in self.get_outputs():
+ mode = S_IMODE(os.stat(fn).st_mode) | 0555
+ log.info("changing mode of %s to %o", fn, mode)
+ if not self.dry_run:
+ os.chmod(fn, mode)
+
+# pylint: disable=W0622
setup(name = "rpkitoolkit",
version = "1.0",
description = "RPKI Toolkit",
license = "BSD",
- url = "http://www.rpki.net/",
- packages = ["rpki", "rpki.POW", "rpki.irdb",
- "rpki.gui", "rpki.gui.app", "rpki.gui.cacheview",
- "rpki.gui.api", "rpki.gui.routeview" ],
- ext_modules = [pow],
- package_data = {
- 'rpki.gui.app': ['migrations/*.py', 'static/*/*',
- 'templates/*.html', 'templates/*/*.html',
- 'templatetags/*.py'],
- 'rpki.gui.cacheview': ['templates/*/*.html']
- },
- data_files = data_files)
+ url = "http://rpki.net/",
+ cmdclass = {"build_scripts" : build_scripts,
+ "install_scripts" : install_scripts},
+ packages = ["rpki",
+ "rpki.POW",
+ "rpki.irdb",
+ "rpki.gui",
+ "rpki.gui.app",
+ "rpki.gui.cacheview",
+ "rpki.gui.api",
+ "rpki.gui.routeview"],
+ ext_modules = [Extension("rpki.POW._POW", ["ext/POW.c"],
+ extra_compile_args = ac_cflags,
+ extra_link_args = ac_ldflags + ac_libs)],
+ package_data = {"rpki.gui.app" : ["migrations/*.py",
+ "static/*/*",
+ "templates/*.html",
+ "templates/*/*.html",
+ "templatetags/*.py"],
+ "rpki.gui.cacheview" : ["templates/*/*.html"]},
+ scripts = [(ac_sbindir,
+ ["rpkic",
+ "rpki-confgen",
+ "rpki-start-servers",
+ "rpki-sql-backup",
+ "rpki-sql-setup",
+ "portal-gui/scripts/rpki-manage",
+ "irbe_cli"]),
+ (ac_libexecdir,
+ ["irdbd",
+ "pubd",
+ "rootd",
+ "rpkid",
+ "portal-gui/scripts/rpkigui-import-routes",
+ "portal-gui/scripts/rpkigui-check-expired",
+ "portal-gui/scripts/rpkigui-rcynic"])],
+ data_files = [(ac_sysconfdir,
+ ["portal-gui/apache.conf",
+ "rpki-confgen.xml"])])