Skip to content

Commit 53e89d3

Browse files
committed
setup: improve macOS handling in setup and dependency installer
Signed-off-by: Sahil Jaiswal <[email protected]>
1 parent 4ba75de commit 53e89d3

2 files changed

Lines changed: 28 additions & 5 deletions

File tree

etc/DependencyInstaller.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ fi
1111

1212
# package versions
1313
klayoutVersion=0.30.3
14-
numThreads=$(nproc)
14+
if [[ "$OSTYPE" == "darwin"* ]]; then
15+
numThreads=$(sysctl -n hw.ncpu)
16+
else
17+
numThreads=$(nproc)
18+
fi
1519

1620
_versionCompare() {
1721
local a b IFS=. ; set -f

setup.sh

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,19 @@ set -euo pipefail
55
# allow this script to be invoked from any folder
66
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
77

8-
if [ $EUID -ne 0 ]; then
9-
echo "This script must be run with sudo"
8+
# macOS detection
9+
IS_DARWIN=false
10+
if [[ "$(uname)" == "Darwin" ]]; then
11+
IS_DARWIN=true
12+
fi
13+
14+
if $IS_DARWIN && [[ $EUID -eq 0 ]]; then
15+
echo "Do NOT run this script with sudo on macOS"
16+
exit 1
17+
fi
18+
19+
if ! $IS_DARWIN && [[ $EUID -ne 0 ]]; then
20+
echo "This script must be run with sudo on Linux"
1021
exit 1
1122
fi
1223

@@ -17,7 +28,11 @@ tmpfile=$(mktemp)
1728
git submodule status --recursive > "$tmpfile"
1829

1930
if grep -q "^-" "$tmpfile"; then
20-
sudo -u $SUDO_USER git submodule update --init --recursive
31+
if $IS_DARWIN; then
32+
git submodule update --init --recursive
33+
else
34+
sudo -u $SUDO_USER git submodule update --init --recursive
35+
fi
2136
elif grep -q "^+" "$tmpfile"; then
2237
# Make it easy for users who are not hacking ORFS to do the right thing,
2338
# run with current submodules, at the cost of having ORFS
@@ -27,4 +42,8 @@ elif grep -q "^+" "$tmpfile"; then
2742
fi
2843

2944
"$DIR/etc/DependencyInstaller.sh" -base
30-
sudo -u $SUDO_USER "$DIR/etc/DependencyInstaller.sh" -common -prefix="$DIR/dependencies"
45+
if $IS_DARWIN; then
46+
"$DIR/etc/DependencyInstaller.sh" -common -prefix="$DIR/dependencies"
47+
else
48+
sudo -u $SUDO_USER "$DIR/etc/DependencyInstaller.sh" -common -prefix="$DIR/dependencies"
49+
fi

0 commit comments

Comments
 (0)