From 571b1a990ca925da63411cf5a37d0d7d9dc7a754 Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Thu, 31 Mar 2016 16:25:41 -0700 Subject: [PATCH] Persistent module working. --- server/build_image.py | 31 +++++++++++++++------------ server/chroot_files/persistent.conf | 11 ---------- server/image.py | 4 ++-- server/modules/persistent.py | 33 +++++++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 26 deletions(-) delete mode 100644 server/chroot_files/persistent.conf create mode 100755 server/modules/persistent.py diff --git a/server/build_image.py b/server/build_image.py index b04cd34..b097d6d 100755 --- a/server/build_image.py +++ b/server/build_image.py @@ -40,6 +40,10 @@ parser.add_argument( dest='image_type', action='store', required=True) +parser.add_argument( + '--module', + dest='modules', + nargs='*') parser.add_argument( '--release', dest='release', @@ -92,15 +96,11 @@ class ImageBuilder(object): '/etc/init.d/systemd-logind': '/bin/true', } - _CHROOT_COPIES = { - 'persistent.conf': 'etc/init/persistent.conf', - } - _ISO_COPIES = { 'loopback.cfg': 'boot/grub/loopback.cfg', } - def __init__(self, source_iso, dest_iso, archive, arch, release, ca_cert, base_url, image_type): + def __init__(self, source_iso, dest_iso, archive, arch, release, ca_cert, base_url, image_type, modules): self._source_iso = source_iso self._dest_iso = dest_iso self._archive = archive @@ -109,6 +109,7 @@ class ImageBuilder(object): self._ca_cert = ca_cert self._base_url = base_url self._image_type = image_type + self._modules = modules self._ico_server_path = os.path.dirname(sys.argv[0]) @@ -209,6 +210,15 @@ class ImageBuilder(object): 'apt-get', 'clean') + def _RunModules(self, chroot_path): + for module in self._modules: + self._Exec( + '%(module)s --chroot-path=%(chroot_path)s' % { + 'module': module, + 'chroot_path': chroot_path, + }, + shell=True) + def _RemoveDiversions(self, chroot_path): for source in self._DIVERSIONS: self._ExecChroot( @@ -223,12 +233,6 @@ class ImageBuilder(object): source) os.unlink(os.path.join(chroot_path, 'usr', 'sbin', 'policy-rc.d')) - def _CopyChrootFiles(self, chroot_path): - for source, dest in self._CHROOT_COPIES.items(): - shutil.copyfile( - os.path.join(self._ico_server_path, 'chroot_files', source), - os.path.join(chroot_path, dest)) - def _InstallIconograph(self, chroot_path): self._ExecChroot( chroot_path, @@ -292,8 +296,8 @@ class ImageBuilder(object): self._FixSourcesList(chroot_path) self._AddDiversions(chroot_path) self._InstallPackages(chroot_path) + self._RunModules(chroot_path) self._RemoveDiversions(chroot_path) - self._CopyChrootFiles(chroot_path) self._InstallIconograph(chroot_path) if FLAGS.shell: self._Exec('bash', cwd=root) @@ -322,7 +326,8 @@ def main(): FLAGS.release, FLAGS.ca_cert, FLAGS.base_url, - FLAGS.image_type) + FLAGS.image_type, + FLAGS.modules) builder.BuildImage() diff --git a/server/chroot_files/persistent.conf b/server/chroot_files/persistent.conf deleted file mode 100644 index 57d6cb3..0000000 --- a/server/chroot_files/persistent.conf +++ /dev/null @@ -1,11 +0,0 @@ -description "Mount /persistent" - -start on filesystem - -script - DEV=$(findfs LABEL=persistent) - if test "$?" = "0"; then - mkdir /persistent - mount "${DEV}" /persistent - fi -end script diff --git a/server/image.py b/server/image.py index 0899809..2f2632c 100755 --- a/server/image.py +++ b/server/image.py @@ -75,7 +75,7 @@ class Imager(object): time.sleep(1) # yuck self._Exec( 'mkfs.ext4', - '-L', 'boot', + '-L', 'BOOT', '-F', self._PartDev(1)) @@ -89,7 +89,7 @@ class Imager(object): time.sleep(1) # yuck self._Exec( 'mkfs.ext4', - '-L', 'persistent', + '-L', 'PERSISTENT', '-F', self._PartDev(2)) diff --git a/server/modules/persistent.py b/server/modules/persistent.py new file mode 100755 index 0000000..1b30e91 --- /dev/null +++ b/server/modules/persistent.py @@ -0,0 +1,33 @@ +#!/usr/bin/python3 + +import argparse +import os + + +parser = argparse.ArgumentParser(description='iconograph persistent') +parser.add_argument( + '--chroot-path', + dest='chroot_path', + action='store', + required=True) +FLAGS = parser.parse_args() + + +def main(): + os.mkdir(os.path.join(FLAGS.chroot_path, 'persistent')) + + init = os.path.join(FLAGS.chroot_path, 'etc', 'init', 'persistent.conf') + with open(init, 'w') as fh: + fh.write(""" +description "Mount /persistent" + +start on filesystem + +script + mount LABEL=PERSISTENT /persistent +end script +""") + + +if __name__ == '__main__': + main()