fluxy-bot 0.6.1 → 0.6.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/bin/cli.js +17 -27
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -32,6 +32,18 @@ function needsSudo() {
|
|
|
32
32
|
return process.getuid() !== 0;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
function sudoReExec() {
|
|
36
|
+
const nodePath = process.env.FLUXY_NODE_PATH || process.execPath;
|
|
37
|
+
const realHome = getRealHome();
|
|
38
|
+
const args = process.argv.slice(1);
|
|
39
|
+
const result = spawnSync('sudo', [
|
|
40
|
+
`FLUXY_NODE_PATH=${nodePath}`,
|
|
41
|
+
`FLUXY_REAL_HOME=${realHome}`,
|
|
42
|
+
nodePath, ...args,
|
|
43
|
+
], { stdio: 'inherit' });
|
|
44
|
+
process.exit(result.status ?? 1);
|
|
45
|
+
}
|
|
46
|
+
|
|
35
47
|
function getRealUser() {
|
|
36
48
|
return process.env.SUDO_USER || os.userInfo().username;
|
|
37
49
|
}
|
|
@@ -1478,17 +1490,7 @@ async function daemon(sub) {
|
|
|
1478
1490
|
}
|
|
1479
1491
|
|
|
1480
1492
|
// Re-exec with sudo if needed
|
|
1481
|
-
if (needsSudo())
|
|
1482
|
-
const nodePath = process.env.FLUXY_NODE_PATH || process.execPath;
|
|
1483
|
-
const realHome = getRealHome();
|
|
1484
|
-
const args = process.argv.slice(1);
|
|
1485
|
-
const result = spawnSync('sudo', [
|
|
1486
|
-
`FLUXY_NODE_PATH=${nodePath}`,
|
|
1487
|
-
`FLUXY_REAL_HOME=${realHome}`,
|
|
1488
|
-
nodePath, ...args,
|
|
1489
|
-
], { stdio: 'inherit' });
|
|
1490
|
-
process.exit(result.status ?? 1);
|
|
1491
|
-
}
|
|
1493
|
+
if (needsSudo()) sudoReExec();
|
|
1492
1494
|
|
|
1493
1495
|
const user = getRealUser();
|
|
1494
1496
|
const home = getRealHome();
|
|
@@ -1518,30 +1520,21 @@ async function daemon(sub) {
|
|
|
1518
1520
|
}
|
|
1519
1521
|
|
|
1520
1522
|
case 'stop': {
|
|
1521
|
-
if (needsSudo())
|
|
1522
|
-
const result = spawnSync('sudo', [process.execPath, ...process.argv.slice(1)], { stdio: 'inherit' });
|
|
1523
|
-
process.exit(result.status ?? 1);
|
|
1524
|
-
}
|
|
1523
|
+
if (needsSudo()) sudoReExec();
|
|
1525
1524
|
execSync(`systemctl stop ${SERVICE_NAME}`, { stdio: 'inherit' });
|
|
1526
1525
|
console.log(`\n ${c.blue}✔${c.reset} Fluxy daemon stopped.\n`);
|
|
1527
1526
|
break;
|
|
1528
1527
|
}
|
|
1529
1528
|
|
|
1530
1529
|
case 'start': {
|
|
1531
|
-
if (needsSudo())
|
|
1532
|
-
const result = spawnSync('sudo', [process.execPath, ...process.argv.slice(1)], { stdio: 'inherit' });
|
|
1533
|
-
process.exit(result.status ?? 1);
|
|
1534
|
-
}
|
|
1530
|
+
if (needsSudo()) sudoReExec();
|
|
1535
1531
|
execSync(`systemctl start ${SERVICE_NAME}`, { stdio: 'inherit' });
|
|
1536
1532
|
console.log(`\n ${c.blue}✔${c.reset} Fluxy daemon started.\n`);
|
|
1537
1533
|
break;
|
|
1538
1534
|
}
|
|
1539
1535
|
|
|
1540
1536
|
case 'restart': {
|
|
1541
|
-
if (needsSudo())
|
|
1542
|
-
const result = spawnSync('sudo', [process.execPath, ...process.argv.slice(1)], { stdio: 'inherit' });
|
|
1543
|
-
process.exit(result.status ?? 1);
|
|
1544
|
-
}
|
|
1537
|
+
if (needsSudo()) sudoReExec();
|
|
1545
1538
|
execSync(`systemctl restart ${SERVICE_NAME}`, { stdio: 'inherit' });
|
|
1546
1539
|
console.log(`\n ${c.blue}✔${c.reset} Fluxy daemon restarted.\n`);
|
|
1547
1540
|
break;
|
|
@@ -1558,10 +1551,7 @@ async function daemon(sub) {
|
|
|
1558
1551
|
}
|
|
1559
1552
|
|
|
1560
1553
|
case 'uninstall': {
|
|
1561
|
-
if (needsSudo())
|
|
1562
|
-
const result = spawnSync('sudo', [process.execPath, ...process.argv.slice(1)], { stdio: 'inherit' });
|
|
1563
|
-
process.exit(result.status ?? 1);
|
|
1564
|
-
}
|
|
1554
|
+
if (needsSudo()) sudoReExec();
|
|
1565
1555
|
try { execSync(`systemctl stop ${SERVICE_NAME}`, { stdio: 'ignore' }); } catch {}
|
|
1566
1556
|
try { execSync(`systemctl disable ${SERVICE_NAME}`, { stdio: 'ignore' }); } catch {}
|
|
1567
1557
|
if (fs.existsSync(SERVICE_PATH)) fs.unlinkSync(SERVICE_PATH);
|