setup: fix unbound SUDO_USER variable when running as root in Docker#4029
setup: fix unbound SUDO_USER variable when running as root in Docker#4029Divinesoumyadip wants to merge 3 commits into
Conversation
Signed-off-by: Divinesoumyadip <soumyacode7@gmail.com>
5de9ff2 to
e9924b0
Compare
|
@maliberty @luarss could you approve the workflows to run CI? Happy to address any review feedback. |
| git submodule update --init --recursive | ||
| else | ||
| sudo -u $SUDO_USER git submodule update --init --recursive | ||
| if [[ -n "${SUDO_USER:-}" ]]; then |
There was a problem hiding this comment.
this nested loop causes lots of repeated code. is a helper function possible here?
There was a problem hiding this comment.
this nested loop causes lots of repeated code. is a helper function possible here?
Done! Refactored to use a run_as_user() helper function that handles both cases drops privileges to the original user when invoked via sudo, and runs directly when already root. Removes the repeated pattern across both submodule and dependency installer calls.
Signed-off-by: Divinesoumyadip <soumyacode7@gmail.com>
Signed-off-by: Divinesoumyadip <soumyacode7@gmail.com>
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 21 days if no further activity occurs. Remove the |
When
setup.shis run directly as root , which is standard in Docker containers and CI/CD pipelines so,$SUDO_USERis never set. Because the script usesset -euo pipefail, the-uflag causes the script to crash immediately on any unbound variable reference.Two lines were affected:
Line 28:
bash sudo -u $SUDO_USER git submodule update --init --recursiveLine 42:
sudo -u $SUDO_USER "$DIR/etc/DependencyInstaller.sh" -common -prefix="$DIR/dependencies"When
$SUDO_USERis empty,sudo -uconsumesgit(or the script path) as the username and crashes with:To resolve this, the script now checks if
$SUDO_USERis set before attempting to use it. If the variable is set (indicating the script was invoked via sudo), it drops privileges to the original user as intended. However, if it is empty (indicating the script is running natively as root), it simply runs the command directly without thesudo -uflag. The macOS paths were already handled correctly by #4023, so this PR completes the fix for the remaining Linux and Docker environments.