Initial autoimage pass
This commit is contained in:
90
server/modules/autoimage.py
Executable file
90
server/modules/autoimage.py
Executable file
@@ -0,0 +1,90 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(description='iconograph autoimage')
|
||||||
|
parser.add_argument(
|
||||||
|
'--base-url',
|
||||||
|
dest='base_url',
|
||||||
|
action='store',
|
||||||
|
required=True)
|
||||||
|
parser.add_argument(
|
||||||
|
'--ca-cert',
|
||||||
|
dest='ca_cert',
|
||||||
|
action='store',
|
||||||
|
required=True)
|
||||||
|
parser.add_argument(
|
||||||
|
'--chroot-path',
|
||||||
|
dest='chroot_path',
|
||||||
|
action='store',
|
||||||
|
required=True)
|
||||||
|
parser.add_argument(
|
||||||
|
'--device',
|
||||||
|
dest='device',
|
||||||
|
action='store',
|
||||||
|
required=True)
|
||||||
|
parser.add_argument(
|
||||||
|
'--image-type',
|
||||||
|
dest='image_type',
|
||||||
|
action='store',
|
||||||
|
required=True)
|
||||||
|
parser.add_argument(
|
||||||
|
'--persistent-percent',
|
||||||
|
dest='persistent_percent',
|
||||||
|
action='store',
|
||||||
|
type=int,
|
||||||
|
default=0)
|
||||||
|
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-openssl')
|
||||||
|
|
||||||
|
ExecChroot(
|
||||||
|
'git',
|
||||||
|
'clone',
|
||||||
|
'https://github.com/robot-tools/iconograph.git',
|
||||||
|
'autoimage')
|
||||||
|
|
||||||
|
os.mkdir(os.path.join(FLAGS.chroot_path, 'autoimage', 'config'))
|
||||||
|
shutil.copyfile(
|
||||||
|
FLAGS.ca_cert,
|
||||||
|
os.path.join(FLAGS.chroot_path, 'autoimage', 'config', 'ca.cert.pem'))
|
||||||
|
|
||||||
|
init = os.path.join(FLAGS.chroot_path, 'etc', 'init', 'autoimage.conf')
|
||||||
|
with open(init, 'w') as fh:
|
||||||
|
fh.write("""
|
||||||
|
description "AutoImage"
|
||||||
|
|
||||||
|
start on filesystem
|
||||||
|
|
||||||
|
script
|
||||||
|
/autoimage/server/image.py --device=%(device)s --persistent-percent=%(persistent_percent)d --ca-cert=/autoimage/config/ca.cert.pem --image-type=%(image_type)s --base-url=%(base_url)s
|
||||||
|
end script
|
||||||
|
""" % {
|
||||||
|
'device': FLAGS.device,
|
||||||
|
'persistent_percent': FLAGS.persistent_percent,
|
||||||
|
'image_type': FLAGS.image_type,
|
||||||
|
'base_url': FLAGS.base_url,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
@@ -6,7 +6,7 @@ import shutil
|
|||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description='iconograph persistent')
|
parser = argparse.ArgumentParser(description='iconograph install module')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--base-url',
|
'--base-url',
|
||||||
dest='base_url',
|
dest='base_url',
|
||||||
|
|||||||
Reference in New Issue
Block a user