Skip to content

Commit 7909d9b

Browse files
committed
refactor: align config install script with main install.sh behavior
Install openboot via Homebrew tap instead of downloading a temp binary, matching the same interactive flow (Xcode CLT prompt, reinstall prompt) so curl openboot.dev/<alias> | bash behaves like curl openboot.dev/install.sh | bash.
1 parent 7cc1fcf commit 7909d9b

File tree

2 files changed

+107
-38
lines changed

2 files changed

+107
-38
lines changed

src/lib/server/install-script.test.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ describe('generateInstallScript', () => {
124124
const script = generateInstallScript('testuser', 'my-config', '', '');
125125

126126
expect(script).toContain('#!/bin/bash');
127-
expect(script).toContain('OpenBoot - Custom Install');
127+
expect(script).toContain('OpenBoot Installer');
128128
expect(script).toContain('Config: @testuser/my-config');
129-
expect(script).toContain('openboot-darwin-${ARCH}');
129+
expect(script).toContain('brew install ${TAP_NAME}/openboot');
130130
expect(script).toContain('--user "testuser/my-config"');
131131
});
132132

@@ -149,9 +149,9 @@ describe('generateInstallScript', () => {
149149
it('should handle ARM64 architecture', () => {
150150
const script = generateInstallScript('testuser', 'my-config', '', '');
151151

152-
expect(script).toContain('if [ "$ARCH" = "arm64" ]');
152+
expect(script).toContain('detect_arch()');
153153
expect(script).toContain('/opt/homebrew/bin/brew');
154-
expect(script).toContain('openboot-darwin-${ARCH}');
154+
expect(script).toContain('arm64)');
155155
});
156156

157157
it('should include custom script when provided', () => {
@@ -240,16 +240,18 @@ describe('generateInstallScript', () => {
240240
expect(script).toContain('Setting up Dotfiles');
241241
});
242242

243-
it('should include cleanup trap for temporary binary', () => {
243+
it('should install openboot via Homebrew tap', () => {
244244
const script = generateInstallScript('testuser', 'my-config', '', '');
245245

246-
expect(script).toContain('OPENBOOT_BIN="$TMPDIR/openboot-$$"');
247-
expect(script).toContain('trap \'rm -f "$OPENBOOT_BIN"\' EXIT');
246+
expect(script).toContain('TAP_NAME="openbootdotdev/tap"');
247+
expect(script).toContain('brew install ${TAP_NAME}/openboot');
248+
expect(script).toContain('brew list openboot');
249+
expect(script).toContain('Reinstall? (y/N)');
248250
});
249251

250-
it('should pass through additional arguments to openboot binary', () => {
252+
it('should pass through additional arguments to openboot', () => {
251253
const script = generateInstallScript('testuser', 'my-config', '', '');
252254

253-
expect(script).toContain('"$OPENBOOT_BIN" --user "testuser/my-config" "$@"');
255+
expect(script).toContain('openboot --user "testuser/my-config" "$@"');
254256
});
255257
});

src/lib/server/install-script.ts

Lines changed: 96 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -100,35 +100,58 @@ export function generateInstallScript(
100100
const safeSlug = sanitizeShellArg(slug);
101101

102102
return `#!/bin/bash
103-
set -e
103+
set -euo pipefail
104+
105+
TAP_NAME="openbootdotdev/tap"
104106
105107
main() {
106108
# When run via "curl | bash", stdin is the script content, not the terminal.
107-
# Reopen stdin from /dev/tty so interactive prompts (sudo, Homebrew) work.
108-
if [ ! -t 0 ] && [ -e /dev/tty ]; then
109+
# Reopen stdin from /dev/tty so interactive prompts (read, sudo, Homebrew) work.
110+
if [[ ! -t 0 ]] && [[ -e /dev/tty ]]; then
109111
exec < /dev/tty || true
110112
fi
111113
112-
echo "========================================"
113-
echo " OpenBoot - Custom Install"
114+
echo ""
115+
echo "OpenBoot Installer"
116+
echo "=================="
114117
echo " Config: @${safeUsername}/${safeSlug}"
115-
echo "========================================"
116118
echo ""
117119
118-
TMPDIR="\${TMPDIR:-/tmp}"
119-
OPENBOOT_BIN="\$TMPDIR/openboot-\$\$"
120+
detect_os() {
121+
local os
122+
os=\$(uname -s | tr '[:upper:]' '[:lower:]')
123+
case "\$os" in
124+
darwin) echo "darwin" ;;
125+
*) echo "Error: OpenBoot only supports macOS" >&2; exit 1 ;;
126+
esac
127+
}
120128
121-
trap 'rm -f "\$OPENBOOT_BIN"' EXIT
129+
detect_arch() {
130+
local arch
131+
arch=\$(uname -m)
132+
case "\$arch" in
133+
x86_64) echo "amd64" ;;
134+
arm64) echo "arm64" ;;
135+
aarch64) echo "arm64" ;;
136+
*) echo "unsupported: \$arch" >&2; exit 1 ;;
137+
esac
138+
}
122139
123140
install_xcode_clt() {
124141
if xcode-select -p &>/dev/null; then
125142
return 0
126143
fi
127-
echo "Installing Xcode Command Line Tools..."
128-
echo "(A dialog may appear - please click 'Install')"
144+
145+
echo ""
146+
echo "Xcode Command Line Tools need to be installed."
147+
echo "A dialog will appear - please click 'Install' and enter your password."
148+
echo ""
149+
read -p "Press Enter to launch installer..." -r
129150
echo ""
151+
130152
xcode-select --install 2>/dev/null || true
131-
echo "Waiting for Xcode Command Line Tools installation..."
153+
154+
echo "Waiting for installation to complete..."
132155
until xcode-select -p &>/dev/null; do
133156
sleep 5
134157
done
@@ -140,36 +163,80 @@ install_homebrew() {
140163
if command -v brew &>/dev/null; then
141164
return 0
142165
fi
166+
143167
echo "Installing Homebrew..."
144168
echo ""
145-
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
146-
if [ "$(uname -m)" = "arm64" ]; then
147-
eval "$(/opt/homebrew/bin/brew shellenv)"
148-
else
149-
eval "$(/usr/local/bin/brew shellenv)"
150-
fi
169+
170+
/bin/bash -c "\$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
171+
172+
local arch
173+
arch=\$(uname -m)
174+
case "\$arch" in
175+
arm64)
176+
if [[ -x "/opt/homebrew/bin/brew" ]]; then
177+
export PATH="/opt/homebrew/bin:/opt/homebrew/sbin:\$PATH"
178+
export HOMEBREW_PREFIX="/opt/homebrew"
179+
export HOMEBREW_CELLAR="/opt/homebrew/Cellar"
180+
export HOMEBREW_REPOSITORY="/opt/homebrew"
181+
fi
182+
;;
183+
x86_64)
184+
if [[ -x "/usr/local/bin/brew" ]]; then
185+
export PATH="/usr/local/bin:/usr/local/sbin:\$PATH"
186+
export HOMEBREW_PREFIX="/usr/local"
187+
export HOMEBREW_CELLAR="/usr/local/Cellar"
188+
export HOMEBREW_REPOSITORY="/usr/local/Homebrew"
189+
fi
190+
;;
191+
*)
192+
echo "Error: Unsupported architecture: \$arch" >&2
193+
exit 1
194+
;;
195+
esac
196+
197+
echo ""
151198
echo "Homebrew installed!"
152199
echo ""
153200
}
154201
202+
local os arch
203+
os=\$(detect_os)
204+
arch=\$(detect_arch)
205+
206+
echo "Detected: \${os}/\${arch}"
207+
echo ""
208+
155209
install_xcode_clt
156210
install_homebrew
157211
158-
ARCH="$(uname -m)"
159-
if [ "$ARCH" = "arm64" ]; then
160-
ARCH="arm64"
212+
if brew list openboot &>/dev/null 2>&1; then
213+
echo "OpenBoot is already installed via Homebrew."
214+
echo ""
215+
read -p "Reinstall? (y/N) " -n 1 -r
216+
echo
217+
218+
if [[ \$REPLY =~ ^[Yy]\$ ]]; then
219+
echo "Reinstalling OpenBoot..."
220+
brew reinstall \${TAP_NAME}/openboot
221+
echo ""
222+
echo "OpenBoot reinstalled!"
223+
else
224+
echo "Using existing installation."
225+
fi
161226
else
162-
ARCH="amd64"
163-
fi
227+
echo "Installing OpenBoot via Homebrew..."
228+
echo ""
164229
165-
OPENBOOT_URL="https://github.com/openbootdotdev/openboot/releases/latest/download/openboot-darwin-\${ARCH}"
230+
brew install \${TAP_NAME}/openboot
166231
167-
echo "Downloading OpenBoot..."
168-
curl -fsSL "\$OPENBOOT_URL" -o "\$OPENBOOT_BIN"
169-
chmod +x "\$OPENBOOT_BIN"
232+
echo ""
233+
echo "OpenBoot installed!"
234+
fi
170235
171-
echo "Using remote config: @${safeUsername}/${safeSlug}"
172-
"\$OPENBOOT_BIN" --user "${safeUsername}/${safeSlug}" "\$@"
236+
echo ""
237+
echo "Starting OpenBoot setup with config: @${safeUsername}/${safeSlug}"
238+
echo ""
239+
openboot --user "${safeUsername}/${safeSlug}" "\$@"
173240
174241
${
175242
customScript

0 commit comments

Comments
 (0)