From 6edd6a4d55af1ca29c799c96ee355f0747df1ea7 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Mon, 17 Jul 2023 21:44:13 +0100 Subject: [PATCH] if ${USER} variable is blank, then populate it with whoami Signed-off-by: Adam Warner --- pihole | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pihole b/pihole index b762c7d4..66771b9b 100755 --- a/pihole +++ b/pihole @@ -544,6 +544,13 @@ if [[ ! $EUID -eq 0 && need_root -eq 1 ]];then exit 1 fi fi + +# In the case of alpine running in a container, the USER variable appears to be blank +# which prevents the next trap from working correctly. Set it by running whoami +if [[ -z ${USER} ]]; then + USER=$(whoami) +fi + # Can also be user pihole for other functions if [[ ${USER} != "pihole" && need_root -eq 0 ]];then if [[ -x "$(command -v sudo)" ]]; then