diff --git a/server/module_lib/icon_lib.py b/server/module_lib/icon_lib.py index c015dd9..f60691b 100644 --- a/server/module_lib/icon_lib.py +++ b/server/module_lib/icon_lib.py @@ -46,7 +46,9 @@ class IconModule(object): self.ExecChroot('ldconfig') def InstallPackages(self, *packages): - self.ExecChroot('apt-get', 'install', '--assume-yes', '--no-install-recommends', *packages) + env = os.environ.copy() + env['DEBIAN_FRONTEND'] = 'noninteractive' + self.ExecChroot('apt-get', 'install', '--assume-yes', '--no-install-recommends', *packages, env=env) def InstallPythonPackages(self, *packages): self.InstallPackages('python-pip') diff --git a/server/modules/adduser.py b/server/modules/adduser.py index 23f0bfd..576a5fd 100755 --- a/server/modules/adduser.py +++ b/server/modules/adduser.py @@ -3,7 +3,8 @@ import argparse import os import shutil -import subprocess + +import icon_lib parser = argparse.ArgumentParser(description='iconograph adduser') @@ -28,18 +29,10 @@ parser.add_argument( FLAGS = parser.parse_args() -def Exec(*args, **kwargs): - print('+', args) - subprocess.check_call(args, **kwargs) - - -def ExecChroot(*args, **kwargs): - Exec('chroot', FLAGS.chroot_path, *args, **kwargs) - - def main(): - ExecChroot('adduser', '--system', '--group', '--disabled-password', - '--shell=/bin/bash', FLAGS.username) + module = icon_lib.IconModule(FLAGS.chroot_path) + module.ExecChroot('adduser', '--system', '--group', '--disabled-password', + '--shell=/bin/bash', FLAGS.username) if FLAGS.sudo: with open(os.path.join(FLAGS.chroot_path, 'etc', 'sudoers.d', FLAGS.username), 'w') as fh: @@ -50,7 +43,7 @@ def main(): dest_path = os.path.join(dest_dir, 'authorized_keys') os.mkdir(dest_dir) shutil.copy(FLAGS.authorized_keys_file, dest_path) - ExecChroot('chown', '--recursive', '%s:%s' % (FLAGS.username, FLAGS.username), '/home/%s' % FLAGS.username) + module.ExecChroot('chown', '--recursive', '%s:%s' % (FLAGS.username, FLAGS.username), '/home/%s' % FLAGS.username) if __name__ == '__main__': diff --git a/server/modules/autoimage.py b/server/modules/autoimage.py index 2b7ad81..441f1af 100755 --- a/server/modules/autoimage.py +++ b/server/modules/autoimage.py @@ -5,6 +5,8 @@ import os import shutil import subprocess +import icon_lib + parser = argparse.ArgumentParser(description='iconograph autoimage') parser.add_argument( @@ -56,26 +58,14 @@ parser.add_argument( FLAGS = parser.parse_args() -def Exec(*args, **kwargs): - print('+', args) - subprocess.check_call(args, **kwargs) - - -def ExecChroot(*args, **kwargs): - Exec('chroot', FLAGS.chroot_path, *args, **kwargs) - - def main(): - ExecChroot( - 'apt-get', - 'install', - '--assume-yes', - 'git', 'grub-pc', 'python3-openssl', 'python3-requests') + module = icon_lib.IconModule(FLAGS.chroot_path) + module.InstallPackages('git', 'grub-pc', 'python3-openssl', 'python3-requests') os.makedirs(os.path.join(FLAGS.chroot_path, 'icon', 'config'), exist_ok=True) if not os.path.exists(os.path.join(FLAGS.chroot_path, 'icon', 'iconograph')): - ExecChroot( + module.ExecChroot( 'git', 'clone', 'https://github.com/robot-tools/iconograph.git', diff --git a/server/modules/certclient.py b/server/modules/certclient.py index 847414c..85b2c4c 100755 --- a/server/modules/certclient.py +++ b/server/modules/certclient.py @@ -5,6 +5,8 @@ import os import shutil import subprocess +import icon_lib + parser = argparse.ArgumentParser(description='iconograph autoimage') parser.add_argument( @@ -45,33 +47,21 @@ parser.add_argument( FLAGS = parser.parse_args() -def Exec(*args, **kwargs): - print('+', args) - subprocess.check_call(args, **kwargs) - - -def ExecChroot(*args, **kwargs): - Exec('chroot', FLAGS.chroot_path, *args, **kwargs) - - def main(): - ExecChroot( - 'apt-get', - 'install', - '--assume-yes', - 'git', 'python3-requests', 'openssl') + module = icon_lib.IconModule(FLAGS.chroot_path) + module.InstallPackages('git', 'python3-requests', 'openssl') os.makedirs(os.path.join(FLAGS.chroot_path, 'icon', 'config'), exist_ok=True) if not os.path.exists(os.path.join(FLAGS.chroot_path, 'icon', 'iconograph')): - ExecChroot( + module.ExecChroot( 'git', 'clone', 'https://github.com/robot-tools/iconograph.git', 'icon/iconograph') if not os.path.exists(os.path.join(FLAGS.chroot_path, 'icon', 'certserver')): - ExecChroot( + module.ExecChroot( 'git', 'clone', 'https://github.com/robot-tools/certserver.git', diff --git a/server/modules/iconograph.py b/server/modules/iconograph.py index 7527ee8..e60045a 100755 --- a/server/modules/iconograph.py +++ b/server/modules/iconograph.py @@ -5,6 +5,8 @@ import os import shutil import subprocess +import icon_lib + parser = argparse.ArgumentParser(description='iconograph install module') parser.add_argument( @@ -29,27 +31,16 @@ parser.add_argument( FLAGS = parser.parse_args() -def Exec(*args, **kwargs): - print('+', args) - subprocess.check_call(args, **kwargs) - - -def ExecChroot(*args, **kwargs): - Exec('chroot', FLAGS.chroot_path, *args, **kwargs) - - def main(): - ExecChroot( - 'apt-get', - 'install', - '--assume-yes', + module = icon_lib.IconModule(FLAGS.chroot_path) + module.InstallPackages( 'daemontools-run', 'genisoimage', 'git', 'python3-openssl', 'python3-requests', 'python3-ws4py') os.makedirs(os.path.join(FLAGS.chroot_path, 'icon', 'config'), exist_ok=True) if not os.path.exists(os.path.join(FLAGS.chroot_path, 'icon', 'iconograph')): - ExecChroot( + module.ExecChroot( 'git', 'clone', 'https://github.com/robot-tools/iconograph.git', diff --git a/server/modules/openssh.py b/server/modules/openssh.py index 2643cd9..7917659 100755 --- a/server/modules/openssh.py +++ b/server/modules/openssh.py @@ -3,7 +3,8 @@ import argparse import glob import os -import subprocess + +import icon_lib parser = argparse.ArgumentParser(description='iconograph openssh') @@ -15,21 +16,9 @@ parser.add_argument( FLAGS = parser.parse_args() -def Exec(*args, **kwargs): - print('+', args) - subprocess.check_call(args, **kwargs) - - -def ExecChroot(*args, **kwargs): - Exec('chroot', FLAGS.chroot_path, *args, **kwargs) - - def main(): - ExecChroot( - 'apt-get', - 'install', - '--assume-yes', - 'openssh-server') + module = icon_lib.IconModule(FLAGS.chroot_path) + module.InstallPackages('openssh-server') for path in glob.glob(os.path.join(FLAGS.chroot_path, 'etc', 'ssh', 'ssh_host_*')): os.unlink(path)