From 3ab1bff4702b5f3eef334b60d8aeed76b9f84be0 Mon Sep 17 00:00:00 2001 From: Vyacheslav <64684523+adeepn@users.noreply.github.com> Date: Thu, 2 Sep 2021 22:57:41 +0300 Subject: [PATCH] Fix gpg signing when sudo unavailable. (#3100) Signed-off-by: Vyacheslav Bocharov --- lib/debootstrap.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/debootstrap.sh b/lib/debootstrap.sh index 6af0db9595..30dc27356e 100644 --- a/lib/debootstrap.sh +++ b/lib/debootstrap.sh @@ -825,8 +825,13 @@ create_image() cd ${DESTIMG} if [[ -n $GPG_PASS ]]; then display_alert "GPG signing" "${version}.img${compression_type}" "info" - [[ -n ${SUDO_USER} ]] && sudo chown -R ${SUDO_USER}:${SUDO_USER} "${DESTIMG}"/ - echo "${GPG_PASS}" | sudo -H -u ${SUDO_USER} bash -c "gpg --passphrase-fd 0 --armor --detach-sign --pinentry-mode loopback --batch --yes ${DESTIMG}/${version}.img${compression_type}" || exit 1 + if [[ -n $SUDO_USER ]]; then + sudo chown -R ${SUDO_USER}:${SUDO_USER} "${DESTIMG}"/ + SUDO_PREFIX="sudo -H -u ${SUDO_USER}" + else + SUDO_PREFIX="" + fi + echo "${GPG_PASS}" | $SUDO_PREFIX bash -c "gpg --passphrase-fd 0 --armor --detach-sign --pinentry-mode loopback --batch --yes ${DESTIMG}/${version}.img${compression_type}" || exit 1 else display_alert "GPG signing skipped - no GPG_PASS" "${version}.img" "wrn" fi