diff --git a/console_conf/controllers/identity.py b/console_conf/controllers/identity.py index f9188618..0e2ba2d6 100644 --- a/console_conf/controllers/identity.py +++ b/console_conf/controllers/identity.py @@ -108,12 +108,7 @@ def write_login_details(fp, username, ips): first_ip=first_ip, version=version)) - -def write_login_details_standalone(): - owner = get_device_owner() - if owner is None: - print("No device owner details found.") - return 0 +def get_ips_standalone(): from probert.prober import Prober from subiquitycore.models.network import NETDEV_IGNORED_IFACE_TYPES prober = Prober() @@ -126,6 +121,15 @@ def write_login_details_standalone(): for addr in l['addresses']: if addr['scope'] == "global": ips.append(addr['address'].split('/')[0]) + return ips + + +def write_login_details_standalone(): + owner = get_device_owner() + if owner is None: + print("No device owner details found.") + return 0 + ips = get_ips_standalone() if len(ips) == 0: tty_name = os.ttyname(0)[5:] version = get_core_version() or "16" diff --git a/subiquity/cmd/tui.py b/subiquity/cmd/tui.py index a5738a52..98121097 100755 --- a/subiquity/cmd/tui.py +++ b/subiquity/cmd/tui.py @@ -47,6 +47,9 @@ def parse_options(argv): parser.add_argument('--serial', action='store_true', dest='run_on_serial', help='Run the installer over serial console.') + parser.add_argument('--ssh', action='store_true', + dest='ssh', + help='Print ssh login details') parser.add_argument('--ascii', action='store_true', dest='ascii', help='Run the installer in ascii mode.') @@ -160,6 +163,20 @@ def main(): logging.getLogger('curtin').addHandler(handler) logging.getLogger('block-discover').addHandler(handler) + if opts.ssh: + from subiquity.ui.views.help import ssh_help_texts, get_installer_password + from console_conf.controllers.identity import get_ips_standalone + texts = ssh_help_texts(get_ips_standalone(), get_installer_password(opts.dry_run)) + for line in texts: + if hasattr(line, 'text'): + if line.text.startswith('installer@'): + print(' ' * 4 + line.text) + else: + print(line.text) + else: + print(line) + return 0 + 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 diff --git a/subiquity/ui/views/help.py b/subiquity/ui/views/help.py index dcf83d60..9241fdf9 100644 --- a/subiquity/ui/views/help.py +++ b/subiquity/ui/views/help.py @@ -124,6 +124,32 @@ Unfortunately the installer was unable to detect the password that has been set. """) +def ssh_help_texts(ips, password): + + texts = [_(SSH_HELP_PROLOGUE), ""] + + if len(ips) > 0: + if len(ips) > 1: + texts.append(rewrap(_(SSH_HELP_MULTIPLE_ADDRESSES))) + texts.append("") + for ip in ips: + texts.append(Text( + "installer@" + str(ip), align='center')) + else: + texts.append(_(SSH_HELP_ONE_ADDRESSES).format( + ip=str(ips[0]))) + texts.append("") + texts.append( + rewrap(_(SSH_HELP_EPILOGUE).format( + password=password))) + texts.append("") + texts.append(Text(host_key_info())) + else: + texts.append("") + texts.append(_(SSH_HELP_NO_ADDRESSES)) + + return texts + class SimpleTextStretchy(Stretchy): @@ -345,29 +371,9 @@ class HelpMenu(WidgetWrap): return ips def _ssh_help(self, sender=None): - - texts = [_(SSH_HELP_PROLOGUE), ""] - - ips = self.get_global_addresses() - if len(ips) > 0: - if len(ips) > 1: - texts.append(rewrap(_(SSH_HELP_MULTIPLE_ADDRESSES))) - texts.append("") - for ip in ips: - texts.append(Text( - "installer@" + str(ip), align='center')) - else: - texts.append(_(SSH_HELP_ONE_ADDRESSES).format( - ip=str(ips[0]))) - texts.append("") - texts.append( - rewrap(_(SSH_HELP_EPILOGUE).format( - password=self.parent.ssh_password))) - texts.append("") - texts.append(Text(host_key_info())) - else: - texts.append("") - texts.append(_(SSH_HELP_NO_ADDRESSES)) + texts = ssh_help_texts( + self.get_global_addresses(), + self.parent.ssh_password) self._show_overlay( SimpleTextStretchy( @@ -405,9 +411,9 @@ class HelpMenu(WidgetWrap): self.parent.app.ui.body)) -def get_installer_password(app): - if app.opts.dry_run: - fp = io.StringIO('installe:rAnd0Mpass') +def get_installer_password(dry_run=False): + if dry_run: + fp = io.StringIO('installer:rAnd0Mpass') else: try: fp = open("/var/log/cloud-init-output.log") @@ -437,7 +443,7 @@ class HelpButton(PopUpLauncher): def create_pop_up(self): if self.ssh_password is None: - self.ssh_password = get_installer_password(self.app) + self.ssh_password = get_installer_password(self.app.opts.dry_run) self._menu = HelpMenu(self) return self._menu