2016-04-05 13:45:24 -07:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
|
import os
|
|
|
|
|
|
2016-07-18 05:54:04 +00:00
|
|
|
import icon_lib
|
|
|
|
|
|
2016-04-05 13:45:24 -07:00
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(description='iconograph systemid')
|
|
|
|
|
parser.add_argument(
|
|
|
|
|
'--chroot-path',
|
|
|
|
|
dest='chroot_path',
|
|
|
|
|
action='store',
|
|
|
|
|
required=True)
|
|
|
|
|
FLAGS = parser.parse_args()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2016-07-18 05:54:04 +00:00
|
|
|
module = icon_lib.IconModule(FLAGS.chroot_path)
|
|
|
|
|
|
2016-04-05 13:45:24 -07:00
|
|
|
os.mkdir(os.path.join(FLAGS.chroot_path, 'systemid'))
|
|
|
|
|
|
2016-07-18 05:54:04 +00:00
|
|
|
tool_path = os.path.join(FLAGS.chroot_path, 'icon', 'systemid')
|
|
|
|
|
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
|
2017-03-30 14:39:45 -07:00
|
|
|
e2fsck -p LABEL=SYSTEMID
|
2016-07-18 05:54:04 +00:00
|
|
|
mount -o data=journal,noatime,sync LABEL=SYSTEMID /systemid
|
|
|
|
|
. /systemid/systemid
|
|
|
|
|
echo ${SYSTEMID} > /etc/hostname
|
|
|
|
|
hostname --file /etc/hostname
|
|
|
|
|
grep ${SYSTEMID} /etc/hosts >/dev/null || echo "127.0.2.1 ${SYSTEMID}" >> /etc/hosts
|
|
|
|
|
""")
|
|
|
|
|
|
2016-07-18 18:40:07 +00:00
|
|
|
with module.ServiceFile('systemid.service') as fh:
|
2016-07-18 05:54:04 +00:00
|
|
|
fh.write("""
|
|
|
|
|
[Unit]
|
|
|
|
|
Description=Mount /systemid and configure from it
|
|
|
|
|
DefaultDependencies=no
|
|
|
|
|
Conflicts=shutdown.target
|
|
|
|
|
After=systemd-remount-fs.service
|
|
|
|
|
Before=sysinit.target
|
|
|
|
|
|
|
|
|
|
[Service]
|
|
|
|
|
Type=oneshot
|
|
|
|
|
RemainAfterExit=yes
|
|
|
|
|
ExecStart=/icon/systemid/startup.sh
|
|
|
|
|
|
|
|
|
|
[Install]
|
|
|
|
|
WantedBy=sysinit.target
|
|
|
|
|
""")
|
2016-07-18 18:40:07 +00:00
|
|
|
module.EnableService('systemid.service')
|
|
|
|
|
|
2016-04-05 13:45:24 -07:00
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
main()
|