@ebowwa/seedinstallation 0.2.4 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +36 -144
- package/dist/bootstrap.d.ts +5 -6
- package/dist/bootstrap.d.ts.map +1 -0
- package/dist/bootstrap.js +294 -215
- package/dist/clone.d.ts +1 -0
- package/dist/clone.d.ts.map +1 -0
- package/dist/clone.js +54 -68
- package/dist/device-auth.d.ts +4 -5
- package/dist/device-auth.d.ts.map +1 -0
- package/dist/device-auth.js +252 -164
- package/dist/index.d.ts +13 -12
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +941 -10
- package/dist/runtime.d.ts +9 -14
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +211 -114
- package/dist/sudo.d.ts +1 -0
- package/dist/sudo.d.ts.map +1 -0
- package/dist/sudo.js +123 -222
- package/dist/systemd.d.ts +207 -3
- package/dist/systemd.d.ts.map +1 -0
- package/dist/systemd.js +477 -177
- package/package.json +40 -40
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,170 +1,62 @@
|
|
|
1
|
-
# @
|
|
1
|
+
# @ebowwa/seedinstallation
|
|
2
2
|
|
|
3
|
-
Composable server installation utilities for edge deployment automation.
|
|
3
|
+
Composable server installation utilities for edge deployment automation.
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
-
- **
|
|
8
|
-
- **
|
|
9
|
-
- **
|
|
10
|
-
- **
|
|
11
|
-
- **
|
|
12
|
-
- **
|
|
13
|
-
- **Bootstrap tracking** - Track provisioning phases and status
|
|
14
|
-
- **Git cloning** - Composable git clone with shallow/sparse support
|
|
7
|
+
- **systemd** - Create/manage systemd services with security hardening
|
|
8
|
+
- **sudo** - Run commands as root via SSH (remote execution)
|
|
9
|
+
- **bootstrap** - Bootstrap/configure new servers
|
|
10
|
+
- **device-auth** - Device login flows (GitHub, Doppler, Tailscale)
|
|
11
|
+
- **clone** - Clone git repositories
|
|
12
|
+
- **runtime** - Detect runtime environment (VPS vs local)
|
|
15
13
|
|
|
16
14
|
## Installation
|
|
17
15
|
|
|
18
16
|
```bash
|
|
19
|
-
npm install @
|
|
17
|
+
npm install @ebowwa/seedinstallation
|
|
20
18
|
```
|
|
21
19
|
|
|
22
20
|
## Usage
|
|
23
21
|
|
|
24
|
-
### Local Command Execution
|
|
25
|
-
|
|
26
|
-
```typescript
|
|
27
|
-
import { sudo, pkgInstall } from '@cheapspaces/seedInstallation';
|
|
28
|
-
|
|
29
|
-
// Run a command with sudo
|
|
30
|
-
const result = await sudo(['apt-get', 'update'], {
|
|
31
|
-
context: { type: 'local' }
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
// Install packages
|
|
35
|
-
await pkgInstall(['git', 'curl', 'vim'], {
|
|
36
|
-
context: { type: 'local' },
|
|
37
|
-
pm: 'apt'
|
|
38
|
-
});
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
### Remote SSH Execution
|
|
42
|
-
|
|
43
|
-
```typescript
|
|
44
|
-
import { sudo, writeFile } from '@cheapspaces/seedInstallation';
|
|
45
|
-
|
|
46
|
-
// Run commands over SSH
|
|
47
|
-
const result = await sudo(['systemctl', 'status', 'nginx'], {
|
|
48
|
-
context: {
|
|
49
|
-
type: 'ssh',
|
|
50
|
-
host: '192.168.1.100',
|
|
51
|
-
user: 'root',
|
|
52
|
-
keyPath: '/path/to/key'
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
// Write files to remote server
|
|
57
|
-
await writeFile('/etc/nginx/nginx.conf', configContent, {
|
|
58
|
-
context: { type: 'ssh', host: '192.168.1.100' },
|
|
59
|
-
mode: '644'
|
|
60
|
-
});
|
|
61
|
-
```
|
|
62
|
-
|
|
63
22
|
### Systemd Service Management
|
|
64
23
|
|
|
65
24
|
```typescript
|
|
66
|
-
import {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
description: 'My Application',
|
|
75
|
-
workingDirectory: '/opt/myapp',
|
|
76
|
-
execStart: '/usr/bin/node /opt/myapp/index.js',
|
|
77
|
-
restart: 'always',
|
|
78
|
-
environment: {
|
|
79
|
-
NODE_ENV: 'production'
|
|
80
|
-
}
|
|
81
|
-
}, { context: { type: 'local' } });
|
|
82
|
-
|
|
83
|
-
// Enable and start the service
|
|
84
|
-
await enableAndStartService('myapp', {
|
|
85
|
-
context: { type: 'local' }
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
// Check service status
|
|
89
|
-
const status = await getServiceStatus('myapp', {
|
|
90
|
-
context: { type: 'local' }
|
|
25
|
+
import { createServiceUnit, SECURITY_PRESETS } from "@ebowwa/seedinstallation/systemd";
|
|
26
|
+
|
|
27
|
+
await createServiceUnit("my-api", {
|
|
28
|
+
description: "My API Service",
|
|
29
|
+
workingDirectory: "/opt/my-api",
|
|
30
|
+
execStart: "/usr/bin/node index.js",
|
|
31
|
+
...SECURITY_PRESETS.network,
|
|
32
|
+
context: { host: "5.161.83.44", user: "root" }
|
|
91
33
|
});
|
|
92
34
|
```
|
|
93
35
|
|
|
94
|
-
###
|
|
36
|
+
### Environment Detection
|
|
95
37
|
|
|
96
38
|
```typescript
|
|
97
|
-
import {
|
|
39
|
+
import { hasSystemd, safeSystemd } from "@ebowwa/seedinstallation/systemd";
|
|
98
40
|
|
|
99
|
-
//
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
console.log(`Polling... attempt ${attempt}`);
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
if (result.success) {
|
|
108
|
-
console.log(`Visit: ${result.url}`);
|
|
109
|
-
console.log(`Code: ${result.code}`);
|
|
110
|
-
}
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
### Git Cloning
|
|
114
|
-
|
|
115
|
-
```typescript
|
|
116
|
-
import { clone } from '@cheapspaces/seedInstallation/clone';
|
|
117
|
-
|
|
118
|
-
// Basic clone
|
|
119
|
-
const { path, commit } = await clone({
|
|
120
|
-
repo: 'https://github.com/user/repo.git'
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
// Shallow clone of specific branch
|
|
124
|
-
await clone({
|
|
125
|
-
repo: 'https://github.com/user/repo.git',
|
|
126
|
-
ref: 'main',
|
|
127
|
-
depth: 1,
|
|
128
|
-
dest: 'my-repo'
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
// Sparse checkout (only specific paths)
|
|
132
|
-
await clone({
|
|
133
|
-
repo: 'https://github.com/user/repo.git',
|
|
134
|
-
sparse: ['src/lib', 'src/types'],
|
|
135
|
-
depth: 1
|
|
136
|
-
});
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
## API
|
|
140
|
-
|
|
141
|
-
### Modules
|
|
142
|
-
|
|
143
|
-
- `.` - Main exports (all utilities)
|
|
144
|
-
- `./clone` - Git clone utilities
|
|
145
|
-
- `./sudo` - Sudo command execution
|
|
146
|
-
- `./runtime` - Runtime installation and PATH management
|
|
147
|
-
- `./systemd` - Systemd service management
|
|
148
|
-
- `./device-auth` - Device-code authentication flows
|
|
149
|
-
- `./bootstrap` - Bootstrap status tracking
|
|
150
|
-
|
|
151
|
-
### Types
|
|
152
|
-
|
|
153
|
-
```typescript
|
|
154
|
-
interface ExecContext {
|
|
155
|
-
type: 'local' | 'ssh';
|
|
156
|
-
host?: string;
|
|
157
|
-
user?: string;
|
|
158
|
-
keyPath?: string;
|
|
159
|
-
port?: number;
|
|
41
|
+
// Check if systemd is available
|
|
42
|
+
const check = await hasSystemd();
|
|
43
|
+
if (!check.available) {
|
|
44
|
+
console.log("No systemd - running in container/codespaces");
|
|
160
45
|
}
|
|
161
46
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
47
|
+
// Safe wrapper with fallback
|
|
48
|
+
await safeSystemd(
|
|
49
|
+
async () => {
|
|
50
|
+
await createServiceUnit("my-service", { ... });
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
requireSystemd: false,
|
|
54
|
+
onNoSystemd: async (check) => {
|
|
55
|
+
console.log(`No systemd: ${check.message}`);
|
|
56
|
+
// Fallback: run process directly
|
|
57
|
+
},
|
|
58
|
+
}
|
|
59
|
+
);
|
|
168
60
|
```
|
|
169
61
|
|
|
170
62
|
## License
|
package/dist/bootstrap.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Manages phase markers, status files, and polling for completion.
|
|
4
4
|
* Works with both local and SSH contexts via ExecContext from sudo.ts.
|
|
5
5
|
*/
|
|
6
|
-
import type { SudoOptions, ExecResult } from "./sudo
|
|
6
|
+
import type { SudoOptions, ExecResult } from "./sudo";
|
|
7
7
|
export interface BootstrapPhase {
|
|
8
8
|
/** Phase name (e.g. "bun", "seed", "doppler") */
|
|
9
9
|
name: string;
|
|
@@ -30,9 +30,7 @@ export interface BootstrapStatus {
|
|
|
30
30
|
/** Raw file content */
|
|
31
31
|
raw: string;
|
|
32
32
|
}
|
|
33
|
-
export interface BootstrapPollOptions {
|
|
34
|
-
/** Execution context for running commands */
|
|
35
|
-
context: SudoOptions["context"];
|
|
33
|
+
export interface BootstrapPollOptions extends SudoOptions {
|
|
36
34
|
/** Maximum poll attempts (default: 30) */
|
|
37
35
|
maxAttempts?: number;
|
|
38
36
|
/** Interval between polls in ms (default: 2000) */
|
|
@@ -101,14 +99,15 @@ export declare function removeMarker(markerPath: string, opts: SudoOptions): Pro
|
|
|
101
99
|
*
|
|
102
100
|
* Returns the final status (complete or failed/timeout).
|
|
103
101
|
*/
|
|
104
|
-
export declare function waitForBootstrap(statusFile: string, opts
|
|
102
|
+
export declare function waitForBootstrap(statusFile: string, opts?: BootstrapPollOptions): Promise<{
|
|
105
103
|
completed: boolean;
|
|
106
104
|
status: BootstrapStatus;
|
|
107
105
|
}>;
|
|
108
106
|
/**
|
|
109
107
|
* Poll until a marker file exists.
|
|
110
108
|
*/
|
|
111
|
-
export declare function waitForMarker(markerPath: string, opts
|
|
109
|
+
export declare function waitForMarker(markerPath: string, opts?: BootstrapPollOptions): Promise<{
|
|
112
110
|
exists: boolean;
|
|
113
111
|
timedOut: boolean;
|
|
114
112
|
}>;
|
|
113
|
+
//# sourceMappingURL=bootstrap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../bootstrap.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAiBtD,MAAM,WAAW,cAAc;IAC7B,iDAAiD;IACjD,IAAI,EAAE,MAAM,CAAC;IACb,mCAAmC;IACnC,MAAM,EAAE,SAAS,GAAG,SAAS,GAAG,UAAU,GAAG,QAAQ,CAAC;IACtD,uCAAuC;IACvC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,yCAAyC;IACzC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,8BAA8B;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,eAAe;IAC9B,+BAA+B;IAC/B,MAAM,EAAE,SAAS,GAAG,SAAS,GAAG,UAAU,GAAG,QAAQ,CAAC;IACtD,2CAA2C;IAC3C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,6CAA6C;IAC7C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,wDAAwD;IACxD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gCAAgC;IAChC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IACvC,uBAAuB;IACvB,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,oBAAqB,SAAQ,WAAW;IACvD,0CAA0C;IAC1C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,mDAAmD;I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