/usr/sbin/edubuntu-server-build-template is in edubuntu-server-host 14.02.2.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | #!/usr/bin/python3
# -*- coding: utf-8 -*-
# Copyright (C) 2012-2014 Stéphane Graber
# Author: Stéphane Graber <stgraber@ubuntu.com>
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You can find the license on Debian systems in the file
# /usr/share/common-licenses/GPL-2
# NOTE: To remove once the API is stabilized
import warnings
warnings.filterwarnings("ignore", "The python-lxc API isn't yet stable")
import argparse
import gettext
import glob
import os
import shutil
import subprocess
import sys
_ = gettext.gettext
gettext.textdomain("edubuntu-server-build-template")
# Some constants
LXC_LIB = "/var/lib/lxc/"
LXC_CACHE = "/var/cache/lxc/"
LXC_TEMPLATE = "tpl-edubuntu-server"
LXC_CONFIGURE = "/usr/share/edubuntu-server/template-configure"
# Begin parsing the command line
parser = argparse.ArgumentParser(
description=_("Edubuntu server template builder"),
formatter_class=argparse.RawTextHelpFormatter)
# Optional arguments
parser.add_argument("--cleanup", action="store_true",
help=_("Remove an existing template and start over."))
args = parser.parse_args()
# Basic requirements check
## The user needs to be uid 0
if not os.geteuid() == 0:
print(_("You must be root to run this script. Try running: sudo %s" %
(sys.argv[0])))
sys.exit(1)
# Only import lxc now so we don't need to build-depend on it for help2man
import lxc
for path in (LXC_LIB, LXC_CACHE):
if not os.path.exists(path):
print(_("%s doesn't exist." % path))
sys.exit(1)
# In cleanup mode, wipe the LXC cache and any existing template
if args.cleanup:
if os.path.exists("%s/%s" % (LXC_LIB, LXC_TEMPLATE)):
shutil.rmtree("%s/%s" % (LXC_LIB, LXC_TEMPLATE))
for entry in glob.glob("%s/*" % LXC_CACHE):
shutil.rmtree(entry)
# Check that the container doesn't exist
if os.path.exists("%s/%s" % (LXC_LIB, LXC_TEMPLATE)):
print(_("The template already exists."))
sys.exit(1)
# Create a basic container
template = lxc.Container(LXC_TEMPLATE)
if not template.create("ubuntu"):
print(_("Failed to create the base system."))
sys.exit(1)
# Run the configuration script
shutil.copy(LXC_CONFIGURE, "%s/%s/rootfs/configure"
% (LXC_LIB, LXC_TEMPLATE))
with open(os.devnull, "w") as fd:
configure = subprocess.Popen(["lxc-unshare",
"-s", "PID|MOUNT|IPC|UTSNAME",
"chroot", "%s/%s/rootfs/" %
(LXC_LIB, LXC_TEMPLATE),
"--", "/configure"],
stdout=fd, stderr=fd)
if configure.wait() != 0:
print(_("Failed to configure the template."))
sys.exit(1)
os.remove("%s/%s/rootfs/configure" % (LXC_LIB, LXC_TEMPLATE))
|