pmb.config: use ssh_key_glob for ask_for_ssh_keys (MR 2251)

Since a user can modify the glob to be somewhat arbitrary, use that to
check if any ssh keys exist and ask in pmbootstrap init.

Otherwise ssh_key_glob would only work if it was a subset of
~/.ssh/id_*.pub, so e.g. ~/.ssh/id_foo.pub but ~/.ssh/foo.pub wouldn't
work.
This commit is contained in:
Luca Weiss 2024-02-07 11:56:22 +01:00 committed by Oliver Smith
parent d19de946b3
commit ca9610a153
No known key found for this signature in database
GPG key ID: 5AE7F5513E0885CB

View file

@ -645,8 +645,8 @@ def ask_for_hostname(default: str | None, device: str) -> str:
return ret
def ask_for_ssh_keys(default: bool) -> bool:
if not len(glob.glob(os.path.expanduser("~/.ssh/id_*.pub"))):
def ask_for_ssh_keys(ssh_key_glob: str, default: bool) -> bool:
if not len(glob.glob(os.path.expanduser(ssh_key_glob))):
return False
return pmb.helpers.cli.confirm(
"Would you like to copy your SSH public keys to the device?", default=default
@ -787,7 +787,7 @@ def frontend(args: PmbArgs) -> None:
config.hostname = ask_for_hostname(config.hostname, device)
# SSH keys
config.ssh_keys = ask_for_ssh_keys(config.ssh_keys)
config.ssh_keys = ask_for_ssh_keys(config.ssh_key_glob, config.ssh_keys)
# pmaports path (if users change it with: 'pmbootstrap --aports=... init')
config.aports = get_context().config.aports