-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmac_shell.sh
More file actions
executable file
·113 lines (97 loc) · 3.49 KB
/
mac_shell.sh
File metadata and controls
executable file
·113 lines (97 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env bash
set -e
IMAGE_NAME="sram-env"
CONTAINER_NAME="sram-shell"
# --- Helper Function ---
install_with_brew() {
local pkg="$1"
if ! brew list --cask "$pkg" >/dev/null 2>&1 && ! brew list "$pkg" >/dev/null 2>&1; then
echo "🔹 Installing $pkg via Homebrew..."
brew install --cask "$pkg" || brew install "$pkg"
else
echo "✅ $pkg already installed."
fi
}
# --- Fast Path: Check if Already Set Up ---
SETUP_COMPLETE=false
if command -v docker >/dev/null 2>&1 && \
docker info >/dev/null 2>&1 && \
[ -d "/Applications/Utilities/XQuartz.app" ] && \
[[ "$(docker images -q $IMAGE_NAME 2>/dev/null)" != "" ]]; then
SETUP_COMPLETE=true
fi
# --- Setup Phase (only if needed) ---
if [ "$SETUP_COMPLETE" = false ]; then
echo "🔧 Running first-time setup..."
# 1. Install Homebrew if Missing
if ! command -v brew >/dev/null 2>&1; then
echo "🍺 Homebrew not found. Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Add Homebrew to PATH for Apple Silicon Macs
if [[ $(uname -m) == 'arm64' ]]; then
echo "🔹 Configuring Homebrew for Apple Silicon..."
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
else
# Intel Macs
echo 'eval "$(/usr/local/bin/brew shellenv)"' >> ~/.zprofile
eval "$(/usr/local/bin/brew shellenv)"
fi
echo "✅ Homebrew installed successfully!"
else
echo "✅ Homebrew already installed."
fi
# 2. Install XQuartz if Missing
if ! [ -d "/Applications/Utilities/XQuartz.app" ]; then
install_with_brew "xquartz"
echo "⚠️ XQuartz installed. Please log out and log back in, then run this script again."
exit 0
fi
# 3. Ensure Docker is Installed
if ! command -v docker >/dev/null 2>&1; then
install_with_brew "docker"
echo "⚠️ Docker installed. Please start Docker Desktop and run this script again."
exit 0
fi
# 4. Ensure Docker Daemon is Running
if ! docker info >/dev/null 2>&1; then
echo "🔹 Starting Docker..."
open -a Docker
echo "⏳ Waiting for Docker to start..."
for i in {1..30}; do
if docker info >/dev/null 2>&1; then
break
fi
sleep 2
if [ $i -eq 30 ]; then
echo "❌ Docker failed to start. Please start Docker Desktop manually."
exit 1
fi
done
fi
# 5. Build Docker Image if Missing
if [[ "$(docker images -q $IMAGE_NAME 2>/dev/null)" == "" ]]; then
echo "🐳 Building Docker image '$IMAGE_NAME'..."
docker build -t $IMAGE_NAME .
fi
echo "✅ Setup complete!"
fi
# Start XQuartz if not running
if ! pgrep -q XQuartz; then
open -a XQuartz &
fi
# Get local IP for DISPLAY
IP=$(ifconfig en0 | grep inet | awk '$1=="inet" {print $2}' 2>/dev/null)
[ -z "$IP" ] && IP=$(ifconfig | grep 'inet ' | grep -v '127.0.0.1' | awk 'NR==1{print $2}')
# Allow X11 connections
xhost +$IP >/dev/null 2>&1 || true
# Enter container
echo "🚀 Entering EDA environment..."
docker run -it --rm \
-e DISPLAY=$IP:0 \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-v "$(pwd):/workspace" \
-v "$HOME/.cache/nix:/root/.cache/nix" \
-v "$HOME/.volare:/root/.volare" \
--name $CONTAINER_NAME \
$IMAGE_NAME nix-shell