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),
])
init = os.path.join(FLAGS.chroot_path, 'etc', 'init', 'autoimage.conf')
with open(init, 'w') as fh:
fh.write("""
description "AutoImage"
tags = {
'device': FLAGS.device,
'persistent_percent': FLAGS.persistent_percent,
'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
chvt 8
/icon/iconograph/client/wait_for_service.py --host=%(server)s --service=https
@@ -118,16 +127,22 @@ script
echo "=================="
echo "autoimage complete"
echo "=================="
""" % tags)
/icon/iconograph/client/alert.py --type=happy
end script
""" % {
'device': FLAGS.device,
'persistent_percent': FLAGS.persistent_percent,
'server': FLAGS.server,
'image_type': FLAGS.image_type,
'image_flags': ' '.join(image_flags),
})
with module.ServiceFile('autoimage-%(image_type)s.service' % tags) as fh:
fh.write("""
[Unit]
Description=AutoImage %(image_type)s
[Service]
Type=simple
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__':

View File

@@ -8,7 +8,7 @@ import subprocess
import icon_lib
parser = argparse.ArgumentParser(description='iconograph autoimage')
parser = argparse.ArgumentParser(description='iconograph certclient')
parser.add_argument(
'--chroot-path',
dest='chroot_path',
@@ -87,14 +87,22 @@ def main():
os.path.join(FLAGS.chroot_path, client_key_path))
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)
with open(init, 'w') as fh:
fh.write("""
description "CertClient %(tag)s"
tags = {
'dh': 'y' if FLAGS.generate_dh else 'n',
'server': FLAGS.server,
'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
chvt 9
@@ -136,13 +144,22 @@ script
echo "=================="
echo "certclient %(tag)s complete"
echo "=================="
end script
""" % {
'dh': 'y' if FLAGS.generate_dh else 'n',
'server': FLAGS.server,
'subject': FLAGS.subject,
'tag': FLAGS.tag,
})
""" % tags)
with module.ServiceFile('certclient-%(tag)s.service' % tags) as fh:
fh.write("""
[Unit]
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__':