From 0b3478a3fdf26317a2a3e333b9d672295f74bdc8 Mon Sep 17 00:00:00 2001 From: Marc Herbert Date: Fri, 6 Jan 2023 01:22:00 +0000 Subject: [PATCH] scripts/sudo-cwd.sh: don't try to copy missing sudoers.d/ permissions Copying a file that does not exist obviously fails. This bug was found when trying to switch from the current "Developer Image" to the smaller "CI Image": https://github.com/zephyrproject-rtos/docker-image/pkgs/container/zephyr-build Signed-off-by: Marc Herbert (cherry picked from commit 75fa04de091581eb182cf4e25f7251ef9e15ebf4) --- scripts/sudo-cwd.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/sudo-cwd.sh b/scripts/sudo-cwd.sh index 2c4d859345d8..2823cf2f6c73 100755 --- a/scripts/sudo-cwd.sh +++ b/scripts/sudo-cwd.sh @@ -54,10 +54,12 @@ exec_as_cwd_uid() local current_user; current_user="$(id -un)" # Copy sudo permissions just in case the build needs it - sudo sed -e "s/$current_user/$cwd_user/" /etc/sudoers.d/"$current_user" | + if test -e /etc/sudoers.d/"$current_user"; then + sudo sed -e "s/$current_user/$cwd_user/" /etc/sudoers.d/"$current_user" | sudo tee -a /etc/sudoers.d/"$cwd_user" - sudo chmod --reference=/etc/sudoers.d/"$current_user" \ + sudo chmod --reference=/etc/sudoers.d/"$current_user" \ /etc/sudoers.d/"$cwd_user" + fi } # Double sudo to work around some funny restriction in