Skip to content

Commit 3225f27

Browse files
committed
fix: add sudo caching and fix script execution order
- Prompt for sudo password upfront to prevent cask install failures - Run custom script (Oh-My-Zsh) BEFORE dotfiles stow to prevent .zshrc conflicts - Deduplicate generateInstallScript by exporting from hooks.server.ts
1 parent 39b3e75 commit 3225f27

File tree

2 files changed

+20
-87
lines changed

2 files changed

+20
-87
lines changed

src/hooks.server.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Handle } from '@sveltejs/kit';
22

3-
function generateInstallScript(username: string, slug: string, customScript: string, dotfilesRepo: string): string {
3+
export function generateInstallScript(username: string, slug: string, customScript: string, dotfilesRepo: string): string {
44
return `#!/bin/bash
55
set -e
66
@@ -10,6 +10,12 @@ echo " Config: @${username}/${slug}"
1010
echo "========================================"
1111
echo ""
1212
13+
echo "Some installations require admin privileges."
14+
sudo -v
15+
( while true; do sudo -n true; sleep 50; done ) 2>/dev/null &
16+
SUDO_KEEPALIVE_PID=$!
17+
trap "kill $SUDO_KEEPALIVE_PID 2>/dev/null; rm -f \\"\$OPENBOOT_BIN\\"" EXIT
18+
1319
install_xcode_clt() {
1420
if xcode-select -p &>/dev/null; then
1521
return 0
@@ -56,8 +62,7 @@ OPENBOOT_URL="https://github.com/openbootdotdev/openboot/releases/latest/downloa
5662
TMPDIR="\${TMPDIR:-/tmp}"
5763
OPENBOOT_BIN="\$TMPDIR/openboot-\$\$"
5864
59-
cleanup() { rm -f "\$OPENBOOT_BIN"; }
60-
trap cleanup EXIT
65+
6166
6267
echo "Downloading OpenBoot..."
6368
curl -fsSL "\$OPENBOOT_URL" -o "\$OPENBOOT_BIN"
@@ -66,6 +71,17 @@ chmod +x "\$OPENBOOT_BIN"
6671
echo "Using remote config: @${username}/${slug}"
6772
"\$OPENBOOT_BIN" --user ${username}/${slug} "\$@"
6873
74+
${
75+
customScript
76+
? `
77+
echo ""
78+
echo "=== Running Custom Post-Install Script ==="
79+
set +e
80+
${customScript}
81+
set -e
82+
`
83+
: ''
84+
}
6985
${
7086
dotfilesRepo
7187
? `
@@ -88,17 +104,6 @@ echo "Deploying dotfiles with stow..."
88104
for dir in */; do
89105
[ -d "\$dir" ] && stow -v --target="\$HOME" "\${dir%/}" 2>/dev/null || true
90106
done
91-
`
92-
: ''
93-
}
94-
${
95-
customScript
96-
? `
97-
echo ""
98-
echo "=== Running Custom Post-Install Script ==="
99-
set +e
100-
${customScript}
101-
set -e
102107
`
103108
: ''
104109
}

src/routes/[username]/[slug]/install/+server.ts

Lines changed: 1 addition & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,5 @@
11
import type { RequestHandler } from './$types';
2-
3-
function generateInstallScript(username: string, slug: string, customScript: string, dotfilesRepo: string): string {
4-
return `#!/bin/bash
5-
set -e
6-
7-
echo "========================================"
8-
echo " OpenBoot - Custom Install"
9-
echo " Config: @${username}/${slug}"
10-
echo "========================================"
11-
echo ""
12-
13-
ARCH="$(uname -m)"
14-
if [ "$ARCH" = "arm64" ]; then
15-
ARCH="arm64"
16-
else
17-
ARCH="amd64"
18-
fi
19-
20-
OPENBOOT_URL="https://github.com/openbootdotdev/openboot/releases/latest/download/openboot-darwin-\${ARCH}"
21-
TMPDIR="\${TMPDIR:-/tmp}"
22-
OPENBOOT_BIN="\$TMPDIR/openboot-\$\$"
23-
24-
cleanup() { rm -f "\$OPENBOOT_BIN"; }
25-
trap cleanup EXIT
26-
27-
echo "Downloading OpenBoot..."
28-
curl -fsSL "\$OPENBOOT_URL" -o "\$OPENBOOT_BIN"
29-
chmod +x "\$OPENBOOT_BIN"
30-
31-
echo "Using remote config: @${username}/${slug}"
32-
"\$OPENBOOT_BIN" --user ${username}/${slug} "\$@"
33-
34-
${
35-
dotfilesRepo
36-
? `
37-
echo ""
38-
echo "=== Setting up Dotfiles ==="
39-
DOTFILES_REPO="${dotfilesRepo}"
40-
DOTFILES_DIR="\$HOME/.dotfiles"
41-
42-
if [ -d "\$DOTFILES_DIR" ]; then
43-
echo "Dotfiles directory already exists at \$DOTFILES_DIR"
44-
echo "Pulling latest changes..."
45-
cd "\$DOTFILES_DIR" && git pull
46-
else
47-
echo "Cloning dotfiles from \$DOTFILES_REPO..."
48-
git clone "\$DOTFILES_REPO" "\$DOTFILES_DIR"
49-
fi
50-
51-
cd "\$DOTFILES_DIR"
52-
if [ -f "Makefile" ]; then
53-
echo "Running make deploy..."
54-
make deploy
55-
else
56-
echo "No Makefile found in dotfiles repo, skipping deploy"
57-
fi
58-
`
59-
: ''
60-
}
61-
${
62-
customScript
63-
? `
64-
echo ""
65-
echo "=== Running Custom Post-Install Script ==="
66-
${customScript}
67-
`
68-
: ''
69-
}
70-
71-
echo ""
72-
echo "Installation complete!"
73-
`;
74-
}
2+
import { generateInstallScript } from '../../../../hooks.server';
753

764
export const GET: RequestHandler = async ({ platform, params }) => {
775
const env = platform?.env;

0 commit comments

Comments
 (0)