@ebowwa/seedinstallation 0.3.0 → 0.4.1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2025 Ebowwa Labs
3
+ Copyright (c) 2026 Ebowwa Labs
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,170 +1,62 @@
1
- # @cheapspaces/seedInstallation
1
+ # @ebowwa/seedinstallation
2
2
 
3
- Composable server installation utilities for edge deployment automation. This package provides a set of utilities for provisioning and managing servers, both locally and via SSH.
3
+ Composable server installation utilities for edge deployment automation.
4
4
 
5
5
  ## Features
6
6
 
7
- - **Sudo command execution** - Run commands with sudo privileges locally or via SSH
8
- - **Package management** - Install system packages (apt, dnf, apk)
9
- - **File operations** - Write to privileged paths with proper permissions
10
- - **Systemd service management** - Create, enable, and manage systemd services
11
- - **Runtime installation** - Install and configure runtimes like Bun
12
- - **Device-code authentication** - Handle OAuth device flows for Doppler, GitHub, Tailscale
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 @cheapspaces/seedInstallation
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
- createServiceUnit,
68
- enableAndStartService,
69
- getServiceStatus
70
- } from '@cheapspaces/seedInstallation';
71
-
72
- // Create a systemd service
73
- await createServiceUnit('myapp', {
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
- ### Device-Code Authentication
36
+ ### Environment Detection
95
37
 
96
38
  ```typescript
97
- import { deviceAuth, dopplerConfig } from '@cheapspaces/seedInstallation';
39
+ import { hasSystemd, safeSystemd } from "@ebowwa/seedinstallation/systemd";
98
40
 
99
- // Authenticate with Doppler via device code
100
- const result = await deviceAuth(dopplerConfig, {
101
- context: { type: 'local' },
102
- onPoll: (attempt, result) => {
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
- interface ExecResult {
163
- stdout: string;
164
- stderr: string;
165
- exitCode: number;
166
- ok: boolean;
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
@@ -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.js";
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: BootstrapPollOptions): Promise<{
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: BootstrapPollOptions): Promise<{
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;IA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