Files
iconograph/server/modules/persistent.py

58 lines
1.1 KiB
Python
Raw Normal View History

2016-03-31 16:25:41 -07:00
#!/usr/bin/python3
import argparse
import os
2016-07-18 18:40:07 +00:00
import icon_lib
2016-03-31 16:25:41 -07:00
parser = argparse.ArgumentParser(description='iconograph persistent')
parser.add_argument(
'--chroot-path',
dest='chroot_path',
action='store',
required=True)
FLAGS = parser.parse_args()
def main():
2016-07-18 18:40:07 +00:00
module = icon_lib.IconModule(FLAGS.chroot_path)
2016-03-31 16:25:41 -07:00
2016-07-18 18:40:07 +00:00
os.mkdir(os.path.join(FLAGS.chroot_path, 'persistent'))
2016-03-31 16:25:41 -07:00
2016-07-18 18:40:07 +00:00
tool_path = os.path.join(FLAGS.chroot_path, 'icon', 'persistent')
os.makedirs(tool_path, exist_ok=True)
2016-04-07 01:00:40 +00:00
2016-07-18 18:40:07 +00:00
script = os.path.join(tool_path, 'startup.sh')
with open(script, 'w') as fh:
os.chmod(fh.fileno(), 0o755)
fh.write("""\
#!/bin/bash
2016-11-19 12:39:06 -08:00
set -ex
2017-03-30 14:39:45 -07:00
e2fsck -y LABEL=PERSISTENT
mount -o noatime LABEL=PERSISTENT /persistent
2016-07-18 18:40:07 +00:00
""")
2016-03-31 16:25:41 -07:00
2016-07-18 18:40:07 +00:00
with module.ServiceFile('persistent.service') as fh:
fh.write("""
[Unit]
Description=Mount /persistent
DefaultDependencies=no
Conflicts=shutdown.target
After=systemd-remount-fs.service
Before=sysinit.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/icon/persistent/startup.sh
[Install]
WantedBy=sysinit.target
2016-03-31 16:25:41 -07:00
""")
2016-07-18 18:40:07 +00:00
module.EnableService('persistent.service')
2016-03-31 16:25:41 -07:00
if __name__ == '__main__':
main()