2015-06-10 20:59:55 +00:00
#!/usr/bin/env python3
# Copyright 2015 Canonical, Ltd.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2015-06-10 21:31:04 +00:00
import argparse
2015-06-23 17:02:01 +00:00
import logging
2017-11-16 20:58:33 +00:00
import os
2015-10-21 15:18:34 +00:00
import signal
2017-11-16 20:58:33 +00:00
import sys
2016-07-25 00:51:39 +00:00
2016-08-09 19:20:15 +00:00
from subiquitycore.log import setup_logger
2016-06-30 18:17:01 +00:00
from subiquitycore import __version__ as VERSION
2016-07-25 00:38:19 +00:00
from subiquitycore.core import ApplicationError
2016-06-30 18:17:01 +00:00
from subiquitycore.ui.frame import SubiquityUI
from subiquitycore.utils import environment_check
2015-06-10 20:59:55 +00:00
2016-07-25 00:51:39 +00:00
from subiquity.core import Subiquity
2015-06-10 20:59:55 +00:00
2016-07-26 03:09:44 +00:00
ENVIRONMENT = '''
checks:
read:
file:
- /var/log/syslog
write:
directory:
- /tmp
mount:
directory:
- /proc
- /sys
exec:
file:
- /sbin/hdparm
- /usr/bin/curtin
'''
2018-05-01 00:29:29 +00:00
class ClickAction(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
namespace.scripts.append("c(" + repr(values) + ")")
2015-06-10 21:31:04 +00:00
def parse_options(argv):
parser = argparse.ArgumentParser(
description='SUbiquity - Ubiquity for Servers',
prog='subiquity')
2015-07-06 15:55:49 +00:00
parser.add_argument('--dry-run', action='store_true',
dest='dry_run',
help='menu-only, do not call installer function')
2015-06-10 21:31:04 +00:00
parser.add_argument('--serial', action='store_true',
dest='run_on_serial',
help='Run the installer over serial console.')
2015-08-28 18:19:13 +00:00
parser.add_argument('--machine-config', metavar='CONFIG',
dest='machine_config',
help="Don't Probe. Use probe data file")
2015-09-23 03:19:54 +00:00
parser.add_argument('--uefi', action='store_true',
dest='uefi',
help='run in uefi support mode')
2016-11-22 23:08:36 +00:00
parser.add_argument('--screens', action='append', dest='screens', default=[])
2018-05-01 00:29:29 +00:00
parser.add_argument('--script', metavar="SCRIPT", action='append', dest='scripts', default=[], help='Execute SCRIPT in a namespace containing view helpers and "ui"')
parser.add_argument('--click', metavar="PAT", action=ClickAction, help='Synthesize a click on a button matching PAT')
2017-11-16 00:29:22 +00:00
parser.add_argument('--answers')
2015-06-10 21:31:04 +00:00
return parser.parse_args(argv)
2016-08-09 19:20:15 +00:00
LOGDIR = "/var/log/installer/"
2017-11-16 20:58:33 +00:00
AUTO_ANSWERS_FILE = "/subiquity_config/answers.yaml"
2015-06-10 20:59:55 +00:00
def main():
2015-06-10 21:31:04 +00:00
opts = parse_options(sys.argv[1:])
2016-08-09 19:20:15 +00:00
global LOGDIR
if opts.dry_run:
LOGDIR = ".subiquity"
LOGFILE = setup_logger(dir=LOGDIR)
2015-06-23 17:02:01 +00:00
logger = logging.getLogger('subiquity')
2015-06-23 17:09:26 +00:00
logger.info("Starting SUbiquity v{}".format(VERSION))
logger.info("Arguments passed: {}".format(sys.argv))
2015-06-24 18:28:47 +00:00
2017-02-10 03:17:58 +00:00
signal.signal(signal.SIGINT, signal.SIG_IGN)
signal.signal(signal.SIGQUIT, signal.SIG_IGN)
2015-10-21 15:18:34 +00:00
2016-07-26 03:09:44 +00:00
env_ok = environment_check(ENVIRONMENT)
2015-10-26 14:19:48 +00:00
if env_ok is False and not opts.dry_run:
print('Failed environment check. '
'Check {} for errors.'.format(LOGFILE))
2015-10-22 19:39:25 +00:00
return 1
2017-11-16 20:58:33 +00:00
if opts.answers is None and os.path.exists(AUTO_ANSWERS_FILE):
logger.debug("Autoloading answers from %s", AUTO_ANSWERS_FILE)
opts.answers = AUTO_ANSWERS_FILE
2015-06-24 18:28:47 +00:00
ui = SubiquityUI()
2015-10-23 15:03:04 +00:00
try:
subiquity_interface = Subiquity(ui, opts)
2016-07-25 00:38:19 +00:00
except ApplicationError as e:
2015-10-23 15:03:04 +00:00
logger.exception('Failed to load Subiquity interface')
print(e)
return 1
2015-06-24 18:28:47 +00:00
subiquity_interface.run()
2015-06-10 20:59:55 +00:00
if __name__ == '__main__':
2015-10-22 19:39:25 +00:00
sys.exit(main())