pmb.install: password for root is already locked (MR 2159)

When running `pmbootstrap install`, pmbootstrap does not unlock root
when it completes. This patch allows `pmbootstrap install` to run two or
more times (without zap).

Co-Authored-By: Oliver Smith <ollieparanoid@postmarketos.org>
This commit is contained in:
Rudraksha Gupta 2022-01-18 00:00:00 +00:00 committed by Oliver Smith
parent d698aa15ad
commit bea18e03f3
No known key found for this signature in database
GPG Key ID: 5AE7F5513E0885CB
1 changed files with 18 additions and 1 deletions

View File

@ -228,6 +228,19 @@ def setup_login_chpasswd_user_from_arg(args, suffix):
os.unlink(path_outside)
def is_root_locked(args, suffix):
"""
Figure out from /etc/shadow if root is already locked. The output of this
is stored in the log, so use grep to only log the line for root, not the
line for the user which contains a hash of the user's password.
:param suffix: either rootfs_{args.device} or installer_{args.device}
"""
shadow_root = pmb.chroot.root(args, ["grep", "^root:!:", "/etc/shadow"],
suffix, output_return=True, check=False)
return shadow_root.startswith("root:!:")
def setup_login(args, suffix):
"""
Loop until the password for user has been set successfully, and disable
@ -253,7 +266,11 @@ def setup_login(args, suffix):
pass
# Disable root login
pmb.chroot.root(args, ["passwd", "-l", "root"], suffix)
if is_root_locked(args, suffix):
logging.debug(f"({suffix}) root is already locked")
else:
logging.debug(f"({suffix}) locking root")
pmb.chroot.root(args, ["passwd", "-l", "root"], suffix)
def copy_ssh_keys(args):