Skip to content

Commit e505ee7

Browse files
committed
feat: add /install.sh endpoint and fix alias URL in docs
1 parent ea1f39c commit e505ee7

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

src/docs/config-options.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ Snapshot data attached to this config (auto-populated when creating from `openbo
9999

100100
### `alias`
101101

102-
Short URL alias for easy sharing. If set, the config is accessible at `openboot.dev/install?alias=<alias>`.
102+
Short URL alias for easy sharing. If set, the config is accessible at `openboot.dev/<alias>` — for example, `curl -fsSL https://openboot.dev/my-setup | bash`.
103103

104104
- **Type:** string
105105
- **Required:** no

src/docs/personal.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ It scans your Homebrew packages, macOS preferences, shell config, and git settin
3939
After uploading, you get a link:
4040

4141
```
42-
curl -fsSL https://openboot.dev/yourname/my-setup | bash
42+
curl -fsSL https://openboot.dev/yourname/my-setup/install.sh | bash
4343
```
4444

4545
Next time you switch machines, run that one command. You can also save locally without uploading:

src/hooks.server.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,42 @@ export const handle: Handle = async ({ event, resolve }) => {
8383
}
8484
}
8585

86+
const installShMatch = path.match(/^\/([a-z0-9_-]+)\/([a-z0-9_-]+)\/install\.sh$/i);
87+
if (installShMatch) {
88+
const env = event.platform?.env;
89+
if (env) {
90+
const username = installShMatch[1];
91+
const slug = installShMatch[2];
92+
93+
const user = await env.DB.prepare('SELECT id FROM users WHERE username = ?').bind(username).first<{ id: string }>();
94+
if (user) {
95+
const config = await env.DB.prepare('SELECT custom_script, visibility, dotfiles_repo FROM configs WHERE user_id = ? AND slug = ?')
96+
.bind(user.id, slug)
97+
.first<{ custom_script: string; visibility: string; dotfiles_repo: string }>();
98+
99+
if (config) {
100+
if (config.visibility === 'private') {
101+
const script = generatePrivateInstallScript(env.APP_URL, username, slug);
102+
return withSecurityHeaders(new Response(script, {
103+
headers: { 'Content-Type': 'text/plain; charset=utf-8', 'Cache-Control': 'no-cache' }
104+
}));
105+
}
106+
107+
const script = generateInstallScript(username, slug, config.custom_script, config.dotfiles_repo || '');
108+
109+
env.DB.prepare('UPDATE configs SET install_count = install_count + 1 WHERE user_id = ? AND slug = ?').bind(user.id, slug).run().catch(() => {});
110+
111+
return withSecurityHeaders(new Response(script, {
112+
headers: {
113+
'Content-Type': 'text/plain; charset=utf-8',
114+
'Cache-Control': 'no-cache'
115+
}
116+
}));
117+
}
118+
}
119+
}
120+
}
121+
86122
const twoSegMatch = path.match(/^\/([a-z0-9_-]+)\/([a-z0-9_-]+)$/i);
87123
if (twoSegMatch) {
88124
const ua = event.request.headers.get('user-agent') || '';

0 commit comments

Comments
 (0)