Xenial updates for autoimage and certclient

This commit is contained in:
Ian Gulliver
2016-08-09 05:04:44 +00:00
parent 5defa222d6
commit d94c305fa8
3 changed files with 109 additions and 120 deletions

View File

@@ -1,43 +0,0 @@
#!/usr/bin/python3
import argparse
import sys
import time
parser = argparse.ArgumentParser(description='iconograph wait_for_service')
parser.add_argument(
'--type',
dest='type',
action='store',
choices={'happy', 'angry'},
required=True)
FLAGS = parser.parse_args()
def Happy():
yield '\a'
time.sleep(3.0)
def Angry():
yield '\a'
time.sleep(0.2)
_TYPES = {
'happy': Happy,
'angry': Angry,
}
def main():
handler = _TYPES[FLAGS.type]
while True:
for item in handler():
sys.stdout.write(item)
sys.stdout.flush()
if __name__ == '__main__':
main()

View File

@@ -99,14 +99,23 @@ def main():
'--https-client-key', os.path.join('/', https_client_key_path), '--https-client-key', os.path.join('/', https_client_key_path),
]) ])
init = os.path.join(FLAGS.chroot_path, 'etc', 'init', 'autoimage.conf') tags = {
with open(init, 'w') as fh: 'device': FLAGS.device,
fh.write(""" 'persistent_percent': FLAGS.persistent_percent,
description "AutoImage" 'server': FLAGS.server,
'image_type': FLAGS.image_type,
'image_flags': ' '.join(image_flags),
}
start on runlevel [2345] tool_path = os.path.join(FLAGS.chroot_path, 'icon', 'autoimage-%(image_type)s' % tags)
os.makedirs(tool_path, exist_ok=True)
script = os.path.join(tool_path, 'startup.sh')
with open(script, 'w') as fh:
os.fchmod(fh.fileno(), 0o755)
fh.write("""\
#!/bin/bash
script
exec </dev/tty8 >/dev/tty8 2>&1 exec </dev/tty8 >/dev/tty8 2>&1
chvt 8 chvt 8
/icon/iconograph/client/wait_for_service.py --host=%(server)s --service=https /icon/iconograph/client/wait_for_service.py --host=%(server)s --service=https
@@ -118,16 +127,22 @@ script
echo "==================" echo "=================="
echo "autoimage complete" echo "autoimage complete"
echo "==================" echo "=================="
""" % tags)
/icon/iconograph/client/alert.py --type=happy with module.ServiceFile('autoimage-%(image_type)s.service' % tags) as fh:
end script fh.write("""
""" % { [Unit]
'device': FLAGS.device, Description=AutoImage %(image_type)s
'persistent_percent': FLAGS.persistent_percent,
'server': FLAGS.server, [Service]
'image_type': FLAGS.image_type, Type=simple
'image_flags': ' '.join(image_flags), RemainAfterExit=yes
}) ExecStart=/icon/autoimage-%(image_type)s/startup.sh
[Install]
WantedBy=multi-user.target
""" % tags)
module.EnableService('autoimage-%(image_type)s.service' % tags)
if __name__ == '__main__': if __name__ == '__main__':

View File

@@ -8,7 +8,7 @@ import subprocess
import icon_lib import icon_lib
parser = argparse.ArgumentParser(description='iconograph autoimage') parser = argparse.ArgumentParser(description='iconograph certclient')
parser.add_argument( parser.add_argument(
'--chroot-path', '--chroot-path',
dest='chroot_path', dest='chroot_path',
@@ -87,14 +87,22 @@ def main():
os.path.join(FLAGS.chroot_path, client_key_path)) os.path.join(FLAGS.chroot_path, client_key_path))
os.chmod(os.path.join(FLAGS.chroot_path, client_key_path), 0o400) os.chmod(os.path.join(FLAGS.chroot_path, client_key_path), 0o400)
init = os.path.join(FLAGS.chroot_path, 'etc', 'init', 'certclient.%s.conf' % FLAGS.tag) tags = {
with open(init, 'w') as fh: 'dh': 'y' if FLAGS.generate_dh else 'n',
fh.write(""" 'server': FLAGS.server,
description "CertClient %(tag)s" 'subject': FLAGS.subject,
'tag': FLAGS.tag,
}
start on systemid-ready tool_path = os.path.join(FLAGS.chroot_path, 'icon', 'certclient-%(tag)s' % tags)
os.makedirs(tool_path, exist_ok=True)
script = os.path.join(tool_path, 'startup.sh')
with open(script, 'w') as fh:
os.chmod(fh.fileno(), 0o755)
fh.write("""\
#!/bin/bash
script
exec </dev/tty9 >/dev/tty9 2>&1 exec </dev/tty9 >/dev/tty9 2>&1
chvt 9 chvt 9
@@ -136,13 +144,22 @@ script
echo "==================" echo "=================="
echo "certclient %(tag)s complete" echo "certclient %(tag)s complete"
echo "==================" echo "=================="
end script """ % tags)
""" % {
'dh': 'y' if FLAGS.generate_dh else 'n', with module.ServiceFile('certclient-%(tag)s.service' % tags) as fh:
'server': FLAGS.server, fh.write("""
'subject': FLAGS.subject, [Unit]
'tag': FLAGS.tag, Description=CertClient %(tag)s
})
[Service]
Type=simple
RemainAfterExit=yes
ExecStart=/icon/certclient-%(tag)s/startup.sh
[Install]
WantedBy=multi-user.target
""" % tags)
module.EnableService('certclient-%(tag)s.service' % tags)
if __name__ == '__main__': if __name__ == '__main__':