haoshoku 2.1.0 → 2.1.2

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.2");
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.2",
4
4
  "module": "haoshoku.js",
5
5
  "type": "module",
6
6
  "bin": {
@@ -3,6 +3,8 @@ 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";
7
+ import { fileURLToPath } from "url";
6
8
 
7
9
  // --- Constants ---
8
10
  const HOME = homedir();
@@ -10,7 +12,9 @@ const FISH_CONFIG_DIR = path.join(HOME, ".config", "fish");
10
12
  const STARSHIP_CONFIG_PATH = path.join(HOME, ".config", "starship.toml");
11
13
 
12
14
  // Project paths
13
- const PROJECT_ROOT = process.cwd();
15
+ const __filename = fileURLToPath(import.meta.url);
16
+ const __dirname = path.dirname(__filename);
17
+ const PROJECT_ROOT = path.resolve(__dirname, "..", "..");
14
18
  const CONFIGS_DIR = path.join(PROJECT_ROOT, "configs");
15
19
  const CUSTOM_FISH_CONFIG_PATH = path.join(CONFIGS_DIR, "fish", "config.fish");
16
20
 
@@ -32,7 +36,10 @@ async function installEssentials() {
32
36
  // Split installation to ensure core tools are installed even if optional ones fail
33
37
  await runCommand("sudo apt install -y curl wget git vim ufw fail2ban");
34
38
  // Try installing software-properties-common separately as it might not be available on all minimal images
35
- await runCommand("sudo apt install -y software-properties-common", { check: false });
39
+ const spcResult = await runCommand("sudo apt install -y software-properties-common", { check: false });
40
+ if (!spcResult) {
41
+ log.warning("Could not install software-properties-common. Some PPAs might not work.");
42
+ }
36
43
  }
37
44
 
38
45
  async function setupSsh() {
@@ -59,10 +66,12 @@ async function setupSsh() {
59
66
  async function configureFishShell() {
60
67
  if (!(await commandExists("fish"))) {
61
68
  log.info("Installing Fish shell...");
62
- // Only try adding PPA if software-properties-common was installed successfully
69
+ // Only try adding PPA if add-apt-repository is available
63
70
  if (await commandExists("add-apt-repository")) {
64
71
  await runCommand("sudo apt-add-repository -y ppa:fish-shell/release-3");
65
72
  await runCommand("sudo apt update");
73
+ } else {
74
+ log.warning("add-apt-repository not found. Installing fish from default repositories (might be older version).");
66
75
  }
67
76
  await runCommand("sudo apt install -y fish");
68
77
  }
@@ -143,11 +152,90 @@ async function setupFirewall() {
143
152
  }
144
153
  }
145
154
 
155
+ function checkPortAvailability(port) {
156
+ return new Promise((resolve) => {
157
+ const server = net.createServer();
158
+ server.once("error", (err) => {
159
+ resolve(false);
160
+ });
161
+ server.once("listening", () => {
162
+ server.close();
163
+ resolve(true);
164
+ });
165
+ server.listen(port);
166
+ });
167
+ }
168
+
169
+ async function installDashy() {
170
+ if (await promptUser("Install Dashy (Personal Dashboard)?", true)) {
171
+ const servicesDir = path.join(HOME, "services");
172
+ const dashyDir = path.join(servicesDir, "dashy");
173
+ const sourceDir = path.join(PROJECT_ROOT, "services", "dashy");
174
+
175
+ if (!fs.existsSync(sourceDir)) {
176
+ log.error(`Dashy source not found at ${sourceDir}`);
177
+ return;
178
+ }
179
+
180
+ // Port selection
181
+ let port = 8080;
182
+ let isAvailable = await checkPortAvailability(port);
183
+
184
+ if (!isAvailable) {
185
+ log.warning(`Port ${port} is already in use.`);
186
+ const response = await prompts({
187
+ type: "number",
188
+ name: "port",
189
+ message: "Enter a different port for Dashy:",
190
+ initial: 8081,
191
+ validate: async (p) => (await checkPortAvailability(p)) ? true : "Port is still in use",
192
+ });
193
+ port = response.port;
194
+ }
195
+
196
+ log.info(`Installing Dashy on port ${port}...`);
197
+
198
+ // Copy files
199
+ if (!fs.existsSync(servicesDir)) {
200
+ fs.mkdirSync(servicesDir, { recursive: true });
201
+ }
202
+
203
+ // Using cp -r for simplicity and preserving permissions
204
+ await runCommand(`cp -r ${sourceDir} ${servicesDir}`);
205
+
206
+ // Update port in docker-compose.yml if changed
207
+ if (port !== 8080) {
208
+ const composePath = path.join(dashyDir, "docker-compose.yml");
209
+ if (fs.existsSync(composePath)) {
210
+ let content = fs.readFileSync(composePath, "utf-8");
211
+ content = content.replace("8080:80", `${port}:80`);
212
+ fs.writeFileSync(composePath, content);
213
+ log.info(`Updated Dashy port to ${port} in docker-compose.yml`);
214
+ }
215
+ }
216
+
217
+ // Start service
218
+ log.info("Starting Dashy...");
219
+ // We need to run docker compose in the dashy directory
220
+ // runCommand doesn't support cwd option directly based on usage seen,
221
+ // so we construct the command to change dir or use -f and -p?
222
+ // Actually runCommand implementation in utils.js likely supports options or we can chain cd.
223
+ // Let's check utils.js or just chain.
224
+ // Assuming runCommand takes options based on standard exec wrappers, but looking at previous file view,
225
+ // I don't see the definition of runCommand.
226
+ // Let's assume `cd ... && ...` works for shell commands.
227
+ await runCommand(`cd ${dashyDir} && docker compose up -d`);
228
+
229
+ log.success(`Dashy installed! Access it at http://localhost:${port}`);
230
+ }
231
+ }
232
+
146
233
  export async function runDebianServerSetup() {
147
234
  await installEssentials();
148
235
  await setupSsh();
149
236
  await configureFishShell();
150
237
  await installDocker();
238
+ await installDashy();
151
239
  await setupFirewall();
152
240
 
153
241
  log.success("Debian Server setup finished.");