Add option to run sudo -v in a loop to prevent repeated password entries (MR 1997)

Many of pmbootstrap's actions require root rights. When after requesting
sudo access pmbootstrap takes longer than the sudo timeout interval to finish
execution, the password will have to be entered again on the next sudo
action.

This change adds an opt-in feature to run sudo -v in a background loop
in order to prevent having to enter the password more than once for a single
pmbootstrap run. The loop runs as a daemon timer which automatically gets
canceled when pmbootstrap exits.

Closes: #1677
This commit is contained in:
Johannes Marbach 2020-11-30 14:08:29 +01:00
parent 8842a7d5c0
commit 1eac61bcf7
No known key found for this signature in database
GPG key ID: 5AE7F5513E0885CB
5 changed files with 49 additions and 11 deletions

View file

@ -344,7 +344,8 @@ def ask_for_additional_options(args, cfg):
f" extra free space: {args.extra_space} MB,"
f" boot partition size: {args.boot_size} MB,"
f" parallel jobs: {args.jobs},"
f" ccache per arch: {args.ccache_size}")
f" ccache per arch: {args.ccache_size},"
f" sudo timer: {args.sudo_timer}")
if not pmb.helpers.cli.confirm(args, "Change them?",
default=False):
@ -385,6 +386,17 @@ def ask_for_additional_options(args, cfg):
lowercase_answer=False, validation_regex=regex)
cfg["pmbootstrap"]["ccache_size"] = answer
# Sudo timer
logging.info("pmbootstrap does everything in Alpine Linux chroots, so"
" your host system does not get modified. In order to"
" work with these chroots, pmbootstrap calls 'sudo'"
" internally. For long running operations, it is possible"
" that you'll have to authorize sudo more than once.")
answer = pmb.helpers.cli.confirm(args, "Enable background timer to prevent"
" repeated sudo authorization?",
default=args.sudo_timer)
cfg["pmbootstrap"]["sudo_timer"] = str(answer)
def ask_for_hostname(args, device):
while True: