aboutsummaryrefslogtreecommitdiff
path: root/buildtools
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2013-04-24 21:59:34 +0000
committerRob Austein <sra@hactrn.net>2013-04-24 21:59:34 +0000
commit63778293fffbaa50f175da2d652d85a8ff3da832 (patch)
tree6635f2abdf0a436bc21ab9246b36bf7dd5e1bd8a /buildtools
parentd0730928332f23d1d7e7fe81246667225d5de656 (diff)
Add pbuilder script to repository.
svn path=/trunk/; revision=5309
Diffstat (limited to 'buildtools')
-rw-r--r--buildtools/rpki-pbuilder.crontab1
-rw-r--r--buildtools/rpki-pbuilder.py116
2 files changed, 117 insertions, 0 deletions
diff --git a/buildtools/rpki-pbuilder.crontab b/buildtools/rpki-pbuilder.crontab
new file mode 100644
index 00000000..b81a0901
--- /dev/null
+++ b/buildtools/rpki-pbuilder.crontab
@@ -0,0 +1 @@
+*/10 * * * * /usr/bin/python $HOME/rpki-pbuilder.py > $HOME/rpki-pbuilder.$$.log 2>&1; if test -s $HOME/rpki-pbuilder.$$.log; then /bin/mv -f $HOME/rpki-pbuilder.$$.log $HOME/rpki-pbuilder.log; else /bin/rm -f $HOME/rpki-pbuilder.$$.log; fi
diff --git a/buildtools/rpki-pbuilder.py b/buildtools/rpki-pbuilder.py
new file mode 100644
index 00000000..5683d95e
--- /dev/null
+++ b/buildtools/rpki-pbuilder.py
@@ -0,0 +1,116 @@
+#!/usr/bin/python
+#
+# $Id$
+#
+# Copyright (C) 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
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+# PERFORMANCE OF THIS SOFTWARE.
+
+import os
+import sys
+import time
+import fcntl
+import errno
+import subprocess
+
+debug = False
+
+def run(*args, **kwargs):
+ if debug:
+ log("Would have run %r %r" % (args, kwargs))
+ else:
+ subprocess.check_call(args, **kwargs)
+
+def log(msg):
+ # Maybe this should go to syslog instead, but this works for now.
+ sys.stdout.write(time.strftime("%Y-%m-%dT%H:%M:%SZ ", time.gmtime()))
+ sys.stdout.write(msg)
+ sys.stdout.write("\n")
+ sys.stdout.flush()
+
+lockfile = os.path.expanduser("~/builder.lock")
+svn_tree = os.path.expanduser("~/source/trunk/")
+apt_tree = os.path.expanduser("~/repository/")
+ubu_tree = os.path.join(apt_tree, "ubuntu/")
+deb_tree = os.path.join(apt_tree, "debian/")
+srv_path = "aptbot@download.rpki.net:/usr/local/www/data/download.rpki.net/APT/"
+
+try:
+ lock = os.open(lockfile, os.O_RDONLY | os.O_CREAT | os.O_NONBLOCK, 0666)
+ fcntl.flock(lock, fcntl.LOCK_EX | fcntl.LOCK_NB)
+except (IOError, OSError), e:
+ sys.exit(0 if e.errno == errno.EAGAIN else "Error %r opening lock %r" % lockfile)
+
+os.chdir(svn_tree)
+
+run("svn", "--quiet", "update")
+
+version = subprocess.check_output(("svnversion", "-c")).strip().split(":")[-1]
+
+if not version.isdigit():
+ sys.exit("Sources don't look pristine, not building (%r)" % version)
+
+version = "0." + version
+
+dsc = os.path.join(svn_tree, "..", "rpki_%s.dsc" % version)
+
+if not os.path.exists(dsc):
+ log("Building source package %s" % version)
+ for fn in os.listdir(".."):
+ if fn != "trunk":
+ os.unlink(os.path.join("..", fn))
+ run("rm", "-rf", "debian")
+ run("python", "buildtools/build-ubuntu-ports.py")
+ run("dpkg-buildpackage", "-S", "-us", "-uc", "-rfakeroot")
+
+env = dict(os.environ,
+ OTHERMIRROR = "deb http://download.rpki.net/APT/ubuntu precise main")
+
+for dist, arch, tag in (("precise", "amd64", ""),
+ ("precise", "i386", "-i386")):
+
+ basedir = os.path.expanduser("~/pbuilder/%s%s-base.tgz" % (dist, tag))
+ result = os.path.expanduser("~/pbuilder/%s%s_result" % (dist, tag))
+ changes = os.path.join(result, "rpki_%s_%s.changes" % (version, arch))
+
+ # Update the build environment if it's been more than a week since
+ # we last did that. If this turns out to be error-prone, we might
+ # want to put it in a cron job of its own so it doesn't crash the
+ # normal cycle, but let's try it this way for a start.
+ #
+ if time.time() > os.stat(basedir).st_mtime + (7 * 24 * 60 * 60):
+ log("Updating build environment %s %s" % (dist, arch))
+ run("pbuilder-dist", dist, arch, "update",
+ env = env)
+
+ if not os.path.exists(changes):
+ # The need for --ignore=wrongdistribution may indicate
+ # something I'm doing wrong in hack-debian-changelog.py,
+ # revisit that later. For now, just whack with a stick.
+ #
+ log("Building binary packages %s %s %s" % (dist, arch, version))
+ for fn in os.listdir(result):
+ os.unlink(os.path.join(result, fn))
+ run("pbuilder-dist", dist, arch, "build", dsc,
+ env = env)
+ run("reprepro", "--ignore=wrongdistribution", "include", dist, changes,
+ cwd = ubu_tree)
+
+run("rsync", "-ai4",
+ "--ignore-existing",
+ apt_tree, srv_path)
+run("rsync", "-ai4",
+ "--exclude", "HEADER.html",
+ "--exclude", "HEADER.css",
+ "--delete", "--delete-delay",
+ apt_tree, srv_path)