haoshoku 2.1.0 → 2.1.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/haoshoku.js CHANGED
@@ -12,7 +12,7 @@ const program = new Command();
12
12
  program
13
13
  .name("haoshoku")
14
14
  .description("Haoshoku: Color of the Supreme King. Dominate your setup.")
15
- .version("2.0.0");
15
+ .version("2.1.1");
16
16
 
17
17
  function detectOS() {
18
18
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "haoshoku",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "module": "haoshoku.js",
5
5
  "type": "module",
6
6
  "bin": {
@@ -3,6 +3,7 @@ import prompts from "prompts";
3
3
  import path from "path";
4
4
  import fs from "fs";
5
5
  import { homedir } from "os";
6
+ import net from "net";
6
7
 
7
8
  // --- Constants ---
8
9
  const HOME = homedir();
@@ -143,11 +144,90 @@ async function setupFirewall() {
143
144
  }
144
145
  }
145
146
 
147
+ function checkPortAvailability(port) {
148
+ return new Promise((resolve) => {
149
+ const server = net.createServer();
150
+ server.once("error", (err) => {
151
+ resolve(false);
152
+ });
153
+ server.once("listening", () => {
154
+ server.close();
155
+ resolve(true);
156
+ });
157
+ server.listen(port);
158
+ });
159
+ }
160
+
161
+ async function installDashy() {
162
+ if (await promptUser("Install Dashy (Personal Dashboard)?", true)) {
163
+ const servicesDir = path.join(HOME, "services");
164
+ const dashyDir = path.join(servicesDir, "dashy");
165
+ const sourceDir = path.join(PROJECT_ROOT, "services", "dashy");
166
+
167
+ if (!fs.existsSync(sourceDir)) {
168
+ log.error(`Dashy source not found at ${sourceDir}`);
169
+ return;
170
+ }
171
+
172
+ // Port selection
173
+ let port = 8080;
174
+ let isAvailable = await checkPortAvailability(port);
175
+
176
+ if (!isAvailable) {
177
+ log.warning(`Port ${port} is already in use.`);
178
+ const response = await prompts({
179
+ type: "number",
180
+ name: "port",
181
+ message: "Enter a different port for Dashy:",
182
+ initial: 8081,
183
+ validate: async (p) => (await checkPortAvailability(p)) ? true : "Port is still in use",
184
+ });
185
+ port = response.port;
186
+ }
187
+
188
+ log.info(`Installing Dashy on port ${port}...`);
189
+
190
+ // Copy files
191
+ if (!fs.existsSync(servicesDir)) {
192
+ fs.mkdirSync(servicesDir, { recursive: true });
193
+ }
194
+
195
+ // Using cp -r for simplicity and preserving permissions
196
+ await runCommand(`cp -r ${sourceDir} ${servicesDir}`);
197
+
198
+ // Update port in docker-compose.yml if changed
199
+ if (port !== 8080) {
200
+ const composePath = path.join(dashyDir, "docker-compose.yml");
201
+ if (fs.existsSync(composePath)) {
202
+ let content = fs.readFileSync(composePath, "utf-8");
203
+ content = content.replace("8080:80", `${port}:80`);
204
+ fs.writeFileSync(composePath, content);
205
+ log.info(`Updated Dashy port to ${port} in docker-compose.yml`);
206
+ }
207
+ }
208
+
209
+ // Start service
210
+ log.info("Starting Dashy...");
211
+ // We need to run docker compose in the dashy directory
212
+ // runCommand doesn't support cwd option directly based on usage seen,
213
+ // so we construct the command to change dir or use -f and -p?
214
+ // Actually runCommand implementation in utils.js likely supports options or we can chain cd.
215
+ // Let's check utils.js or just chain.
216
+ // Assuming runCommand takes options based on standard exec wrappers, but looking at previous file view,
217
+ // I don't see the definition of runCommand.
218
+ // Let's assume `cd ... && ...` works for shell commands.
219
+ await runCommand(`cd ${dashyDir} && docker compose up -d`);
220
+
221
+ log.success(`Dashy installed! Access it at http://localhost:${port}`);
222
+ }
223
+ }
224
+
146
225
  export async function runDebianServerSetup() {
147
226
  await installEssentials();
148
227
  await setupSsh();
149
228
  await configureFishShell();
150
229
  await installDocker();
230
+ await installDashy();
151
231
  await setupFirewall();
152
232
 
153
233
  log.success("Debian Server setup finished.");