docs: def main(device_type):
      """Run ssh-agent using given hardware client factory."""
      args = create_agent_parser(device_type=device_type).parse_args()
      util.setup_logging(verbosity=args.verbose, filename=args.log_file)
  
      public_keys = None
      filename = None
      if args.identity.startswith('/'):
          filename = args.identity
          contents = open(filename, 'rb').read().decode('utf-8')
          # Allow loading previously exported SSH public keys
          if filename.endswith('.pub'):
              public_keys = list(import_public_keys(contents))
          identities = list(parse_config(contents))
      else:
          identities = [device.interface.Identity(
              identity_str=args.identity, curve_name=args.ecdsa_curve_name)]
      for index, identity in enumerate(identities):
          identity.identity_dict['proto'] = u'ssh'
          log.info('identity #%d: %s', index, identity.to_string())
  
      # override default PIN/passphrase entry tools (relevant for TREZOR/Keepkey):
      device_type.ui = device.ui.UI(device_type=device_type, config=vars(args))
      device_type.ui.cached_passphrase_ack = util.ExpiringCache(
          args.cache_expiry_seconds)
  
      conn = JustInTimeConnection(
          conn_factory=lambda: client.Client(device_type()),
          identities=identities, public_keys=public_keys)
  
      sock_path = _get_sock_path(args)
      command = args.command
      context = _dummy_context()
      if args.connect:
          command = ['ssh'] + ssh_args(conn) + args.command
      elif args.mosh:
          command = ['mosh'] + mosh_args(conn) + args.command
      elif args.daemonize:
          out = 'SSH_AUTH_SOCK={0}; export SSH_AUTH_SOCK;\n'.format(sock_path)
          sys.stdout.write(out)
          sys.stdout.flush()
          context = daemon.DaemonContext()
          log.info('running the agent as a daemon on %s', sock_path)
      elif args.foreground:
          log.info('running the agent on %s', sock_path)
  
      use_shell = bool(args.shell)
      if use_shell:
          command = os.environ['SHELL']
          sys.stdin.close()
  
      if command or args.daemonize or args.foreground:
          with context:
              return run_server(conn=conn, command=command, sock_path=sock_path,
                                debug=args.debug, timeout=args.timeout)
      else:
          for pk in conn.public_keys():
              sys.stdout.write(pk)
          return 0