-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall-macos.sh
More file actions
193 lines (148 loc) · 4.81 KB
/
install-macos.sh
File metadata and controls
193 lines (148 loc) · 4.81 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#!/usr/bin/env bash
set -euo pipefail
# Slicer URI Bridge macOS installer
#
# What it does:
# 1. Finds Python 3.11+
# 2. If Python 3.11+ is missing, installs Homebrew Python 3.12
# 3. Creates a private virtual environment
# 4. Installs / upgrades Slicer URI Bridge into that environment
# 5. Creates a wrapper in ~/.local/bin/slicer-uri-bridge
# 6. Creates config if missing
# 7. Registers URI handlers
# 8. Shows how to test the registered handler
#
# To update later, run this installer again.
PROJECT_SPEC="https://github.com/mbv06/slicer-uri-bridge/archive/refs/heads/main.zip"
APP_HOME="${HOME}/.local/share/slicer-uri-bridge"
VENV="${APP_HOME}/venv"
LOCAL_BIN="${HOME}/.local/bin"
WRAPPER="${LOCAL_BIN}/slicer-uri-bridge"
BIN="${VENV}/bin/slicer-uri-bridge"
MIN_MAJOR=3
MIN_MINOR=11
BREW_PYTHON_FORMULA="python@3.12"
log() {
printf '\n==> %s\n' "$*"
}
die() {
printf 'Error: %s\n' "$*" >&2
exit 1
}
python_is_compatible() {
local python="$1"
"$python" - <<PY >/dev/null 2>&1
import sys
raise SystemExit(0 if sys.version_info >= (${MIN_MAJOR}, ${MIN_MINOR}) else 1)
PY
}
find_python311() {
local candidate path
for candidate in \
python3.14 python3.13 python3.12 python3.11 \
/opt/homebrew/bin/python3.14 /opt/homebrew/bin/python3.13 /opt/homebrew/bin/python3.12 /opt/homebrew/bin/python3.11 \
/usr/local/bin/python3.14 /usr/local/bin/python3.13 /usr/local/bin/python3.12 /usr/local/bin/python3.11 \
python3
do
path=""
if command -v "$candidate" >/dev/null 2>&1; then
path="$(command -v "$candidate")"
elif [ -x "$candidate" ]; then
path="$candidate"
fi
if [ -n "$path" ] && python_is_compatible "$path"; then
printf '%s\n' "$path"
return 0
fi
done
return 1
}
install_homebrew_python() {
if ! command -v brew >/dev/null 2>&1; then
cat >&2 <<'EOF'
Python 3.11+ was not found.
Homebrew is required to install Python automatically.
Install Homebrew first:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Then run this installer again.
EOF
exit 1
fi
log "Installing Python with Homebrew"
brew install "${BREW_PYTHON_FORMULA}"
local brew_python
brew_python="$(brew --prefix "${BREW_PYTHON_FORMULA}")/bin/python3.12"
if [ ! -x "$brew_python" ]; then
die "Homebrew Python was installed, but this executable was not found: ${brew_python}"
fi
if ! python_is_compatible "$brew_python"; then
"$brew_python" --version >&2 || true
die "Homebrew Python is not Python ${MIN_MAJOR}.${MIN_MINOR}+."
fi
printf '%s\n' "$brew_python"
}
ensure_zprofile_path() {
if [[ ":${PATH}:" == *":${LOCAL_BIN}:"* ]]; then
return 0
fi
touch "${HOME}/.zprofile"
if ! grep -Fq 'export PATH="$HOME/.local/bin:$PATH"' "${HOME}/.zprofile"; then
{
printf '\n'
printf '# Slicer URI Bridge\n'
printf 'export PATH="$HOME/.local/bin:$PATH"\n'
} >> "${HOME}/.zprofile"
fi
}
create_wrapper() {
mkdir -p "$LOCAL_BIN"
cat > "$WRAPPER" <<EOF
#!/usr/bin/env bash
exec "${BIN}" "\$@"
EOF
chmod +x "$WRAPPER"
}
main() {
if [ "$(uname -s)" != "Darwin" ]; then
die "This installer is for macOS only."
fi
log "Checking Python ${MIN_MAJOR}.${MIN_MINOR}+"
local python
if python="$(find_python311)"; then
printf 'Using Python: %s\n' "$python"
else
python="$(install_homebrew_python)"
printf 'Using Python: %s\n' "$python"
fi
log "Checking built-in venv support"
if ! "$python" -m venv --help >/dev/null 2>&1; then
die "This Python does not support the built-in venv module. Install a full Python ${MIN_MAJOR}.${MIN_MINOR}+ distribution and run this installer again."
fi
log "Creating private Python environment"
mkdir -p "$APP_HOME"
"$python" -m venv "$VENV"
log "Installing / upgrading Slicer URI Bridge"
"${VENV}/bin/python" -m pip install --upgrade pip
"${VENV}/bin/python" -m pip install --upgrade "$PROJECT_SPEC"
log "Creating command wrapper"
create_wrapper
ensure_zprofile_path
log "Creating config if needed"
"$BIN" init-config || true
log "Registering URI handlers"
"$BIN" register --auto
cat <<EOF
✅ Done! Slicer URI Bridge is installed.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
📌 Command: slicer-uri-bridge
⚙️ Config: ~/.config/slicer-uri-bridge/config.toml
📂 Logs: ~/.config/slicer-uri-bridge/launcher.log
~/.config/slicer-uri-bridge/bridge.log
🧪 Test: slicer-uri-bridge test
📦 Environment: ${VENV}
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠️ If "slicer-uri-bridge" is not found, open a new Terminal window.
🔄 To update later, just run this installer again.
EOF
}
main "$@"