fluxy-bot 0.6.0 → 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 +20 -28
- 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
|
}
|
|
@@ -933,7 +945,9 @@ async function init() {
|
|
|
933
945
|
|
|
934
946
|
stepper.advance();
|
|
935
947
|
stepper.finish();
|
|
936
|
-
if (
|
|
948
|
+
if (!hasTunnelInit) {
|
|
949
|
+
privateNetworkMessage(config.port);
|
|
950
|
+
} else if (tunnelFailed) {
|
|
937
951
|
tunnelFailedMessage(tunnelUrl);
|
|
938
952
|
} else {
|
|
939
953
|
finalMessage(tunnelUrl, relayUrl);
|
|
@@ -1476,17 +1490,7 @@ async function daemon(sub) {
|
|
|
1476
1490
|
}
|
|
1477
1491
|
|
|
1478
1492
|
// Re-exec with sudo if needed
|
|
1479
|
-
if (needsSudo())
|
|
1480
|
-
const nodePath = process.env.FLUXY_NODE_PATH || process.execPath;
|
|
1481
|
-
const realHome = getRealHome();
|
|
1482
|
-
const args = process.argv.slice(1);
|
|
1483
|
-
const result = spawnSync('sudo', [
|
|
1484
|
-
`FLUXY_NODE_PATH=${nodePath}`,
|
|
1485
|
-
`FLUXY_REAL_HOME=${realHome}`,
|
|
1486
|
-
nodePath, ...args,
|
|
1487
|
-
], { stdio: 'inherit' });
|
|
1488
|
-
process.exit(result.status ?? 1);
|
|
1489
|
-
}
|
|
1493
|
+
if (needsSudo()) sudoReExec();
|
|
1490
1494
|
|
|
1491
1495
|
const user = getRealUser();
|
|
1492
1496
|
const home = getRealHome();
|
|
@@ -1516,30 +1520,21 @@ async function daemon(sub) {
|
|
|
1516
1520
|
}
|
|
1517
1521
|
|
|
1518
1522
|
case 'stop': {
|
|
1519
|
-
if (needsSudo())
|
|
1520
|
-
const result = spawnSync('sudo', [process.execPath, ...process.argv.slice(1)], { stdio: 'inherit' });
|
|
1521
|
-
process.exit(result.status ?? 1);
|
|
1522
|
-
}
|
|
1523
|
+
if (needsSudo()) sudoReExec();
|
|
1523
1524
|
execSync(`systemctl stop ${SERVICE_NAME}`, { stdio: 'inherit' });
|
|
1524
1525
|
console.log(`\n ${c.blue}✔${c.reset} Fluxy daemon stopped.\n`);
|
|
1525
1526
|
break;
|
|
1526
1527
|
}
|
|
1527
1528
|
|
|
1528
1529
|
case 'start': {
|
|
1529
|
-
if (needsSudo())
|
|
1530
|
-
const result = spawnSync('sudo', [process.execPath, ...process.argv.slice(1)], { stdio: 'inherit' });
|
|
1531
|
-
process.exit(result.status ?? 1);
|
|
1532
|
-
}
|
|
1530
|
+
if (needsSudo()) sudoReExec();
|
|
1533
1531
|
execSync(`systemctl start ${SERVICE_NAME}`, { stdio: 'inherit' });
|
|
1534
1532
|
console.log(`\n ${c.blue}✔${c.reset} Fluxy daemon started.\n`);
|
|
1535
1533
|
break;
|
|
1536
1534
|
}
|
|
1537
1535
|
|
|
1538
1536
|
case 'restart': {
|
|
1539
|
-
if (needsSudo())
|
|
1540
|
-
const result = spawnSync('sudo', [process.execPath, ...process.argv.slice(1)], { stdio: 'inherit' });
|
|
1541
|
-
process.exit(result.status ?? 1);
|
|
1542
|
-
}
|
|
1537
|
+
if (needsSudo()) sudoReExec();
|
|
1543
1538
|
execSync(`systemctl restart ${SERVICE_NAME}`, { stdio: 'inherit' });
|
|
1544
1539
|
console.log(`\n ${c.blue}✔${c.reset} Fluxy daemon restarted.\n`);
|
|
1545
1540
|
break;
|
|
@@ -1556,10 +1551,7 @@ async function daemon(sub) {
|
|
|
1556
1551
|
}
|
|
1557
1552
|
|
|
1558
1553
|
case 'uninstall': {
|
|
1559
|
-
if (needsSudo())
|
|
1560
|
-
const result = spawnSync('sudo', [process.execPath, ...process.argv.slice(1)], { stdio: 'inherit' });
|
|
1561
|
-
process.exit(result.status ?? 1);
|
|
1562
|
-
}
|
|
1554
|
+
if (needsSudo()) sudoReExec();
|
|
1563
1555
|
try { execSync(`systemctl stop ${SERVICE_NAME}`, { stdio: 'ignore' }); } catch {}
|
|
1564
1556
|
try { execSync(`systemctl disable ${SERVICE_NAME}`, { stdio: 'ignore' }); } catch {}
|
|
1565
1557
|
if (fs.existsSync(SERVICE_PATH)) fs.unlinkSync(SERVICE_PATH);
|