Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this nested loop causes lots of repeated code. is a helper function possible here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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,
Expand All @@ -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