Skip to content

Commit fddb5d4

Browse files
committed
refactor: simplify install.sh to Homebrew-only installer
Redesign install.sh as a Homebrew bootstrapper that ensures Homebrew is installed and then delegates to 'brew install openboot' for all installations. This eliminates multi-channel conflicts entirely. Changes: - Remove direct binary download logic (236 lines removed) - Remove checksum verification, atomic operations, PATH management - Keep install_xcode_clt and install_homebrew functions - Add reinstall prompt if already installed via Homebrew - Maintain 'exec openboot' behavior for automatic launch after install - Simplify from 405 to 169 lines (58% reduction) Rationale: - OpenBoot requires Homebrew to function, so curl|bash should ensure Homebrew is present then use it as the installation method - Single installation channel eliminates conflicts between curl and brew - Reduces maintenance burden and security surface - User experience unchanged: curl|bash still auto-launches setup wizard Installation flow: 1. curl|bash executes install.sh 2. Script ensures Xcode CLT + Homebrew installed 3. Script runs 'brew tap openbootdotdev/tap && brew install openboot' 4. Script auto-launches 'openboot' interactive wizard
1 parent 69f6852 commit fddb5d4

1 file changed

Lines changed: 41 additions & 277 deletions

File tree

scripts/install.sh

Lines changed: 41 additions & 277 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ set -euo pipefail
44
VERSION="${OPENBOOT_VERSION:-latest}"
55
REPO="openbootdotdev/openboot"
66
BINARY_NAME="openboot"
7-
INSTALL_DIR="${OPENBOOT_INSTALL_DIR:-$HOME/.openboot/bin}"
7+
TAP_NAME="openbootdotdev/tap"
88
DRY_RUN="${OPENBOOT_DRY_RUN:-false}"
9-
SKIP_CHECKSUM="${OPENBOOT_SKIP_CHECKSUM:-false}"
109

