Skip to content
Open
Changes from all commits
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
20 changes: 12 additions & 8 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,7 +29,7 @@ if grep -q "^-" "$tmpfile"; then
if [[ "$OSTYPE" == "darwin"* ]]; then
git submodule update --init --recursive
else
sudo -u $SUDO_USER git submodule update --init --recursive
run_as_user git submodule update --init --recursive
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,5 @@ 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"
run_as_user "$DIR/etc/DependencyInstaller.sh" -common -prefix="$DIR/dependencies"
fi