From e9924b0a416354a9c21462ff4504de1296ba0c7b Mon Sep 17 00:00:00 2001 From: Divinesoumyadip Date: Sun, 22 Mar 2026 17:21:25 +0000 Subject: [PATCH 1/3] setup: fix unbound SUDO_USER variable when running as root in Docker Signed-off-by: Divinesoumyadip --- setup.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/setup.sh b/setup.sh index b9f2853e1e..fb1b180222 100755 --- a/setup.sh +++ b/setup.sh @@ -25,7 +25,11 @@ if grep -q "^-" "$tmpfile"; then if [[ "$OSTYPE" == "darwin"* ]]; then git submodule update --init --recursive else - sudo -u $SUDO_USER git submodule update --init --recursive + if [[ -n "${SUDO_USER:-}" ]]; then + sudo -u "$SUDO_USER" git submodule update --init --recursive + else + git submodule update --init --recursive + fi fi elif grep -q "^+" "$tmpfile"; then # Make it easy for users who are not hacking ORFS to do the right thing, @@ -39,5 +43,9 @@ fi if [[ "$OSTYPE" == "darwin"* ]]; then "$DIR/etc/DependencyInstaller.sh" -common -prefix="$DIR/dependencies" else - sudo -u $SUDO_USER "$DIR/etc/DependencyInstaller.sh" -common -prefix="$DIR/dependencies" + if [[ -n "${SUDO_USER:-}" ]]; then + sudo -u "$SUDO_USER" "$DIR/etc/DependencyInstaller.sh" -common -prefix="$DIR/dependencies" + else + "$DIR/etc/DependencyInstaller.sh" -common -prefix="$DIR/dependencies" + fi fi From 21a69ed90ee3e4a2f03a859bd7c346d9acf0d854 Mon Sep 17 00:00:00 2001 From: Divinesoumyadip Date: Fri, 3 Apr 2026 05:12:41 +0000 Subject: [PATCH 2/3] setup: refactor to use helper function for SUDO_USER handling Signed-off-by: Divinesoumyadip --- setup.sh | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/setup.sh b/setup.sh index fb1b180222..ed4d168db8 100755 --- a/setup.sh +++ b/setup.sh @@ -5,16 +5,20 @@ set -euo pipefail # allow this script to be invoked from any folder DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -if [[ "$OSTYPE" == "darwin"* ]] && [[ $EUID -eq 0 ]]; then - echo "Do NOT run this script with sudo on macOS" +if [ $EUID -ne 0 ]; then + echo "This script must be run with sudo" exit 1 fi -if [[ "$OSTYPE" != "darwin"* ]] && [[ $EUID -ne 0 ]]; then - echo "This script must be run with sudo on Linux" - exit 1 -fi +# Run a command as the original user if invoked via sudo, otherwise run directly +run_as_user() { + if [[ -n "${SUDO_USER:-}" ]]; then + sudo -u "$SUDO_USER" "$@" + else + "$@" + fi +} tmpfile=$(mktemp) # any error messages from this command will stand out # more clearly when run as a separate command rather than @@ -22,15 +26,15 @@ tmpfile=$(mktemp) git submodule status --recursive > "$tmpfile" if grep -q "^-" "$tmpfile"; then +<<<<<<< Updated upstream + sudo -u $SUDO_USER git submodule update --init --recursive +======= if [[ "$OSTYPE" == "darwin"* ]]; then git submodule update --init --recursive else - if [[ -n "${SUDO_USER:-}" ]]; then - sudo -u "$SUDO_USER" git submodule update --init --recursive - else - git submodule update --init --recursive - fi + run_as_user git submodule update --init --recursive fi +>>>>>>> Stashed changes elif grep -q "^+" "$tmpfile"; then # Make it easy for users who are not hacking ORFS to do the right thing, # run with current submodules, at the cost of having ORFS @@ -40,12 +44,12 @@ elif grep -q "^+" "$tmpfile"; then fi "$DIR/etc/DependencyInstaller.sh" -base +<<<<<<< Updated upstream +sudo -u $SUDO_USER "$DIR/etc/DependencyInstaller.sh" -common -prefix="$DIR/dependencies" +======= if [[ "$OSTYPE" == "darwin"* ]]; then "$DIR/etc/DependencyInstaller.sh" -common -prefix="$DIR/dependencies" else - if [[ -n "${SUDO_USER:-}" ]]; then - sudo -u "$SUDO_USER" "$DIR/etc/DependencyInstaller.sh" -common -prefix="$DIR/dependencies" - else - "$DIR/etc/DependencyInstaller.sh" -common -prefix="$DIR/dependencies" - fi + run_as_user "$DIR/etc/DependencyInstaller.sh" -common -prefix="$DIR/dependencies" fi +>>>>>>> Stashed changes From ebbdf37e25b8e78eb0278bdf318965d25983e092 Mon Sep 17 00:00:00 2001 From: Divinesoumyadip Date: Fri, 3 Apr 2026 05:17:52 +0000 Subject: [PATCH 3/3] setup: resolve merge conflicts, keep helper function approach Signed-off-by: Divinesoumyadip --- setup.sh | 8 -------- 1 file changed, 8 deletions(-) diff --git a/setup.sh b/setup.sh index ed4d168db8..1b473a1188 100755 --- a/setup.sh +++ b/setup.sh @@ -26,15 +26,11 @@ tmpfile=$(mktemp) git submodule status --recursive > "$tmpfile" if grep -q "^-" "$tmpfile"; then -<<<<<<< Updated upstream - sudo -u $SUDO_USER git submodule update --init --recursive -======= if [[ "$OSTYPE" == "darwin"* ]]; then git submodule update --init --recursive else run_as_user git submodule update --init --recursive fi ->>>>>>> Stashed changes elif grep -q "^+" "$tmpfile"; then # Make it easy for users who are not hacking ORFS to do the right thing, # run with current submodules, at the cost of having ORFS @@ -44,12 +40,8 @@ elif grep -q "^+" "$tmpfile"; then fi "$DIR/etc/DependencyInstaller.sh" -base -<<<<<<< Updated upstream -sudo -u $SUDO_USER "$DIR/etc/DependencyInstaller.sh" -common -prefix="$DIR/dependencies" -======= if [[ "$OSTYPE" == "darwin"* ]]; then "$DIR/etc/DependencyInstaller.sh" -common -prefix="$DIR/dependencies" else run_as_user "$DIR/etc/DependencyInstaller.sh" -common -prefix="$DIR/dependencies" fi ->>>>>>> Stashed changes