1110
install_xcode_clt() {
1211
if xcode-select -p &>/dev/null; then
@@ -37,7 +36,6 @@ install_homebrew() {
3736

3837
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
3938

40-
# Manually set PATH instead of using eval for security
4139
local arch
4240
arch=$(uname -m)
4341
case "$arch" in
@@ -68,40 +66,13 @@ install_homebrew() {
6866
echo ""
6967
}
7068

71-
check_existing_installation() {
72-
if ! command -v brew &>/dev/null; then
73-
return 0
74-
fi
75-
76-
if ! brew list openboot &>/dev/null 2>&1; then
77-
return 0
78-
fi
79-
80-
local existing_path
81-
existing_path=$(command -v openboot 2>/dev/null || true)
82-
83-
if [[ -z "$existing_path" ]]; then
84-
return 0
85-
fi
86-
87-
if [[ -L "$existing_path" ]]; then
88-
local link_target
89-
link_target=$(readlink "$existing_path" 2>/dev/null || true)
90-
if [[ "$link_target" == *"/Cellar/openboot"* ]] || [[ "$link_target" == *"/opt/homebrew"*"/openboot"* ]]; then
91-
echo ""
92-
echo "⚠️ OpenBoot is already installed via Homebrew"
93-
echo " Location: $existing_path"
94-
echo ""
95-
echo "Choose one:"
96-
echo " 1. Update via Homebrew: brew upgrade openboot"
97-
echo " 2. Switch to curl: brew uninstall openboot && curl -fsSL https://openboot.dev/install.sh | bash"
98-
echo ""
99-
exit 1
100-
fi
101-
fi
102-
103-
echo "Cleaning up stale Homebrew registration..."
104-
brew uninstall --force openboot &>/dev/null || true
69+
detect_os() {
70+
local os
71+
os=$(uname -s | tr '[:upper:]' '[:lower:]')
72+
case "$os" in
73+
darwin) echo "darwin" ;;
74+
*) echo "Error: OpenBoot only supports macOS" >&2; exit 1 ;;
75+
esac
10576
}
10677

10778
detect_arch() {
@@ -115,177 +86,6 @@ detect_arch() {
11586
esac
11687
}
11788

118-
detect_os() {
119-
local os
120-
os=$(uname -s | tr '[:upper:]' '[:lower:]')
121-
case "$os" in
122-
darwin) echo "darwin" ;;
123-
*) echo "Error: OpenBoot only supports macOS" >&2; exit 1 ;;
124-
esac
125-
}
126-
127-
get_download_url() {
128-
local os="$1"
129-
local arch="$2"
130-
131-
if [[ "$VERSION" == "latest" ]]; then
132-
echo "https://github.com/${REPO}/releases/latest/download/${BINARY_NAME}-${os}-${arch}"
133-
else
134-
echo "https://github.com/${REPO}/releases/download/${VERSION}/${BINARY_NAME}-${os}-${arch}"
135-
fi
136-
}
137-
138-
verify_checksum() {
139-
local binary_path="$1"
140-
local os="$2"
141-
local arch="$3"
142-
143-
if [[ "$SKIP_CHECKSUM" == "true" ]]; then
144-
return 0
145-
fi
146-
147-
local checksum_url
148-
if [[ "$VERSION" == "latest" ]]; then
149-
checksum_url="https://github.com/${REPO}/releases/latest/download/checksums.txt"
150-
else
151-
checksum_url="https://github.com/${REPO}/releases/download/${VERSION}/checksums.txt"
152-
fi
153-
154-
local checksums
155-
if ! checksums=$(curl -fsSL \
156-
--max-time 30 \
157-
--retry 3 \
158-
--retry-delay 2 \
159-
--proto '=https' \
160-
--tlsv1.2 \
161-
"$checksum_url" 2>/dev/null); then
162-
echo "Warning: Could not download checksums file. Skipping verification."
163-
return 0
164-
fi
165-
166-
local expected_checksum
167-
expected_checksum=$(echo "$checksums" | grep "${BINARY_NAME}-${os}-${arch}" | awk '{print $1}')
168-
169-
if [[ -z "$expected_checksum" ]]; then
170-
echo "Warning: No checksum found for ${BINARY_NAME}-${os}-${arch}. Skipping verification."
171-
return 0
172-
fi
173-
174-
local actual_checksum
175-
if command -v shasum &>/dev/null; then
176-
actual_checksum=$(shasum -a 256 "$binary_path" | awk '{print $1}')
177-
elif command -v sha256sum &>/dev/null; then
178-
actual_checksum=$(sha256sum "$binary_path" | awk '{print $1}')
179-
else
180-
return 0
181-
fi
182-
183-
if [[ "$actual_checksum" != "$expected_checksum" ]]; then
184-
echo ""
185-
echo "Error: Downloaded file appears corrupted."
186-
echo "Expected: $expected_checksum"
187-
echo "Got: $actual_checksum"
188-
echo ""
189-
echo "Please try again or download manually from:"
190-
echo " https://github.com/${REPO}/releases"
191-
rm -f "$binary_path"
192-
exit 1
193-
fi
194-
}
195-
196-
detect_shell() {
197-
local current_shell="${SHELL:-/bin/zsh}"
198-
case "$current_shell" in
199-
*/zsh) echo "zsh" ;;
200-
*/bash) echo "bash" ;;
201-
*/fish) echo "fish" ;;
202-
*) echo "zsh" ;;
203-
esac
204-
}
205-
206-
get_shell_rc_file() {
207-
local shell_type="$1"
208-
case "$shell_type" in
209-
zsh) echo "$HOME/.zshrc" ;;
210-
bash)
211-
if [[ -f "$HOME/.bash_profile" ]]; then
212-
echo "$HOME/.bash_profile"
213-
else
214-
echo "$HOME/.bashrc"
215-
fi
216-
;;
217-
fish) echo "$HOME/.config/fish/config.fish" ;;
218-
*) echo "$HOME/.zshrc" ;;
219-
esac
220-
}
221-
222-
create_env_file() {
223-
local env_file="$HOME/.openboot/env.sh"
224-
225-
if [[ -f "$env_file" ]]; then
226-
return 0
227-
fi
228-
229-
cat > "$env_file" << 'EOF'
230-
# OpenBoot environment setup
231-
export PATH="$HOME/.openboot/bin:$PATH"
232-
EOF
233-
234-
echo "Created $env_file"
235-
}
236-
237-
add_to_path() {
238-
if command -v openboot &>/dev/null; then
239-
local existing_path
240-
existing_path=$(command -v openboot)
241-
if [[ "$existing_path" != "$INSTALL_DIR/openboot" ]]; then
242-
echo "OpenBoot already available at: $existing_path"
243-
echo "Skipping PATH modification to avoid conflicts"
244-
echo ""
245-
echo "If you want to use the version at $INSTALL_DIR/openboot instead,"
246-
echo "remove the existing installation first or adjust your PATH manually."
247-
return 0
248-
fi
249-
fi
250-
251-
local shell_type
252-
shell_type=$(detect_shell)
253-
local rc_file
254-
rc_file=$(get_shell_rc_file "$shell_type")
255-
256-
if [[ -f "$rc_file" ]] && grep -qF '.openboot/bin' "$rc_file"; then
257-
echo "Already configured in $rc_file"
258-
return 0
259-
fi
260-
261-
if [[ "$shell_type" == "fish" ]]; then
262-
mkdir -p "$(dirname "$rc_file")"
263-
echo "" >> "$rc_file"
264-
echo "# OpenBoot" >> "$rc_file"
265-
echo 'set -gx PATH "$HOME/.openboot/bin" $PATH' >> "$rc_file"
266-
else
267-
create_env_file
268-
local source_line='[ -f "$HOME/.openboot/env.sh" ] && source "$HOME/.openboot/env.sh"'
269-
echo "" >> "$rc_file"
270-
echo "# OpenBoot" >> "$rc_file"
271-
echo "$source_line" >> "$rc_file"
272-
fi
273-
274-
echo "Added to PATH in $rc_file"
275-
276-
if [[ -d "$HOME/dotfiles" ]] || [[ -d "$HOME/.dotfiles" ]]; then
277-
echo ""
278-
echo "⚠️ Dotfiles detected!"
279-
echo "If your dotfiles overwrite $rc_file, add this line:"
280-
if [[ "$shell_type" == "fish" ]]; then
281-
echo ' set -gx PATH "$HOME/.openboot/bin" $PATH'
282-
else
283-
echo ' [ -f "$HOME/.openboot/env.sh" ] && source "$HOME/.openboot/env.sh"'
284-
fi
285-
echo ""
286-
fi
287-
}
288-
28989
main() {
29090
local snapshot_mode=false
29191
if [[ "${1:-}" == "snapshot" ]]; then
@@ -305,101 +105,65 @@ main() {
305105
fi
306106
echo ""
307107

308-
local os arch url binary_path
108+
local os arch
309109
os=$(detect_os)
310110
arch=$(detect_arch)
311111

312-
if [[ "$os" == "darwin" && "$snapshot_mode" == false ]]; then
313-
install_xcode_clt
314-
install_homebrew
315-
check_existing_installation
316-
fi
317-
318-
url=$(get_download_url "$os" "$arch")
319-
binary_path="${INSTALL_DIR}/${BINARY_NAME}"
320-
321112
echo "Detected: ${os}/${arch}"
322-
echo "Download URL: $url"
323-
echo "Install location: $binary_path"
324113
echo ""
325114

326115
if [[ "$DRY_RUN" == "true" ]]; then
327116
echo "Would perform:"
328-
echo " 1. mkdir -p $INSTALL_DIR"
329-
echo " 2. Download $url -> $binary_path"
330-
echo " 3. chmod +x $binary_path"
331-
echo " 4. Add to PATH via shell rc file"
117+
echo " 1. Check/Install Xcode Command Line Tools"
118+
echo " 2. Check/Install Homebrew"
119+
echo " 3. Run: brew tap ${TAP_NAME}"
120+
echo " 4. Run: brew install ${BINARY_NAME}"
121+
echo " 5. Launch: ${BINARY_NAME}"
332122
echo ""
333123
echo "To actually install, run without OPENBOOT_DRY_RUN:"
334124
echo " curl -fsSL https://openboot.dev/install.sh | bash"
335125
echo ""
336126
exit 0
337127
fi
338128

339-
echo "Downloading OpenBoot..."
340-
mkdir -p "$INSTALL_DIR"
341-
342-
local temp_binary="${INSTALL_DIR}/.openboot.tmp.$$"
343-
trap 'rm -f "$temp_binary"' EXIT INT TERM
344-
345-
if [[ -f "$binary_path" ]]; then
346-
local backup_path="${binary_path}.backup.$(date +%s)"
347-
echo "Backing up existing binary to: ${backup_path##*/}"
348-
mv "$binary_path" "$backup_path"
129+
if [[ "$os" == "darwin" && "$snapshot_mode" == false ]]; then
130+
install_xcode_clt
131+
install_homebrew
349132
fi
350133

351-
if ! curl -fsSL \
352-
--max-time 60 \
353-
--retry 3 \
354-
--retry-delay 2 \
355-
--proto '=https' \
356-
--tlsv1.2 \
357-
"$url" \
358-
-o "$temp_binary"; then
134+
if brew list openboot &>/dev/null 2>&1; then
135+
echo "OpenBoot is already installed via Homebrew."
359136
echo ""
360-
echo "Error: Failed to download OpenBoot"
361-
echo "URL: $url"
362-
echo ""
363-
echo "Please check: https://github.com/${REPO}/releases"
364-
exit 1
365-
fi
366-
367-
local file_size
368-
if command -v stat &>/dev/null; then
369-
if stat -f%z "$temp_binary" &>/dev/null 2>&1; then
370-
file_size=$(stat -f%z "$temp_binary")
137+
read -p "Reinstall? (y/N) " -n 1 -r
138+
echo
139+
140+
if [[ $REPLY =~ ^[Yy]$ ]]; then
141+
echo "Reinstalling OpenBoot..."
142+
brew reinstall openboot
143+
echo ""
144+
echo "✓ OpenBoot reinstalled!"
371145
else
372-
file_size=$(stat -c%s "$temp_binary" 2>/dev/null || echo "0")
146+
echo "Using existing installation."
373147
fi
374148
else
375-
file_size="0"
376-
fi
377-
378-
if [[ "$file_size" -lt 1000000 ]]; then
149+
echo "Installing OpenBoot via Homebrew..."
379150
echo ""
380-
echo "Error: Downloaded file is too small (${file_size} bytes)"
381-
echo "This may indicate a download error or invalid release"
382-
rm -f "$temp_binary"
383-
exit 1
384-
fi
385-
386-
verify_checksum "$temp_binary" "$os" "$arch"
387-
388-
chmod 755 "$temp_binary"
389-
390-
if ! mv "$temp_binary" "$binary_path"; then
151+
152+
if ! brew tap | grep -q "${TAP_NAME}"; then
153+
brew tap "${TAP_NAME}"
154+
fi
155+
156+
brew install openboot
157+
391158
echo ""
392-
echo "Error: Failed to install binary"
393-
exit 1
159+
echo "✓ OpenBoot installed!"
394160
fi
395161

396-
add_to_path
397-
export PATH="$INSTALL_DIR:$PATH"
398-
399-
echo "OpenBoot installed to $binary_path"
400162
echo ""
401-
402-
exec "$binary_path" "$@"
163+
echo "Starting OpenBoot setup..."
164+
echo ""
165+
166+
exec openboot "$@"
403167
}
404168

405169
main "$@"

0 commit comments

Comments
 (0)