Move internal modules to icon_lib
This commit is contained in:
@@ -46,7 +46,9 @@ class IconModule(object):
|
|||||||
self.ExecChroot('ldconfig')
|
self.ExecChroot('ldconfig')
|
||||||
|
|
||||||
def InstallPackages(self, *packages):
|
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):
|
def InstallPythonPackages(self, *packages):
|
||||||
self.InstallPackages('python-pip')
|
self.InstallPackages('python-pip')
|
||||||
|
|||||||
@@ -3,7 +3,8 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
|
||||||
|
import icon_lib
|
||||||
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description='iconograph adduser')
|
parser = argparse.ArgumentParser(description='iconograph adduser')
|
||||||
@@ -28,18 +29,10 @@ parser.add_argument(
|
|||||||
FLAGS = parser.parse_args()
|
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():
|
def main():
|
||||||
ExecChroot('adduser', '--system', '--group', '--disabled-password',
|
module = icon_lib.IconModule(FLAGS.chroot_path)
|
||||||
'--shell=/bin/bash', FLAGS.username)
|
module.ExecChroot('adduser', '--system', '--group', '--disabled-password',
|
||||||
|
'--shell=/bin/bash', FLAGS.username)
|
||||||
|
|
||||||
if FLAGS.sudo:
|
if FLAGS.sudo:
|
||||||
with open(os.path.join(FLAGS.chroot_path, 'etc', 'sudoers.d', FLAGS.username), 'w') as fh:
|
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')
|
dest_path = os.path.join(dest_dir, 'authorized_keys')
|
||||||
os.mkdir(dest_dir)
|
os.mkdir(dest_dir)
|
||||||
shutil.copy(FLAGS.authorized_keys_file, dest_path)
|
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__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import os
|
|||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
import icon_lib
|
||||||
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description='iconograph autoimage')
|
parser = argparse.ArgumentParser(description='iconograph autoimage')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
@@ -56,26 +58,14 @@ parser.add_argument(
|
|||||||
FLAGS = parser.parse_args()
|
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():
|
def main():
|
||||||
ExecChroot(
|
module = icon_lib.IconModule(FLAGS.chroot_path)
|
||||||
'apt-get',
|
module.InstallPackages('git', 'grub-pc', 'python3-openssl', 'python3-requests')
|
||||||
'install',
|
|
||||||
'--assume-yes',
|
|
||||||
'git', 'grub-pc', 'python3-openssl', 'python3-requests')
|
|
||||||
|
|
||||||
os.makedirs(os.path.join(FLAGS.chroot_path, 'icon', 'config'), exist_ok=True)
|
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')):
|
if not os.path.exists(os.path.join(FLAGS.chroot_path, 'icon', 'iconograph')):
|
||||||
ExecChroot(
|
module.ExecChroot(
|
||||||
'git',
|
'git',
|
||||||
'clone',
|
'clone',
|
||||||
'https://github.com/robot-tools/iconograph.git',
|
'https://github.com/robot-tools/iconograph.git',
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import os
|
|||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
import icon_lib
|
||||||
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description='iconograph autoimage')
|
parser = argparse.ArgumentParser(description='iconograph autoimage')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
@@ -45,33 +47,21 @@ parser.add_argument(
|
|||||||
FLAGS = parser.parse_args()
|
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():
|
def main():
|
||||||
ExecChroot(
|
module = icon_lib.IconModule(FLAGS.chroot_path)
|
||||||
'apt-get',
|
module.InstallPackages('git', 'python3-requests', 'openssl')
|
||||||
'install',
|
|
||||||
'--assume-yes',
|
|
||||||
'git', 'python3-requests', 'openssl')
|
|
||||||
|
|
||||||
os.makedirs(os.path.join(FLAGS.chroot_path, 'icon', 'config'), exist_ok=True)
|
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')):
|
if not os.path.exists(os.path.join(FLAGS.chroot_path, 'icon', 'iconograph')):
|
||||||
ExecChroot(
|
module.ExecChroot(
|
||||||
'git',
|
'git',
|
||||||
'clone',
|
'clone',
|
||||||
'https://github.com/robot-tools/iconograph.git',
|
'https://github.com/robot-tools/iconograph.git',
|
||||||
'icon/iconograph')
|
'icon/iconograph')
|
||||||
|
|
||||||
if not os.path.exists(os.path.join(FLAGS.chroot_path, 'icon', 'certserver')):
|
if not os.path.exists(os.path.join(FLAGS.chroot_path, 'icon', 'certserver')):
|
||||||
ExecChroot(
|
module.ExecChroot(
|
||||||
'git',
|
'git',
|
||||||
'clone',
|
'clone',
|
||||||
'https://github.com/robot-tools/certserver.git',
|
'https://github.com/robot-tools/certserver.git',
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import os
|
|||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
import icon_lib
|
||||||
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description='iconograph install module')
|
parser = argparse.ArgumentParser(description='iconograph install module')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
@@ -29,27 +31,16 @@ parser.add_argument(
|
|||||||
FLAGS = parser.parse_args()
|
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():
|
def main():
|
||||||
ExecChroot(
|
module = icon_lib.IconModule(FLAGS.chroot_path)
|
||||||
'apt-get',
|
module.InstallPackages(
|
||||||
'install',
|
|
||||||
'--assume-yes',
|
|
||||||
'daemontools-run', 'genisoimage', 'git', 'python3-openssl',
|
'daemontools-run', 'genisoimage', 'git', 'python3-openssl',
|
||||||
'python3-requests', 'python3-ws4py')
|
'python3-requests', 'python3-ws4py')
|
||||||
|
|
||||||
os.makedirs(os.path.join(FLAGS.chroot_path, 'icon', 'config'), exist_ok=True)
|
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')):
|
if not os.path.exists(os.path.join(FLAGS.chroot_path, 'icon', 'iconograph')):
|
||||||
ExecChroot(
|
module.ExecChroot(
|
||||||
'git',
|
'git',
|
||||||
'clone',
|
'clone',
|
||||||
'https://github.com/robot-tools/iconograph.git',
|
'https://github.com/robot-tools/iconograph.git',
|
||||||
|
|||||||
@@ -3,7 +3,8 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import glob
|
import glob
|
||||||
import os
|
import os
|
||||||
import subprocess
|
|
||||||
|
import icon_lib
|
||||||
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description='iconograph openssh')
|
parser = argparse.ArgumentParser(description='iconograph openssh')
|
||||||
@@ -15,21 +16,9 @@ parser.add_argument(
|
|||||||
FLAGS = parser.parse_args()
|
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():
|
def main():
|
||||||
ExecChroot(
|
module = icon_lib.IconModule(FLAGS.chroot_path)
|
||||||
'apt-get',
|
module.InstallPackages('openssh-server')
|
||||||
'install',
|
|
||||||
'--assume-yes',
|
|
||||||
'openssh-server')
|
|
||||||
|
|
||||||
for path in glob.glob(os.path.join(FLAGS.chroot_path, 'etc', 'ssh', 'ssh_host_*')):
|
for path in glob.glob(os.path.join(FLAGS.chroot_path, 'etc', 'ssh', 'ssh_host_*')):
|
||||||
os.unlink(path)
|
os.unlink(path)
|
||||||
|
|||||||
Reference in New Issue
Block a user