Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/lib/server/install-script.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ describe('generateInstallScript', () => {
expect(script).toContain('#!/bin/bash');
expect(script).toContain('OpenBoot Installer');
expect(script).toContain('Config: @testuser/my-config');
expect(script).toContain('brew install ${TAP_NAME}/openboot');
expect(script).toContain('api.github.com/repos/${OPENBOOT_REPO}/releases/latest');
expect(script).toContain('--user "testuser/my-config"');
});

Expand Down Expand Up @@ -182,13 +182,13 @@ describe('generateInstallScript', () => {
expect(script).not.toContain('my config!');
});

it('should install openboot via Homebrew tap', () => {
it('should install openboot via GitHub releases', () => {
const script = generateInstallScript('testuser', 'my-config');

expect(script).toContain('TAP_NAME="openbootdotdev/tap"');
expect(script).toContain('brew install ${TAP_NAME}/openboot');
expect(script).toContain('brew list openboot');
expect(script).toContain('Reinstall? (y/N)');
expect(script).toContain('OPENBOOT_REPO="openbootdotdev/openboot"');
expect(script).toContain('api.github.com/repos/${OPENBOOT_REPO}/releases/latest');
expect(script).toContain('install_openboot()');
expect(script).toContain('github.com/${OPENBOOT_REPO}/releases/download/${latest_version}/openboot-');
});

it('should pass through additional arguments to openboot', () => {
Expand Down
59 changes: 34 additions & 25 deletions src/lib/server/install-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export function generateInstallScript(
return `#!/bin/bash
set -euo pipefail

TAP_NAME="openbootdotdev/tap"
OPENBOOT_REPO="openbootdotdev/openboot"

main() {
# When run via "curl | bash", stdin is the script content, not the terminal.
Expand Down Expand Up @@ -205,39 +205,48 @@ install_homebrew() {
echo ""
}

local os arch
os=\$(detect_os)
arch=\$(detect_arch)
install_openboot() {
local os_name="\$1"
local arch_name="\$2"

echo "Detected: \${os}/\${arch}"
echo ""
echo "Fetching latest OpenBoot version..."
local latest_version
latest_version=\$(curl -fsSL "https://api.github.com/repos/\${OPENBOOT_REPO}/releases/latest" \\
| grep '"tag_name"' | grep -o 'v[0-9][0-9.]*')

install_xcode_clt
install_homebrew
if [[ -z "\$latest_version" ]]; then
echo "Error: Could not fetch latest OpenBoot version" >&2
exit 1
fi

local binary_url="https://github.com/\${OPENBOOT_REPO}/releases/download/\${latest_version}/openboot-\${os_name}-\${arch_name}"

if brew list openboot &>/dev/null 2>&1; then
echo "OpenBoot is already installed via Homebrew."
echo "Installing OpenBoot \${latest_version}..."
echo ""
read -p "Reinstall? (y/N) " -n 1 -r
echo

if [[ \$REPLY =~ ^[Yy]\$ ]]; then
echo "Reinstalling OpenBoot..."
brew reinstall \${TAP_NAME}/openboot
echo ""
echo "OpenBoot reinstalled!"

curl -fsSL "\$binary_url" -o /tmp/openboot-install
chmod +x /tmp/openboot-install

if [[ -w "/usr/local/bin" ]]; then
mv /tmp/openboot-install /usr/local/bin/openboot
else
echo "Using existing installation."
sudo mv /tmp/openboot-install /usr/local/bin/openboot
fi
else
echo "Installing OpenBoot via Homebrew..."

echo ""
echo "OpenBoot \${latest_version} installed!"
}

brew install \${TAP_NAME}/openboot
local os arch
os=\$(detect_os)
arch=\$(detect_arch)

echo ""
echo "OpenBoot installed!"
fi
echo "Detected: \${os}/\${arch}"
echo ""

install_xcode_clt
install_homebrew
install_openboot "\$os" "\$arch"

echo ""
echo "Starting OpenBoot setup with config: @${safeUsername}/${safeSlug}"
Expand Down
Loading