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